forked from directus/directus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
71 lines (53 loc) · 1.81 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
# syntax=docker/dockerfile:1.4
####################################################################################################
## Build Packages
FROM node:18-alpine AS builder
ARG TARGETPLATFORM
RUN <<EOF
if [ "$TARGETPLATFORM" = 'linux/arm64' ]; then
apk --no-cache add python3 build-base
ln -sf /usr/bin/python3 /usr/bin/python
fi
EOF
WORKDIR /directus
COPY package.json .
RUN corepack enable && corepack prepare
# Deploy as 'node' user to match pnpm setups in production image
# (see https://github.com/directus/directus/issues/23822)
RUN chown node:node .
USER node
ENV NODE_OPTIONS=--max-old-space-size=8192
COPY pnpm-lock.yaml .
RUN pnpm fetch
COPY --chown=node:node . .
RUN <<EOF
pnpm install --recursive --offline --frozen-lockfile
npm_config_workspace_concurrency=1 pnpm run build
pnpm --filter directus deploy --prod dist
cd dist
# Regenerate package.json file with essential fields only
# (see https://github.com/directus/directus/issues/20338)
node -e '
const f = "package.json", {name, version, type, exports, bin} = require(`./${f}`), {packageManager} = require(`../${f}`);
fs.writeFileSync(f, JSON.stringify({name, version, type, exports, bin, packageManager}, null, 2));
'
mkdir -p database extensions uploads
EOF
####################################################################################################
## Create Production Image
FROM node:18-alpine AS runtime
RUN npm install --global pm2@5
USER node
WORKDIR /directus
ENV \
DB_CLIENT="sqlite3" \
DB_FILENAME="/directus/database/database.sqlite" \
NODE_ENV="production" \
NPM_CONFIG_UPDATE_NOTIFIER="false"
COPY --from=builder --chown=node:node /directus/ecosystem.config.cjs .
COPY --from=builder --chown=node:node /directus/dist .
EXPOSE 8055
CMD : \
&& node cli.js bootstrap \
&& pm2-runtime start ecosystem.config.cjs \
;