Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(build): Optimized Dockerfiles (@ilolm) #5955

Merged
merged 4 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 11 additions & 14 deletions docker/backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
21 changes: 8 additions & 13 deletions docker/frontend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Loading