generated from imperial/impaas-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
devops: update CI/CD pipeline for prisma migrations (#106)
* devops: update CI/CD pipeline for prisma migrations * wip: update migrations to see what happens * wip: update migrations to see what happens * wip: remove requirement of main branch for migrations * wip: use old migration steps * wip: use old migration steps * wip: use new migration steps * wip: add .nvmrc * wip: fix lint job * feat: new workflow finalisation * chore: remove migration-altering comments * chore: remove unnecessary impaas env setting in workflow * chore: cleanup dockerfile and add dockerignore * chore: add style-check --------- Co-authored-by: nick-bolas <[email protected]> Co-authored-by: Ivan Procaccini <[email protected]>
- Loading branch information
1 parent
a2812a0
commit 5f0548b
Showing
4 changed files
with
140 additions
and
130 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v20.13.0 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,47 @@ | ||
FROM node:18-alpine AS base | ||
# Stage 1: Build | ||
FROM node:18-alpine AS builder | ||
|
||
FROM base AS app_base | ||
|
||
# Make UPLOAD_DIRs | ||
ENV UPLOAD_DIR=/uploads | ||
RUN mkdir $UPLOAD_DIR | ||
RUN mkdir $UPLOAD_DIR/banners $UPLOAD_DIR/cvs $UPLOAD_DIR/avatars $UPLOAD_DIR/logos $UPLOAD_DIR/attachments | ||
ENV NEXT_TELEMETRY_DISABLED=1 | ||
WORKDIR /app | ||
|
||
# Prisma base image only for installing prisma | ||
FROM base AS prisma_base | ||
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed. | ||
RUN apk add --no-cache libc6-compat | ||
WORKDIR /app | ||
COPY package.json package-lock.json* ./ | ||
RUN npm install prisma --omit=dev | ||
|
||
FROM prisma_base AS deps | ||
WORKDIR /app | ||
|
||
# Won't need to re-install prisma, since it's already installed in the prisma_base image | ||
RUN npm ci | ||
|
||
FROM base AS builder | ||
WORKDIR /app | ||
COPY --from=deps /app/node_modules ./node_modules | ||
COPY . . | ||
RUN npx prisma generate | ||
RUN npm run build | ||
|
||
# Disable telemetry during the build. | ||
ENV NEXT_TELEMETRY_DISABLED 1 | ||
|
||
RUN npm run build | ||
# Stage 2: Production | ||
FROM node:18-alpine AS runner | ||
|
||
# Production image, copy all the files and run next | ||
FROM app_base AS runner | ||
ENV NEXT_TELEMETRY_DISABLED=1 | ||
WORKDIR /app | ||
|
||
# Disable telemetry during runtime. | ||
ENV NEXT_TELEMETRY_DISABLED 1 | ||
|
||
COPY --from=builder /app/public ./public | ||
# Make UPLOAD_DIRs | ||
ENV UPLOAD_DIR=/uploads | ||
RUN mkdir $UPLOAD_DIR | ||
RUN mkdir $UPLOAD_DIR/banners $UPLOAD_DIR/cvs $UPLOAD_DIR/avatars $UPLOAD_DIR/logos $UPLOAD_DIR/attachments | ||
RUN chown node:node /app | ||
RUN chown -R node:node $UPLOAD_DIR | ||
|
||
# Set the correct permission for prerender cache | ||
RUN mkdir .next | ||
RUN chown node:node .next | ||
|
||
# Copy prisma schema | ||
COPY --from=builder --chown=node:node /app/prisma ./prisma | ||
|
||
# Copy over the prisma client | ||
COPY --from=prisma_base /app/node_modules ./node_modules | ||
|
||
# Automatically leverage output traces to reduce image size | ||
# https://nextjs.org/docs/advanced-features/output-file-tracing | ||
COPY --from=builder /app/node_modules ./node_modules | ||
COPY --from=builder /app/public ./public | ||
COPY --from=builder --chown=node:node /app/.next/standalone ./ | ||
COPY --from=builder --chown=node:node /app/.next/static ./.next/static | ||
|
||
# Take ownership of the app folder and uploads | ||
RUN chown node:node /app | ||
RUN chown -R node:node $UPLOAD_DIR | ||
COPY --from=builder --chown=node:node /app/prisma ./prisma | ||
|
||
USER node | ||
|
||
EXPOSE 3000 | ||
|
||
ENV PORT=3000 | ||
ENV HOSTNAME="0.0.0.0" | ||
ENV NODE_ENV=production | ||
|
||
CMD HOSTNAME="0.0.0.0" node server.js | ||
CMD ["npm", "run", "start"] |
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