2022-02-05 08:39:14 +03:00
|
|
|
FROM node:16.13.2-alpine AS BUILD_IMAGE
|
2022-01-29 03:31:41 +03:00
|
|
|
|
2022-02-14 02:30:34 +03:00
|
|
|
# Set the platform to build image for
|
2022-01-29 03:31:41 +03:00
|
|
|
ARG TARGETPLATFORM
|
|
|
|
ENV TARGETPLATFORM=${TARGETPLATFORM:-linux/amd64}
|
|
|
|
|
2022-02-14 02:30:34 +03:00
|
|
|
# Install additional tools needed if on arm64 / armv7
|
2022-01-29 03:31:41 +03:00
|
|
|
RUN \
|
|
|
|
case "${TARGETPLATFORM}" in \
|
2022-02-05 08:39:14 +03:00
|
|
|
'linux/arm64') apk add --no-cache python3 make g++ ;; \
|
|
|
|
'linux/arm/v7') apk add --no-cache python3 make g++ ;; \
|
2022-01-29 03:31:41 +03:00
|
|
|
esac
|
|
|
|
|
|
|
|
# Create and set the working directory
|
|
|
|
WORKDIR /app
|
|
|
|
|
|
|
|
# Install app dependencies
|
|
|
|
COPY package.json yarn.lock ./
|
|
|
|
RUN yarn install --frozen-lockfile --network-timeout 1000000
|
|
|
|
|
|
|
|
# Copy over all project files and folders to the working directory
|
|
|
|
COPY . ./
|
|
|
|
|
|
|
|
# Build initial app for production
|
|
|
|
RUN yarn build
|
|
|
|
|
2022-02-14 02:30:34 +03:00
|
|
|
# Production stage
|
2022-02-05 08:32:39 +03:00
|
|
|
FROM node:16.13.2-alpine
|
2021-08-15 02:03:06 +03:00
|
|
|
|
|
|
|
# Define some ENV Vars
|
|
|
|
ENV PORT=80 \
|
2021-08-15 13:24:04 +03:00
|
|
|
DIRECTORY=/app \
|
2022-02-17 17:52:07 +03:00
|
|
|
IS_DOCKER=true \
|
2022-02-18 10:01:36 +03:00
|
|
|
USER=docker \
|
|
|
|
UID=12345 \
|
|
|
|
GID=23456
|
2021-08-15 02:03:06 +03:00
|
|
|
|
2022-02-18 10:01:36 +03:00
|
|
|
# Install tini for initialization and tzdata for setting timezone
|
|
|
|
RUN apk add --no-cache tzdata tini \
|
|
|
|
# Add group
|
|
|
|
&& addgroup --gid ${GID} "${USER}" \
|
|
|
|
# Add user
|
|
|
|
&& adduser \
|
|
|
|
--disabled-password \
|
|
|
|
--ingroup "${USER}" \
|
|
|
|
--gecos "" \
|
|
|
|
--home "${DIRECTORY}" \
|
|
|
|
--no-create-home \
|
|
|
|
--uid "$UID" \
|
|
|
|
"$USER"
|
|
|
|
|
|
|
|
USER ${USER}
|
2022-02-17 17:52:07 +03:00
|
|
|
|
2021-08-15 02:03:06 +03:00
|
|
|
# Create and set the working directory
|
|
|
|
WORKDIR ${DIRECTORY}
|
|
|
|
|
2022-01-29 03:31:41 +03:00
|
|
|
# Copy built application from build phase
|
2022-02-18 10:01:36 +03:00
|
|
|
COPY --from=BUILD_IMAGE --chown=${USER}:${USER} /app ./
|
2021-06-04 21:57:43 +03:00
|
|
|
|
2022-01-29 03:31:41 +03:00
|
|
|
# Finally, run start command to serve up the built application
|
|
|
|
ENTRYPOINT [ "/sbin/tini", "--" ]
|
|
|
|
CMD [ "yarn", "build-and-start" ]
|
2021-06-10 21:46:46 +03:00
|
|
|
|
2022-02-14 02:30:34 +03:00
|
|
|
# Expose the port
|
2021-08-15 02:03:06 +03:00
|
|
|
EXPOSE ${PORT}
|
2021-08-15 02:23:29 +03:00
|
|
|
|
2022-02-14 02:30:34 +03:00
|
|
|
# Run simple healthchecks every 5 mins, to check that everythings still great
|
2021-08-15 02:23:29 +03:00
|
|
|
HEALTHCHECK --interval=5m --timeout=2s --start-period=30s CMD yarn health-check
|