From ebf98f15f63534a584444967d5cd1dd2fdcd6510 Mon Sep 17 00:00:00 2001 From: Nikolai Ogorodnik <83036869+ilolm@users.noreply.github.com> Date: Wed, 9 Oct 2024 13:37:08 +0300 Subject: [PATCH] refactor(build): optimize dockerfiles (@ilolm) (#5955) !nuf --- docker/backend/Dockerfile | 25 +++++++++++-------------- docker/frontend/Dockerfile | 21 ++++++++------------- 2 files changed, 19 insertions(+), 27 deletions(-) diff --git a/docker/backend/Dockerfile b/docker/backend/Dockerfile index 3b2c478ba..c45cd5a27 100644 --- a/docker/backend/Dockerfile +++ b/docker/backend/Dockerfile @@ -3,28 +3,26 @@ FROM node:20.16.0-alpine3.19 AS builder WORKDIR /app #copy -COPY package.json package.json -COPY pnpm-lock.yaml pnpm-lock.yaml -COPY pnpm-workspace.yaml pnpm-workspace.yaml -COPY turbo.json turbo.json +COPY ["package.json", "pnpm-lock.yaml", "pnpm-workspace.yaml", "turbo.json", "./"] COPY packages packages COPY backend backend -#gimme pnpm -RUN npm i -g pnpm - -#build -RUN pnpm i --frozen-lockfile -RUN npm run build +#gimme pnpm + build +RUN npm i -g pnpm && \ + pnpm i --frozen-lockfile && \ + npm run build #deploy (install all non-dev dependencies in a single node_module folder) RUN pnpm deploy --filter backend --prod /prod/backend +#--------------------------------- + ## target image FROM node:20.16.0-alpine3.19 ##install wget, used by the applyConfig script -RUN apk add wget +RUN apk update --no-cache && \ + apk add --no-cache wget # COPY to target COPY --from=builder /prod/backend/node_modules /app/backend/node_modules @@ -36,10 +34,9 @@ COPY --from=builder /prod/backend/redis-scripts /app/backend/redis-scripts WORKDIR /app/backend/dist ## logs -RUN mkdir logs +RUN mkdir -p /app/backend/dist/logs -COPY docker/backend/entry-point.sh entry-point.sh -COPY docker/backend/applyConfig.sh applyConfig.sh +COPY ["docker/backend/entry-point.sh", "docker/backend/applyConfig.sh", "./"] #run in env mode (no anticheat) ENV MODE=dev diff --git a/docker/frontend/Dockerfile b/docker/frontend/Dockerfile index 36e4c38f8..598cfccf2 100644 --- a/docker/frontend/Dockerfile +++ b/docker/frontend/Dockerfile @@ -2,32 +2,27 @@ FROM node:20.16.0-alpine3.19 AS builder WORKDIR /app #ENV -ENV BACKEND_URL=###MONKEYTYPE_BACKENDURL### -ENV RECAPTCHA_SITE_KEY=###RECAPTCHA_SITE_KEY### +ENV BACKEND_URL=###MONKEYTYPE_BACKENDURL### RECAPTCHA_SITE_KEY=###RECAPTCHA_SITE_KEY### #COPY -COPY package.json package.json -COPY pnpm-lock.yaml pnpm-lock.yaml -COPY pnpm-workspace.yaml pnpm-workspace.yaml -COPY turbo.json turbo.json +COPY ["package.json", "pnpm-lock.yaml", "pnpm-workspace.yaml", "turbo.json", "./"] COPY packages packages COPY frontend frontend COPY docker/frontend/firebase-config-live.ts frontend/src/ts/constants/firebase-config.ts COPY docker/frontend/firebase-config-live.ts frontend/src/ts/constants/firebase-config-live.ts -#gimme pnpm -RUN npm i -g pnpm - -#build -RUN pnpm i --frozen-lockfile -RUN npm run build +#gimme pnpm + build +RUN npm i -g pnpm && \ + pnpm i --frozen-lockfile && \ + npm run build # COPY to target FROM nginx:mainline-alpine + COPY --from=builder /app/frontend/dist /usr/share/nginx/html COPY docker/frontend/updateConfig.sh /docker-entrypoint.d/updateConfig.sh -RUN chmod +x /docker-entrypoint.d/updateConfig.sh +RUN chmod +x /docker-entrypoint.d/updateConfig.sh # entry #CMD ["./entryPoint.sh"]