From 0c585cf35450e6f96c3ab4d31de18645e9b575fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment?= Date: Fri, 5 Jan 2024 12:14:57 +0100 Subject: [PATCH] feat: add Dockerfile to webapp-next --- webapp/Dockerfile | 59 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 webapp/Dockerfile diff --git a/webapp/Dockerfile b/webapp/Dockerfile new file mode 100644 index 00000000..372855fe --- /dev/null +++ b/webapp/Dockerfile @@ -0,0 +1,59 @@ +ARG NODE_VERSION=lts-alpine3.18@sha256:ef5e088232f803cadb83326edb4731015f42961d23a11510b109c2c98cfbb945 + +FROM node:$NODE_VERSION as dependencies +WORKDIR /app +ARG PRODUCTION +COPY package.json yarn.lock ./ +RUN yarn install --frozen-lockfile + +FROM node:$NODE_VERSION as builder +WORKDIR /app +ARG PRODUCTION + +ARG DATABASE_URL +ENV DATABASE_URL=$DATABASE_URL +ARG PAYLOAD_SECRET +ENV PAYLOAD_SECRET=$PAYLOAD_SECRET +ARG PAYLOAD_CONFIG_PATH +ENV PAYLOAD_CONFIG_PATH=$PAYLOAD_CONFIG_PATH + +COPY . . +COPY --from=dependencies /app/node_modules ./node_modules +RUN yarn build + +FROM node:$NODE_VERSION as runner +WORKDIR /app +ARG PRODUCTION +ENV NODE_ENV production + +ARG DATABASE_URL +ENV DATABASE_URL=$DATABASE_URL +ARG PAYLOAD_SECRET +ENV PAYLOAD_SECRET=$PAYLOAD_SECRET +ARG PAYLOAD_CONFIG_PATH +ENV PAYLOAD_CONFIG_PATH=$PAYLOAD_CONFIG_PATH + +COPY package.json yarn.lock ./ +# Remove dev dependencies +RUN yarn install --production --frozen-lockfile && \ + yarn cache clean + +RUN addgroup --system --gid 1001 nodejs && \ + adduser --system --uid 1001 nextjs + +COPY --from=builder /app/public ./public +COPY --from=builder /app/.next ./.next +COPY --from=builder /app/node_modules ./node_modules + +# Block crawlers for staging deployments +RUN if [ -z "$PRODUCTION" ]; then mv -f public/robots.staging.txt public/robots.txt; \ + else rm -f public/robots.staging.txt; fi + +RUN chmod 1777 /tmp +RUN chmod 1777 /app + +USER 1001 + +EXPOSE 3000 +ENV PORT 3000 +CMD ["yarn", "start"]