From e81a4d28b7f18f8864557e05862b7c3bd265550c Mon Sep 17 00:00:00 2001 From: hugolxt <87241914+hugolxt@users.noreply.github.com> Date: Mon, 3 Apr 2023 17:55:59 +0200 Subject: [PATCH] setup dockerfile local front (#4) DockerFile Front local --- .gitignore | 1 + Dockerfiles/Dockerfile.front | 38 +++++++++++++++++++++++------------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index 7903eff7..1cc82db5 100644 --- a/.gitignore +++ b/.gitignore @@ -36,3 +36,4 @@ yarn-error.log* *.tsbuildinfo next-env.d.ts node_modules +id_rsa diff --git a/Dockerfiles/Dockerfile.front b/Dockerfiles/Dockerfile.front index 87358262..11d63f6c 100644 --- a/Dockerfiles/Dockerfile.front +++ b/Dockerfiles/Dockerfile.front @@ -1,34 +1,44 @@ # Install dependencies only when needed -FROM node:19-alpine AS deps +FROM node:19-alpine AS deps -WORKDIR lecoffre-front +WORKDIR leCoffre-front COPY package.json ./ +RUN apk update && apk add openssh-client git + +COPY id_rsa /root/.ssh/id_rsa +RUN chmod 600 ~/.ssh/id_rsa +RUN eval "$(ssh-agent -s)" && ssh-add /root/.ssh/id_rsa +RUN ssh-keyscan github.com smart-chain-fr/leCoffre-resources.git >> /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 +WORKDIR leCoffre-front + +COPY --from=deps leCoffre-front/node_modules ./node_modules +COPY --from=deps leCoffre-front/package.json package.json +COPY tsconfig.json tsconfig.json +COPY src src -COPY . . -COPY --from=deps lecoffre-front/node_modules ./node_modules RUN npm run build # Production image, copy all the files and run next FROM node:19-alpine AS production -WORKDIR lecoffre-front +WORKDIR leCoffre-front -RUN adduser -D lecoffre-frontuser --uid 10000 && chown -R lecoffre-frontuser . +RUN adduser -D lecoffreuser --uid 10000 && chown -R lecoffreuser . -COPY --from=builder --chown=lecoffre-frontuser lecoffre-front/node_modules ./node_modules -COPY --from=builder --chown=lecoffre-frontuser lecoffre-front/public ./public -COPY --from=builder --chown=lecoffre-frontuser lecoffre-front/.next ./.next -COPY --from=builder --chown=lecoffre-frontuser lecoffre-front/next.config.js ./next.config.js -COPY --from=builder --chown=lecoffre-frontuser lecoffre-front/package.json ./package.json -USER lecoffre-frontuser +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/package.json ./package.json + +USER lecoffreuser CMD ["npm", "run", "start"] -EXPOSE 3000 +EXPOSE 3000 \ No newline at end of file