-
Notifications
You must be signed in to change notification settings - Fork 22
/
Dockerfile
189 lines (168 loc) · 5.94 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#######
## Website
#######
FROM node:18.19.1-bookworm-slim as build-website
### FRONT_ARG_REPLACER ###
WORKDIR /wepublish
COPY . .
RUN npm ci
RUN npx nx build ${NEXT_PROJECT}
RUN bash /wepublish/deployment/map-secrets.sh clean
FROM node:18.19.1-bookworm-slim as website
MAINTAINER WePublish Foundation
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
ENV HOSTNAME=0.0.0.0
ENV ADDRESS=0.0.0.0
ENV PORT=4000
### FRONT_ARG_REPLACER ###
WORKDIR /wepublish
RUN groupadd -r wepublish && \
useradd -r -g wepublish -d /wepublish wepublish && \
chown -R wepublish:wepublish /wepublish && \
echo "#!/bin/bash\n bash /wepublish/map-secrets.sh restore && node /wepublish/apps/${NEXT_PROJECT}/server.js" > /entrypoint.sh && \
chown -R wepublish:wepublish /entrypoint.sh && \
chmod +x /entrypoint.sh
COPY --chown=wepublish:wepublish --from=build-website /wepublish/dist/apps/${NEXT_PROJECT}/.next/standalone /wepublish
COPY --chown=wepublish:wepublish --from=build-website /wepublish/dist/apps/${NEXT_PROJECT}/public /wepublish/apps/${NEXT_PROJECT}/public
COPY --chown=wepublish:wepublish --from=build-website /wepublish/dist/apps/${NEXT_PROJECT}/.next/static /wepublish/apps/${NEXT_PROJECT}/public/_next/static
COPY --chown=wepublish:wepublish --from=build-website /wepublish/secrets_name.list /wepublish/secrets_name.list
COPY --chown=wepublish:wepublish --from=build-website /wepublish/deployment/map-secrets.sh /wepublish/map-secrets.sh
EXPOSE 4001
USER wepublish
ENTRYPOINT ["/entrypoint.sh"]
#######
## API
#######
FROM node:18.19.1-bookworm-slim as build-api
WORKDIR /wepublish
COPY . .
RUN apt-get update && \
apt-get install -y --no-install-recommends openssl && \
npm ci && \
npm install -g pkg && \
npx nx build api-example && \
cp docker/api_build_package.json package.json && \
pkg package.json
FROM debian:bookworm-slim as api
MAINTAINER WePublish Foundation
ENV NODE_ENV=production
ENV ADDRESS=0.0.0.0
ENV PORT=4000
WORKDIR /wepublish
RUN groupadd -r wepublish && \
useradd -r -g wepublish -d /wepublish wepublish && \
chown -R wepublish:wepublish /wepublish && \
apt-get update && \
apt-get install -y --no-install-recommends openssl && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
COPY --chown=wepublish:wepublish apps/api-example/src/default.yaml /wepublish/config/default.yaml
COPY --chown=wepublish:wepublish --from=build-api /wepublish/api /wepublish
COPY --chown=wepublish:wepublish --from=build-api /wepublish/node_modules/bcrypt node_modules/bcrypt
EXPOSE 4000
USER wepublish
CMD /wepublish/api
#######
## Editor
#######
FROM node:18.19.1-bookworm-slim as build-editor
WORKDIR /wepublish
COPY . .
RUN npm ci && \
npm install -g pkg && \
npx nx build editor && \
cp docker/editor_build_package.json package.json && \
pkg package.json
FROM debian:bookworm-slim as editor
MAINTAINER WePublish Foundation
ENV NODE_ENV=production
ENV ADDRESS=0.0.0.0
ENV PORT=3000
WORKDIR /wepublish
RUN groupadd -r wepublish && \
useradd -r -g wepublish -d /wepublish wepublish && \
chown -R wepublish:wepublish /wepublish
COPY --chown=wepublish:wepublish --from=build-editor /wepublish/editor /wepublish
COPY --chown=wepublish:wepublish --from=build-editor /wepublish/dist/apps/editor/browser dist/apps/editor/browser
EXPOSE 3000
USER wepublish
CMD /wepublish/editor
#######
## Migrations
#######
FROM node:18.19.1-bookworm-slim as build-migration
ENV NODE_ENV=production
WORKDIR /wepublish
COPY libs/settings/api/src/lib/setting.ts settings/api/src/lib/setting.ts
COPY libs/api/prisma/run-seed.ts api/prisma/run-seed.ts
COPY libs/api/prisma/seed.ts api/prisma/seed.ts
COPY docker/tsconfig.yaml_seed tsconfig.yaml
RUN npm install prisma @prisma/client @types/node bcrypt typescript && \
npx tsc -p tsconfig.yaml
FROM node:18.19.1-bookworm-slim as migration
ENV NODE_ENV=production
MAINTAINER WePublish Foundation
WORKDIR /wepublish
COPY --from=build-migration /wepublish/dist ./dist
COPY libs/api/prisma/migrations prisma/migrations
COPY libs/api/prisma/schema.prisma prisma/schema.prisma
COPY docker/migrate_start.sh start.sh
RUN groupadd -r wepublish && \
useradd -r -g wepublish -d /wepublish wepublish && \
apt-get update && \
apt-get install -y --no-install-recommends openssl && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* && \
npm install prisma bcrypt && \
perl -i -0777 -pe 's/generator fabbrica \{\n provider = "prisma-fabbrica"\n output = "\.\.\/\.\.\/testing\/src\/__generated__\/fabbrica"\n\}//gs' prisma/schema.prisma && \
npx prisma generate \
USER wepublish
CMD ["bash", "./start.sh"]
#######
## Media Server
#######
FROM node:18.20.4-bullseye-slim AS base-media
FROM base-media AS build-media
ENV LD_PRELOAD="/usr/lib/x86_64-linux-gnu/libjemalloc.so"
WORKDIR /app
RUN apt-get update
RUN apt-get install -y libjemalloc-dev
COPY . .
COPY ./apps/media/package.json ./package.json
COPY ./apps/media/package-lock.json ./package-lock.json
RUN npm ci
RUN npx nx build media
FROM base-media AS media
ENV NODE_ENV=production
MAINTAINER WePublish Foundation
WORKDIR /wepublish
ENV LD_PRELOAD="/usr/lib/x86_64-linux-gnu/libjemalloc.so"
RUN groupadd -r wepublish && \
useradd -r -g wepublish -d /wepublish wepublish && \
apt-get update && \
apt-get install -y libjemalloc-dev && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
COPY --from=build-media /app/dist/apps/media/ .
COPY --from=build-media --chown=wepublish:wepublish /app/node_modules ./node_modules
USER wepublish
EXPOSE 4100
CMD ["node", "main.js"]
######
## Storybook
######
FROM ghcr.io/wepublish/node:18.1 as dependencies
RUN apk update
USER node
RUN mkdir -p /home/node/wepublish
WORKDIR /home/node/wepublish
COPY --chown=node:node . .
RUN rm -rf .env
RUN npm ci
FROM dependencies as storybook-builder
RUN npx nx run website:build-storybook
FROM nginx:alpine as storybook
COPY --from=storybook-builder /home/node/wepublish/dist/storybook/website /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]