1- {%- if packageManager == "yarn" %}
1+ # Creating multi-stage build for production
22FROM node:16-alpine as build
3- # Installing libvips-dev for sharp Compatability
43RUN apk update && apk add --no-cache build-base gcc autoconf automake zlib-dev libpng-dev vips-dev > /dev/null 2>&1
54ARG NODE_ENV=production
65ENV NODE_ENV=${NODE_ENV}
7- WORKDIR /opt/
8- COPY ./package.json ./yarn.lock ./
9- ENV PATH /opt/node_modules/.bin:$PATH
10- RUN yarn config set network-timeout 600000 -g && yarn install --production
11- WORKDIR /opt/app
12- COPY ./ .
13- RUN yarn build
146
15- FROM node:16-alpine
16- RUN apk add --no-cache vips-dev
17- ARG NODE_ENV=production
18- ENV NODE_ENV=${NODE_ENV}
197WORKDIR /opt/
20- COPY --from=build /opt/node_modules ./node_modules
21- ENV PATH /opt/node_modules/.bin:$PATH
22- WORKDIR /opt/app
23- COPY --from=build /opt/app ./
24- EXPOSE 1337
25- CMD ["yarn", "start"]
26-
8+ {%- if packageManager == "yarn" %}
9+ COPY package.json yarn.lock ./
10+ RUN yarn config set network-timeout 600000 -g && yarn install --production
2711{%- else %}
28- FROM node:16-alpine as build
29- # Installing libvips-dev for sharp Compatability
30- RUN apk update && apk add --no-cache build-base gcc autoconf automake zlib-dev libpng-dev vips-dev > /dev/null 2>&1
31- ARG NODE_ENV=production
32- ENV NODE_ENV=${NODE_ENV}
33- WORKDIR /opt/
34- COPY ./package.json ./package-lock.json ./
12+ COPY package.json package-lock.json ./
13+ RUN npm config set network-timeout 600000 -g && npm install --only=production
14+ {%- endif %}
3515ENV PATH /opt/node_modules/.bin:$PATH
36- RUN npm install --production
3716WORKDIR /opt/app
38- COPY ./ .
17+ COPY . .
18+ {%- if packageManager == "yarn" %}
19+ RUN yarn build
20+ {%- else %}
3921RUN npm run build
22+ {%- endif %}
4023
24+ # Creating final production image
4125FROM node:16-alpine
42- # Installing libvips-dev for sharp Compatability
26+ RUN addgroup -g 1001 strapi && adduser -u 1001 -G strapi -s /bin/sh -D strapi
4327RUN apk add --no-cache vips-dev
4428ARG NODE_ENV=production
4529ENV NODE_ENV=${NODE_ENV}
4630WORKDIR /opt/
4731COPY --from=build /opt/node_modules ./node_modules
48- ENV PATH /opt/node_modules/.bin:$PATH
4932WORKDIR /opt/app
5033COPY --from=build /opt/app ./
34+ ENV PATH /opt/node_modules/.bin:$PATH
35+
36+ RUN chown -R strapi:strapi /opt/app
37+ USER strapi
5138EXPOSE 1337
52- CMD ["npm", "run","start"]
53- {% endif %}
39+ {%- if packageManager == "yarn" %}
40+ CMD ["yarn", "start"]
41+ {%- else %}
42+ CMD ["npm", "run", "start"]
43+ {%- endif %}
0 commit comments