47 lines
1.4 KiB
Docker
47 lines
1.4 KiB
Docker
# Install dependencies only when needed
|
|
FROM node:19-alpine AS deps
|
|
|
|
WORKDIR leCoffre
|
|
|
|
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
|
|
RUN npm install --frozen-lockfile
|
|
|
|
# Rebuild the source code only when needed
|
|
FROM node:19-alpine AS builder
|
|
|
|
WORKDIR leCoffre
|
|
|
|
COPY . .
|
|
|
|
RUN apk update && apk add openssh-client git
|
|
|
|
COPY id_ed25519 /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-resources.git >> /root/.ssh/known_hosts
|
|
|
|
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
|
|
|
|
RUN adduser -D lecoffreuser --uid 10000 && chown -R lecoffreuser .
|
|
|
|
COPY --from=builder --chown=lecoffreuser leCoffre/node_modules ./node_modules
|
|
COPY --from=builder --chown=lecoffreuser leCoffre/dist/api ./dist/api
|
|
COPY --from=builder --chown=lecoffreuser leCoffre/dist/entries ./dist/entries
|
|
COPY --from=builder --chown=lecoffreuser leCoffre/dist/common ./dist/common
|
|
COPY --from=builder --chown=lecoffreuser leCoffre/src/common/databases/ ./src/common/databases/
|
|
COPY --from=builder --chown=lecoffreuser leCoffre/package.json ./package.json
|
|
|
|
USER lecoffreuser
|
|
|
|
CMD ["npm", "run", "api:start"]
|
|
EXPOSE 3001 |