diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..41d0a02c --- /dev/null +++ b/.dockerignore @@ -0,0 +1,10 @@ +.git +node_modules +.next +coverage +dist +.DS_Store +npm-debug.log* +yarn-debug.log* +yarn-error.log* +.env* diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a168531..e05c67d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,3 +7,11 @@ ## v0.1.2 - LoginCallback (`index.tsx`) ajusté: suppression de la redirection spéciale `local.4nkweb.com` au profit d'un flux standard basé sur variables d'environnement. + +## v0.1.3 + +- Optimisations build Docker: + - `.dockerignore` pour réduire le contexte. + - Next.js `output: 'standalone'` pour une image runtime plus légère. + - Caches BuildKit (npm et .next) pour accélérer les builds. + - Runtime basé sur `server.js` (standalone) au lieu de `next start`. diff --git a/Dockerfile b/Dockerfile index 9af6dd44..73b4771f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,6 +9,7 @@ RUN apk update && apk add --no-cache openssh-client git # Forward SSH agent via BuildKit (clé jamais écrite dans l'image) RUN --mount=type=ssh \ + --mount=type=cache,target=/root/.npm \ mkdir -p /root/.ssh && \ ssh-keyscan git.4nkweb.com >> /root/.ssh/known_hosts && \ npm install --no-audit --no-fund @@ -74,7 +75,7 @@ ENV NEXT_PUBLIC_BACK_API_PROTOCOL=${NEXT_PUBLIC_BACK_API_PROTOCOL} \ NEXT_PUBLIC_DEFAULT_VALIDATOR_ID=${NEXT_PUBLIC_DEFAULT_VALIDATOR_ID} \ NEXT_PUBLIC_DEFAULT_STORAGE_URLS=${NEXT_PUBLIC_DEFAULT_STORAGE_URLS} -RUN npm run build +RUN --mount=type=cache,target=/leCoffre-front/.next/cache npm run build # --- Image d'exécution "ext" FROM node:19-alpine AS ext @@ -83,15 +84,14 @@ WORKDIR /leCoffre-front ENV NODE_ENV=production \ PORT=3000 -COPY --from=builder /leCoffre-front/.next ./.next +# Next.js standalone runtime (output: 'standalone') +COPY --from=builder /leCoffre-front/.next/standalone ./ +COPY --from=builder /leCoffre-front/.next/static ./.next/static COPY --from=builder /leCoffre-front/public ./public -COPY --from=deps /leCoffre-front/node_modules ./node_modules -COPY --from=builder /leCoffre-front/package.json ./package.json -COPY --from=builder /leCoffre-front/next.config.js ./next.config.js # Création de l'utilisateur non-root RUN adduser -D lecoffreuser --uid 10000 && chown -R lecoffreuser . USER lecoffreuser EXPOSE 3000 -CMD ["npm", "run", "start"] \ No newline at end of file +CMD ["node", "server.js"] \ No newline at end of file diff --git a/docs/ext.md b/docs/ext.md index 8e4f5d6b..8ed77743 100644 --- a/docs/ext.md +++ b/docs/ext.md @@ -33,7 +33,7 @@ Prérequis: Docker BuildKit activé et agent SSH opérationnel pour cloner `le-c 1. `cd /home/debian/lecoffre-front` 2. `export DOCKER_BUILDKIT=1` -3. `docker build --target ext --ssh default -t lecoffre/front:ext-0.1.2 -f /home/debian/lecoffre-front/Dockerfile /home/debian/lecoffre-front` +3. `docker build --target ext --ssh default -t lecoffre/front:ext-0.1.3 -f /home/debian/lecoffre-front/Dockerfile /home/debian/lecoffre-front` #### Exécution locale (validation) @@ -48,11 +48,11 @@ docker run --rm -p 3000:3000 \ -e NEXT_PUBLIC_BACK_API_VERSION=v1 \ -e NEXT_PUBLIC_FRONT_APP_HOST=https://app.example.com \ -e NEXT_PUBLIC_4NK_URL=https://app.example.com \ - lecoffre/front:ext-0.1.2 + lecoffre/front:ext-0.1.3 ``` #### Publication via CI (git.4nkweb.com) - Le push d'image est effectué par la CI de `git.4nkweb.com` suite à un `git push`. -- Définir le tag Docker dans le message de commit: `ci: docker_tag=ext-0.1.2` (fallback CI: `dev-test`). +- Définir le tag Docker dans le message de commit: `ci: docker_tag=ext-0.1.3` (fallback CI: `dev-test`). - La branche peut être utilisée par la CI comme tag en l’absence d’override. diff --git a/next.config.js b/next.config.js index c2558b15..0a03ba71 100644 --- a/next.config.js +++ b/next.config.js @@ -2,6 +2,7 @@ const nextConfig = { reactStrictMode: false, + output: 'standalone', typescript: { ignoreBuildErrors: true, }, diff --git a/package.json b/package.json index a0c0c918..340051d8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lecoffre-front", - "version": "0.1.2", + "version": "0.1.3", "private": true, "scripts": { "dev": "next dev",