1
- {%- if packageManager == "yarn" %}
1
+ # Creating multi-stage build for production
2
2
FROM node:16-alpine as build
3
- # Installing libvips-dev for sharp Compatability
4
3
RUN apk update && apk add --no-cache build-base gcc autoconf automake zlib-dev libpng-dev vips-dev > /dev/null 2>&1
5
4
ARG NODE_ENV=production
6
5
ENV 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
14
6
15
- FROM node:16-alpine
16
- RUN apk add --no-cache vips-dev
17
- ARG NODE_ENV=production
18
- ENV NODE_ENV=${NODE_ENV}
19
7
WORKDIR /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
27
11
{%- 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 %}
35
15
ENV PATH /opt/node_modules/.bin:$PATH
36
- RUN npm install --production
37
16
WORKDIR /opt/app
38
- COPY ./ .
17
+ COPY . .
18
+ {%- if packageManager == "yarn" %}
19
+ RUN yarn build
20
+ {%- else %}
39
21
RUN npm run build
22
+ {%- endif %}
40
23
24
+ # Creating final production image
41
25
FROM 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
43
27
RUN apk add --no-cache vips-dev
44
28
ARG NODE_ENV=production
45
29
ENV NODE_ENV=${NODE_ENV}
46
30
WORKDIR /opt/
47
31
COPY --from=build /opt/node_modules ./node_modules
48
- ENV PATH /opt/node_modules/.bin:$PATH
49
32
WORKDIR /opt/app
50
33
COPY --from=build /opt/app ./
34
+ ENV PATH /opt/node_modules/.bin:$PATH
35
+
36
+ RUN chown -R strapi:strapi /opt/app
37
+ USER strapi
51
38
EXPOSE 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