lecoffre-back/devops/Dockerfile
2023-03-31 17:44:48 +02:00

51 lines
1.6 KiB
Docker

# Install dependencies only when needed
FROM node:19-alpine AS deps
WORKDIR leCoffre-back
RUN npm install -D prisma@4.11.0
COPY package.json ./
COPY src/common/databases/schema.prisma ./src/common/databases/schema.prisma
RUN npx prisma generate
ARG FINGERPRINT
ENV FINGERPRINT=$FINGERPRINT
COPY id_rsa_${FINGERPRINT} /root/.ssh/id_ed25519
RUN chmod 600 ~/.ssh/id_ed25519
RUN eval "$(ssh-agent -s)" && ssh-add /root/.ssh/id_ed25519
RUN ssh-keyscan github.com smart-chain-fr/leCoffre-back-resources.git >> /root/.ssh/known_hosts
RUN npm cache clean --force
RUN npm install --frozen-lockfile -g npm-cache
# Rebuild the source code only when needed
FROM node:19-alpine AS builder
WORKDIR leCoffre-back
COPY . .
RUN apk update && apk add openssh-client git
COPY node_modules ./node_modules
RUN npx prisma generate
RUN npm run build
# Production image, copy all the files and run next
FROM node:19-alpine AS production
WORKDIR leCoffre-back
RUN unset FINGERPRINT
RUN adduser -D lecoffre-back-user --uid 10000 && chown -R lecoffre-back-user .
COPY --from=builder --chown=lecoffre-back-user leCoffre-back/node_modules ./node_modules
COPY --from=builder --chown=lecoffre-back-user leCoffre-back/dist/app/api ./dist/api
COPY --from=builder --chown=lecoffre-back-user leCoffre-back/dist/entries ./dist/entries
COPY --from=builder --chown=lecoffre-back-user leCoffre-back/dist/common ./dist/common
COPY --from=builder --chown=lecoffre-back-user leCoffre-back/src/common/databases/ ./src/common/databases/
COPY --from=builder --chown=lecoffre-back-user leCoffre-back/package.json ./package.json
USER lecoffre-back-user
CMD ["npm", "run", "api:start"]
EXPOSE 3001