From 1d92178c6190571d7fa6fd9e36627dcc724630ef Mon Sep 17 00:00:00 2001 From: Julian Grabitzky Date: Tue, 5 Sep 2023 18:51:42 +0200 Subject: [PATCH] #129 Add first draft for multi-stage builds --- Server/Dockerfile | 26 +++++++++++++++++++------- Server/package.json | 8 +++----- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/Server/Dockerfile b/Server/Dockerfile index 2ad1fce1..27eb00ba 100644 --- a/Server/Dockerfile +++ b/Server/Dockerfile @@ -1,4 +1,4 @@ -FROM node:18-alpine +FROM node:18-alpine AS build-stage WORKDIR /app @@ -9,13 +9,25 @@ COPY package*.json ./ RUN npm i -g node-gyp RUN npm i -# TODO: currently we need dev-dependancies (like typescript) installed for our product to work -# These are not installed when NODE_ENV=production, so we set that ENV later -ENV NODE_ENV production # Copy remaining parts COPY . . -RUN chmod +x ./startup.sh +# Generate prisma files +RUN npx prisma generate + +# Build the TypeScript application +RUN npm run build + +FROM node:18-alpine AS base + +WORKDIR /app + +# Copy only the built files from the previous stage +COPY --from=build-stage /app/build ./build +COPY --from=build-stage /app/package.json ./ +COPY --from=build-stage /app/prisma/schema.prisma ./ +COPY --from=build-stage /app/node_modules ./node_modules +ENV NODE_ENV production -# Run the service -ENTRYPOINT [ "./startup.sh" ] \ No newline at end of file +FROM base AS production-stage +CMD ["npm", "start"] \ No newline at end of file diff --git a/Server/package.json b/Server/package.json index b3030503..926b0c68 100644 --- a/Server/package.json +++ b/Server/package.json @@ -4,12 +4,10 @@ "description": "Backend service for the RailTrail project.", "main": "index.ts", "scripts": { - "start": "tsc && node ./build/index.js", - "test": "echo \"Error: no test specified\" && exit 1", + "build": "tsc --build", + "start": "prisma db push && node ./build/index.js", "dev": "nodemon --watch 'src/**/*.ts' --exec 'ts-node' src/index.ts", - "prisma": "prisma generate && prisma db push", - "tsc": "tsc", - "generate-guards": "npx ts-auto-guard ./src/models/api*.ts" + "prisma": "prisma generate && prisma db push" }, "repository": { "type": "git",