feat: cleanup docker setup

- Add .dockerignore
- Replace .env with .env.example
- Add migrations service
- Cleanup Dockerfile: simpler setup, simpler copy, no migrations inside the image
- Update README to match new instruction
This commit is contained in:
Nour 2024-01-23 17:43:02 +00:00
commit 1d4251c23e
No known key found for this signature in database
GPG key ID: 9744560DE7DA09AE
6 changed files with 90 additions and 46 deletions

View file

@ -1,31 +1,26 @@
FROM node:20-alpine AS build
FROM node:20.11-bullseye AS build
WORKDIR /app
# 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 ./
COPY package*.json ./
RUN npm install
# Copy application files
COPY src/ src/
COPY scripts/ scripts/
COPY prisma/schema.prisma prisma/
COPY tsconfig.json ./
COPY . .
# Generate prisma client and build the application
RUN npx prisma generate
RUN npm run build
# Runtime stage
FROM node:20-alpine
FROM node:20.11-alpine as runtime
WORKDIR /app
RUN apk update && \
apk add --no-cache openssl
apk add --no-cache openssl && \
rm -rf /var/cache/apk/*
# Copy built files from the build stage
COPY --from=build /app .
@ -33,11 +28,7 @@ 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
RUN npx prisma db push
EXPOSE 3000
# Set entrypoint
ENTRYPOINT [ "node", "scripts/start.js" ]
ENTRYPOINT [ "node", "./dist/index.js" ]
CMD ["start"]