refactor(build): optimize dockerfiles (@ilolm) (#5955)

!nuf
This commit is contained in:
Nikolai Ogorodnik 2024-10-09 13:37:08 +03:00 committed by GitHub
parent 1c2f04eed8
commit ebf98f15f6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 27 deletions

View file

@ -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

View file

@ -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"]