From 688ad6420ed5cac5a9f4e6c379e6d7d322b9f9b7 Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Mon, 17 Apr 2023 22:44:38 +0100 Subject: [PATCH] Writes quick Dockerfile, cos - why not? --- Dockerfile | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5afb8ba --- /dev/null +++ b/Dockerfile @@ -0,0 +1,55 @@ +FROM node:18-alpine AS BUILD_IMAGE + +# Set the platform to build image for +ARG TARGETPLATFORM +ENV TARGETPLATFORM=${TARGETPLATFORM:-linux/amd64} + +# Get environment variables +ARG NODE_ENV + +# Install additional tools needed if on arm64 / armv7 +RUN \ + case "${TARGETPLATFORM}" in \ + 'linux/arm64') apk add --no-cache python3 make g++ ;; \ + 'linux/arm/v7') apk add --no-cache python3 make g++ ;; \ + 'linux/arm64/v8') apk add --no-cache python3 make g++ ;; \ + esac + +# Create and set the working directory +WORKDIR /app + +# Install app dependencies +COPY package.json package-lock.json ./ +RUN npm install + +# Copy over all project files and folders to the working directory +COPY . ./ + +# Build initial app for production +RUN npm run build + +# Production stage +FROM node:18-alpine + +# Define some ENV Vars +ENV PORT=80 \ + DIRECTORY=/app \ + IS_DOCKER=true + +# Create and set the working directory +WORKDIR ${DIRECTORY} + +# Update tzdata for setting timezone +RUN apk add --no-cache tzdata + +# Copy built application from build phase +COPY --from=BUILD_IMAGE /app ./ + +# Finally, run start command to serve up the built application +CMD [ "npm", "start" ] + +# Expose the port +EXPOSE ${PORT} + +# Run simple healthchecks every 5 mins, to check that everythings still great +HEALTHCHECK --interval=5m --timeout=5s --start-period=30s CMD yarn health-check \ No newline at end of file