-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathDockerfile
85 lines (64 loc) · 2.9 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# This is PRODUCTION Dockerfile for Strapi in Turborepo.
# It's assumed that this Dockerfile is run from the root of the monorepo.
# Created according to following examples:
# - https://docs.strapi.io/dev-docs/installation/docker#production-dockerfile
# - https://github.com/vercel/turbo/blob/main/examples/with-docker/apps/api/Dockerfile
# - https://dev.to/moofoo/creating-a-development-dockerfile-and-docker-composeyml-for-yarn-122-monorepos-using-turborepo-896
# Customize APP (name of folder in /apps) and WORKSPACE (name from package.json) to match this app
ARG APP=strapi
ARG WORKSPACE=@repo/strapi
FROM node:20-alpine AS base
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk update && apk add --no-cache libc6-compat
# -------------------------- stage pruned ---------------------------------
FROM base AS pruned
ARG WORKSPACE
# Set working directory
WORKDIR /app
COPY . .
# see https://turbo.build/repo/docs/reference/command-line-reference#turbo-prune---scopetarget
RUN yarn global add turbo@^1.13.4
RUN turbo prune ${WORKSPACE} --docker
# -------------------------- stage installer ---------------------------------
FROM base AS installer
ARG APP
ARG WORKSPACE
ENV NODE_ENV=production
WORKDIR /app
# Install system dependencies for Strapi
RUN apk update && apk add --no-cache build-base gcc autoconf automake zlib-dev libpng-dev vips-dev git > /dev/null 2>&1
# First install dependencies (as they change less often)
COPY .gitignore .gitignore
COPY --from=pruned /app/out/json/ .
COPY --from=pruned /app/out/yarn.lock ./yarn.lock
RUN yarn global add node-gyp
RUN yarn global add turbo@^1.13.4
# see https://github.com/moby/buildkit/blob/master/frontend/dockerfile/docs/reference.md#run---mounttypecache
RUN \
--mount=type=cache,target=/usr/local/share/.cache/yarn/v6,sharing=locked \
yarn --prefer-offline --frozen-lockfile --ignore-scripts --production
# Because of yarn v1 install sharp explicitly with "--ignore-engines". See https://github.com/lovell/sharp/issues/3871
RUN \
--mount=type=cache,target=/usr/local/share/.cache/yarn/v6,sharing=locked \
yarn workspace ${WORKSPACE} add sharp --ignore-engines --prefer-offline --frozen-lockfile
ENV PATH /app/apps/${APP}/node_modules/.bin:$PATH
# Build the project and its dependencies
COPY --from=pruned /app/out/full/ .
COPY turbo.json turbo.json
RUN turbo run build --filter=${WORKSPACE}
# -------------------------- stage runner ---------------------------------
FROM base AS runner
ARG APP
ARG WORKSPACE
ENV NODE_ENV=production
RUN apk update && apk add --no-cache vips-dev
# Don't run production as root
RUN addgroup --system --gid 1001 strapi
RUN adduser --system --uid 1001 strapi
USER strapi
WORKDIR /app
COPY --from=installer /app .
ENV PATH /app/apps/${APP}/node_modules/.bin:$PATH
WORKDIR /app/apps/${APP}
EXPOSE ${PORT:-1337}
CMD ["yarn", "start"]