Skip to content

Commit

Permalink
#129 Add first draft for multi-stage builds
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianGrabitzky committed Sep 5, 2023
1 parent 237748f commit 1d92178
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
26 changes: 19 additions & 7 deletions Server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:18-alpine
FROM node:18-alpine AS build-stage

WORKDIR /app

Expand All @@ -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" ]
FROM base AS production-stage
CMD ["npm", "start"]
8 changes: 3 additions & 5 deletions Server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 1d92178

Please sign in to comment.