From 1652419cd3b1e0d131d65dfeef36428d31a2949a Mon Sep 17 00:00:00 2001 From: Fishcake Date: Fri, 22 Dec 2023 21:42:06 +0900 Subject: [PATCH] reduce Docker image size and use alpine as base --- Dockerfile | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 367f0af..a9e11db 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,24 +1,42 @@ -FROM node:19-buster-slim as build +FROM node:20-alpine AS build WORKDIR /app -RUN apt-get update -y && apt-get install -y openssl python3 build-essential make gcc +# Install dependencies +RUN apk update && \ + apk add --no-cache openssl python3 make g++ \ + && ln -sf python3 /usr/bin/python +# Copy package files and install dependencies COPY package.json package-lock.json ./ -RUN npm i - -RUN apt-get purge -y gcc make build-essential && apt-get autoremove -y +RUN npm install +# Copy application files COPY src/ src/ -COPY scripts scripts/ +COPY scripts/ scripts/ COPY prisma/schema.prisma prisma/ COPY tsconfig.json ./ +# Generate prisma client and build the application RUN npx prisma generate - RUN npm run build -RUN npm i +# Runtime stage +FROM node:20-alpine +WORKDIR /app + +RUN apk update && \ + apk add --no-cache openssl + +# Copy built files from the build stage +COPY --from=build /app . + +# Install only runtime dependencies +RUN npm install --only=production + +# Copy and run migrations +COPY --from=build /app/prisma ./prisma RUN npx prisma migrate deploy +# Set entrypoint ENTRYPOINT [ "node", "scripts/start.js" ] CMD ["start"]