Created
September 15, 2023 18:31
-
-
Save Zoomelectrico/65079d63b870fcc589d0c487781e2f6e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM node:18-alpine AS base | |
RUN apk add --no-cache python3 py3-pip | |
# --no-cache: download package index on-the-fly, no need to cleanup afterwards | |
# --virtual: bundle packages, remove whole bundle at once, when done | |
RUN apk --no-cache --virtual build-dependencies add \ | |
make \ | |
g++ | |
ENV SCOPE=api | |
RUN npm config set fetch-retry-mintimeout 20000 | |
RUN npm config set fetch-retry-maxtimeout 120000 | |
FROM base AS builder | |
RUN apk update | |
WORKDIR /app | |
RUN npm i -g turbo | |
COPY . . | |
RUN turbo prune --scope=${SCOPE} --docker | |
FROM base AS installer | |
RUN apk add --no-cache libc6-compat | |
RUN apk update | |
WORKDIR /app | |
# First install dependencies (as they change less often) | |
COPY --from=builder /app/out/json/ . | |
COPY --from=builder /app/out/package-lock.json ./package-lock.json | |
RUN npm install -g node-gyp | |
RUN npm i --workspace=apps/api argon2@0.30.3 | |
RUN npm install | |
# Build the project and its dependencies | |
COPY --from=builder /app/out/full/ . | |
COPY turbo.json turbo.json | |
# Uncomment and use build args to enable remote caching | |
ARG TURBO_TEAM | |
ENV TURBO_TEAM=$TURBO_TEAM | |
ARG TURBO_TOKEN | |
ENV TURBO_TOKEN=$TURBO_TOKEN | |
RUN yarn turbo run build --filter=${SCOPE} | |
FROM base AS runner | |
WORKDIR /app | |
# Don't run production as root | |
RUN addgroup --system --gid 1001 expressjs | |
RUN adduser --system --uid 1001 expressjs | |
USER expressjs | |
COPY --from=installer /app . | |
CMD node apps/api/dist/main.js | |
# compiled output | |
/dist | |
/node_modules | |
../../node_modules | |
# Logs | |
logs | |
*.log | |
npm-debug.log* | |
pnpm-debug.log* | |
yarn-debug.log* | |
yarn-error.log* | |
lerna-debug.log* | |
# OS | |
.DS_Store | |
# Tests | |
/coverage | |
/.nyc_output | |
# IDEs and editors | |
/.idea | |
.project | |
.classpath | |
.c9/ | |
*.launch | |
.settings/ | |
*.sublime-workspace | |
# IDE - VSCode | |
.vscode/* | |
!.vscode/settings.json | |
!.vscode/tasks.json | |
!.vscode/launch.json | |
!.vscode/extensions.json | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment