refactor: polish dockerfiles (#51546)

This commit is contained in:
Oliver Eyton-Williams
2023-09-14 08:17:28 +02:00
committed by GitHub
parent 1119c21d44
commit 0441090482
6 changed files with 21 additions and 13 deletions
+8 -5
View File
@@ -1,17 +1,20 @@
# bookworm was only released on 10-6-2023, so is a little too new. # bookworm was only released on 10-6-2023, so is a little too new.
FROM node:18-bullseye AS builder FROM node:18-bullseye AS builder
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
# global installs need root permissions, so have to happen before we switch to # global installs need root permissions, so have to happen before we switch to
# the node user # the node user
RUN npm i -g pnpm@8 RUN npm i -g pnpm@8
# node images create a non-root user that we can use # node images create a non-root user that we can use
USER node USER node
WORKDIR /home/node/build WORKDIR /home/node/build
COPY --chown=node:node . .
# TODO: figure out why the cache is getting invalidated. Is it in part because COPY --chown=node:node *.* .
# we're not ignoring THIS file? Or do we need corepack? COPY --chown=node:node api-server/ api-server/
COPY --chown=node:node shared/ shared/
COPY --chown=node:node tools/ tools/
COPY --chown=node:node curriculum/ curriculum/
# TODO: AFAIK it's just the intro translations. Those should be folded into the
# curriculum and then we can remove this.
COPY --chown=node:node client/ client/
# We have to prevent pnpm from deduping peer dependencies because otherwise it # We have to prevent pnpm from deduping peer dependencies because otherwise it
# will install all of the packages, not just api-server. Also, pnpm deploy is # will install all of the packages, not just api-server. Also, pnpm deploy is
+7 -4
View File
@@ -7,9 +7,7 @@ RUN npm i -g pnpm@8
USER node USER node
WORKDIR /home/node/build WORKDIR /home/node/build
COPY --chown=node:node package.json . COPY --chown=node:node *.* .
COPY --chown=node:node pnpm*.yaml .
COPY --chown=node:node tsconfig*.json .
COPY --chown=node:node api/ api/ COPY --chown=node:node api/ api/
COPY --chown=node:node shared/ shared/ COPY --chown=node:node shared/ shared/
COPY --chown=node:node tools/ tools/ COPY --chown=node:node tools/ tools/
@@ -39,7 +37,12 @@ COPY --chown=node:node pnpm*.yaml .
COPY --chown=node:node api/ api/ COPY --chown=node:node api/ api/
COPY --chown=node:node shared/ shared/ COPY --chown=node:node shared/ shared/
RUN npm i -g pnpm@8 RUN npm i -g pnpm@8
RUN pnpm install --prod --ignore-scripts -F=shared -F=api
# Weirdly this config does not seem necessary for the new api (the same number
# of deps are installed in both cases), but I'm including it just for
# consistency.
RUN pnpm config set dedupe-peer-dependents false
RUN pnpm install --prod --ignore-scripts -F=shared -F=api --frozen-lockfile
# While we want to ignore scripts generally, we do need to generate the prisma # While we want to ignore scripts generally, we do need to generate the prisma
# client. Note: npx is the simplest way to generate the client without us having # client. Note: npx is the simplest way to generate the client without us having
# to have prisma as a prod dependency. # to have prisma as a prod dependency.
+6 -4
View File
@@ -7,7 +7,11 @@ RUN npm i -g pnpm@8
USER node USER node
WORKDIR /home/node/build WORKDIR /home/node/build
COPY --chown=node:node . . COPY --chown=node:node *.* .
COPY --chown=node:node client/ client/
COPY --chown=node:node shared/ shared/
COPY --chown=node:node tools/ tools/
COPY --chown=node:node curriculum/ curriculum/
ARG HOME_LOCATION ARG HOME_LOCATION
ARG API_LOCATION ARG API_LOCATION
@@ -43,9 +47,7 @@ RUN npm i -g serve@13 pm2@4
USER node USER node
WORKDIR /home/node/client WORKDIR /home/node/client
COPY --from=builder /home/node/build/client/public/ public COPY --from=builder /home/node/build/client/public/ public
COPY --from=builder /home/node/build/docker/web/serve.sh serve.sh COPY --from=builder /home/node/build/client/serve/ ./
COPY --from=builder /home/node/build/docker/web/pm2-start.sh pm2-start.sh
COPY --from=builder /home/node/build/docker/web/serve.json serve.json
ENTRYPOINT [ "./pm2-start.sh" ] ENTRYPOINT [ "./pm2-start.sh" ]
CMD [ "8000" ] CMD [ "8000" ]