Skip to content

Commit 68c266a

Browse files
author
Simen Daehlin
committed
feat(dockerfile): added security layer, optimized image now 1.5GB on default
1 parent 94d0b08 commit 68c266a

1 file changed

Lines changed: 27 additions & 22 deletions

File tree

templates/Dockerfile.liquid

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,36 @@
1-
{%- if packageManager == "yarn" %}
21
FROM node:16-alpine
3-
# Installing libvips-dev for sharp Compatability
2+
# Installing libvips-dev for sharp Compatibility
43
RUN apk update && apk add --no-cache build-base gcc autoconf automake zlib-dev libpng-dev nasm bash vips-dev
54
ARG NODE_ENV=development
65
ENV NODE_ENV=${NODE_ENV}
6+
RUN addgroup -g 1001 strapi && adduser -u 1001 -G strapi -s /bin/sh -D strapi
7+
78
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
11-
WORKDIR /opt/app
12-
COPY ./ .
13-
RUN yarn build
14-
EXPOSE 1337
15-
CMD ["yarn", "develop"]
9+
{%- if packageManager == "yarn" %}
10+
COPY package.json yarn.lock ./
1611
{%- else %}
17-
FROM node:16-alpine
18-
# Installing libvips-dev for sharp Compatability
19-
RUN apk update && apk add --no-cache build-base gcc autoconf automake zlib-dev libpng-dev nasm bash vips-dev
20-
ARG NODE_ENV=development
21-
ENV NODE_ENV=${NODE_ENV}
22-
WORKDIR /opt/
23-
COPY ./package.json ./package-lock.json ./
12+
COPY package.json package-lock.json ./
13+
{% endif %}
2414
ENV PATH /opt/node_modules/.bin:$PATH
25-
RUN npm install
15+
RUN chown -R strapi:strapi /opt/
16+
USER strapi{%- if packageManager == "yarn" %}
17+
COPY package.json yarn.lock ./
18+
RUN yarn config set network-timeout 600000 -g && yarn install --production
19+
{%- else %}
20+
COPY package.json package-lock.json ./
21+
RUN npm config set network-timeout 600000 -g && npm install --only=production
22+
{%- endif %}
23+
2624
WORKDIR /opt/app
27-
COPY ./ .
28-
RUN npm run build
25+
COPY . .
26+
{%- if packageManager == "yarn" %}
27+
RUN ["yarn", "build"]
28+
{%- else %}
29+
RUN ["npm", "run","build"]
30+
{%- endif %}
2931
EXPOSE 1337
30-
CMD ["npm", "run", "develop"]
31-
{% endif %}
32+
{%- if packageManager == "yarn" %}
33+
CMD ["yarn", "start"]
34+
{%- else %}
35+
CMD ["npm", "run","develop"]
36+
{% endif %}

0 commit comments

Comments
 (0)