Dokerfile optim speed
Some checks failed
Build release Docker image / Build Docker Images (push) Failing after 6m55s
Some checks failed
Build release Docker image / Build Docker Images (push) Failing after 6m55s
This commit is contained in:
35
Dockerfile
35
Dockerfile
@@ -1,36 +1,18 @@
|
||||
# --- ÉTAPE 1 : BUILD ---
|
||||
FROM node:20-alpine AS build-stage
|
||||
|
||||
# Installation des outils pour les modules natifs
|
||||
RUN apk update && apk add --no-cache \
|
||||
build-base \
|
||||
gcc \
|
||||
autoconf \
|
||||
automake \
|
||||
zlib-dev \
|
||||
libpng-dev \
|
||||
vips-dev \
|
||||
git > /dev/null 2>&1
|
||||
build-base gcc autoconf automake zlib-dev libpng-dev vips-dev git > /dev/null 2>&1
|
||||
|
||||
ARG NODE_ENV=production
|
||||
ENV NODE_ENV=${NODE_ENV}
|
||||
|
||||
# ON SE MET DIRECTEMENT DANS LE BON DOSSIER
|
||||
WORKDIR /opt/app
|
||||
|
||||
# On copie les fichiers de dépendances
|
||||
COPY package.json yarn.lock ./
|
||||
|
||||
# Installation (Les node_modules seront créés dans /opt/app/node_modules)
|
||||
RUN yarn install --frozen-lockfile
|
||||
|
||||
# On copie le reste du projet
|
||||
COPY . .
|
||||
|
||||
# Maintenant Yarn trouvera Strapi sans problème
|
||||
RUN yarn build
|
||||
|
||||
# --- ÉTAPE 2 : RUNTIME ---
|
||||
# --- ÉTAPE 2 : RUNTIME (L'image finale) ---
|
||||
FROM node:20-alpine AS runtime-stage
|
||||
RUN apk add --no-cache vips-dev libpng libjpeg-turbo
|
||||
|
||||
@@ -39,15 +21,18 @@ ENV NODE_ENV=${NODE_ENV}
|
||||
|
||||
WORKDIR /opt/app
|
||||
|
||||
# On récupère tout le dossier de build (qui contient maintenant les node_modules au bon endroit)
|
||||
COPY --from=build-stage /opt/app ./
|
||||
# ASTUCE : On copie et on change le propriétaire EN MÊME TEMPS
|
||||
# On ne prend que ce qui est utile pour l'exécution
|
||||
COPY --from=build-stage --chown=node:node /opt/app/node_modules ./node_modules
|
||||
COPY --from=build-stage --chown=node:node /opt/app/dist ./dist
|
||||
COPY --from=build-stage --chown=node:node /opt/app/build ./build
|
||||
COPY --from=build-stage --chown=node:node /opt/app/package.json ./
|
||||
COPY --from=build-stage --chown=node:node /opt/app/public ./public
|
||||
|
||||
# On expose le binaire de Strapi dans le PATH au cas où
|
||||
# On expose le binaire
|
||||
ENV PATH=/opt/app/node_modules/.bin:$PATH
|
||||
|
||||
RUN chown -R node:node /opt/app
|
||||
USER node
|
||||
|
||||
EXPOSE 1337
|
||||
|
||||
CMD ["yarn", "start"]
|
||||
Reference in New Issue
Block a user