lecoffre-front/Dockerfile
omaroughriss fd4a9d32b7
Some checks failed
Build and Push to Registry / build-and-push (push) Failing after 25s
Minor update
2025-07-01 16:11:26 +02:00

54 lines
1.5 KiB
Docker

# Install dependencies only when needed
FROM node:19-alpine AS deps
WORKDIR leCoffre-front
COPY package.json ./
ARG ENV_VARS
RUN echo "${ENV_VARS}" > .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