lecoffre-front/Dockerfile
2025-07-01 15:55:24 +02:00

52 lines
1.5 KiB
Docker

# Install dependencies only when needed
FROM node:19-alpine AS deps
WORKDIR leCoffre-front
COPY package.json ./
COPY .env ./
RUN apk update && apk add openssh-client git
ARG SSH_PRIVATE_KEY
RUN mkdir -p /root/.ssh && \
echo "${SSH_PRIVATE_KEY}" > /root/.ssh/id_rsa && \
chmod 600 /root/.ssh/id_rsa && \
eval "$(ssh-agent -s)" && \
ssh-add /root/.ssh/id_rsa && \
ssh-keyscan git.4nkweb.com >> /root/.ssh/known_hosts
RUN npm install --frozen-lockfile
# Rebuild the source code only when needed
FROM node:19-alpine AS builder
WORKDIR leCoffre-front
COPY --from=deps leCoffre-front/node_modules ./node_modules
COPY --from=deps leCoffre-front/package.json package.json
COPY --from=deps leCoffre-front/.env ./.env
COPY tsconfig.json tsconfig.json
COPY next.config.js next.config.js
COPY src src
RUN npm run build
# Production image, copy all the files and run next
FROM node:19-alpine AS production
WORKDIR leCoffre-front
RUN adduser -D lecoffreuser --uid 10000 && chown -R lecoffreuser .
COPY public ./public
COPY --from=builder --chown=lecoffreuser leCoffre-front/node_modules ./node_modules
COPY --from=builder --chown=lecoffreuser leCoffre-front/.next ./.next
COPY --from=builder --chown=lecoffreuser leCoffre-front/next.config.js ./next.config.js
COPY --from=builder --chown=lecoffreuser leCoffre-front/package.json ./package.json
COPY --from=builder --chown=lecoffreuser leCoffre-front/.env ./.env
USER lecoffreuser
CMD ["npm", "run", "start"]
EXPOSE 3000