-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Dockerfile
260 lines (186 loc) · 7.07 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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
# syntax=docker/dockerfile:experimental
# @see https://laravel-news.com/multi-stage-docker-builds-for-laravel
# @see https://github.com/moby/buildkit/blob/master/frontend/dockerfile/docs/experimental.md
# ARG PHP_VERSION=7.4.12
# ARG PHP_VERSION=8.0.5
ARG PHP_VERSION=nightly
ARG NODE_VERSION=15.5.0
ARG USERNAME=khs1994
# 前端构建
FROM ${USERNAME}/node:git as frontend-builder
ARG NODE_REGISTRY=https://registry.npmjs.org
COPY frontend/package.json /app/pcit/frontend/
RUN --mount=type=cache,target=/root/.npm,id=npm_cache cd /app/pcit/frontend \
set -x \
# && npm install cross-env --registry=${NODE_REGISTRY} \
# && npm install --registry=${NODE_REGISTRY} --production
&& npm install --registry=${NODE_REGISTRY}
COPY ./frontend/tsconfig.json /app/pcit/frontend/
COPY ./frontend/webpack.config.js /app/pcit/frontend/
COPY ./frontend/images /app/pcit/frontend/images
COPY ./frontend/js /app/pcit/frontend/js
COPY ./frontend/html /app/pcit/frontend/html
COPY ./frontend/css /app/pcit/frontend/css
COPY ./frontend/src /app/pcit/frontend/src
RUN set -x \
&& cd /app/pcit/frontend \
&& npm run build
# 安装 composer 依赖
FROM ${USERNAME}/php:7.4.12-composer-alpine as composer
COPY composer.json /app/pcit/
COPY src /app/pcit/src/
RUN --mount=type=cache,target=/tmp/composer/cache,id=composer_cache cd /app/pcit \
set -x \
&& composer config -g --unset repos.packagist \
&& composer install --no-dev \
&& rm -rf src app
# 整合项目
FROM ${USERNAME}/php:${PHP_VERSION}-cli-alpine as dump
COPY --from=composer /app/pcit/vendor /app/pcit/vendor
COPY . /app/pcit
COPY --from=frontend-builder /app/pcit/public/ /app/pcit/public/
RUN set -x \
&& rm -rf /app/pcit/Dockerfile \
&& rm -rf /app/pcit/frontend \
&& rm -rf /app/pcit/.docker \
\
&& /app/pcit/bin/pcit developer:plugin \
&& rm -rf /app/pcit/plugins
# ==> pcit
FROM --platform=$TARGETPLATFORM ${USERNAME}/php:${PHP_VERSION}-cli-alpine as pcit
ARG VCS_REF="unknow"
ARG UI_VCS_REF="unknow"
LABEL org.opencontainers.image.revision=$VCS_REF \
ui.revision=$UI_VCS_REF \
org.opencontainers.image.source="https://github.com/pcit-ce/pcit"
COPY --from=dump /app/pcit/ /app/pcit/
ENTRYPOINT ["/app/pcit/bin/pcitd"]
# ENTRYPOINT ["/app/pcit/bin/pcit"]
CMD ["up"]
# CMD ["server"]
# CMD ["agent"]
# ==> cli
FROM --platform=$TARGETPLATFORM ${USERNAME}/php:${PHP_VERSION}-cli-alpine as pcit_cli
ARG VCS_REF="unknow"
ARG UI_VCS_REF="unknow"
LABEL org.opencontainers.image.revision=$VCS_REF \
ui.revision=$UI_VCS_REF \
org.opencontainers.image.source="https://github.com/pcit-ce/pcit"
COPY --from=dump /app/pcit/ /app/pcit/
VOLUME [ "/workspace" ]
WORKDIR /workspace
ENTRYPOINT ["/app/pcit/bin/pcit"]
CMD ["list"]
# ==> fpm
FROM --platform=$TARGETPLATFORM ${USERNAME}/php:${PHP_VERSION}-fpm-alpine as pcit_fpm
ARG VCS_REF="unknow"
ARG UI_VCS_REF="unknow"
LABEL org.opencontainers.image.revision=$VCS_REF \
ui.revision=$UI_VCS_REF \
org.opencontainers.image.source="https://github.com/pcit-ce/pcit"
COPY --from=dump /app/pcit/ /app/.pcit/
COPY .docker/fpm/docker-entrypoint.sh /
ENV CI_DAEMON_ENABLED=true
ENTRYPOINT [ "sh","/docker-entrypoint.sh" ]
CMD ["up"]
# CMD ["server"]
# ==> nginx unit
FROM --platform=$TARGETPLATFORM ${USERNAME}/php:${PHP_VERSION}-unit-alpine as unit
RUN --mount=type=bind,from=khs1994/s6:2.1.0.1,source=/,target=/tmp/s6 \
set -x \
&& tar -zxvf /tmp/s6/s6-overlay.tar.gz -C / \
# https://github.com/MinchinWeb/docker-base/commit/f5e350dcf3523a424772a1e42a3dba3200d7a2aa
&& ln -s /init /s6-init
ARG VCS_REF="unknow"
ARG UI_VCS_REF="unknow"
LABEL org.opencontainers.image.revision=$VCS_REF \
ui.revision=$UI_VCS_REF \
org.opencontainers.image.source="https://github.com/pcit-ce/pcit"
COPY --from=dump /app/pcit/ /app/pcit/
COPY .docker/unit/docker-entrypoint.sh /
COPY .docker/unit/config.json /etc/nginx-unit/
COPY .docker/unit/services.d /etc/services.d
EXPOSE 80
ENV CI_DAEMON_ENABLED=true
ENTRYPOINT [ "sh","/docker-entrypoint.sh" ]
CMD ["up"]
# CMD ["server"]
# ==> nginx unit + dockerd + pcitd (all in one)
FROM --platform=$TARGETPLATFORM docker:dind as all-in-one
COPY --from=khs1994/php:nightly-unit-alpine /usr/local/ /usr/local
COPY --from=redis:6.0.6-alpine /usr/local/bin /usr/local/bin/
RUN set -x \
# && sed -i "s/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g" /etc/apk/repositories \
&& runDeps="$( \
scanelf --needed --nobanner --format '%n#p' --recursive /usr/local \
| tr ',' '\n' \
| sort -u \
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
)" \
&& apk add --no-cache $runDeps \
tzdata \
bash \
curl \
\
&& mkdir -p /usr/local/etc/redis /data \
&& echo > /usr/local/etc/redis/redis.conf \
\
&& mkdir -p /var/log/nginx-unit /usr/local/nginx-unit/tmp \
&& ln -sf /dev/stdout /var/log/nginx-unit/nginx-unit.log \
&& ln -sf /dev/stdout /var/log/nginx-unit/access.log \
\
&& php -v \
&& php -d error_reporting=22527 -d display_errors=1 -r 'var_dump(iconv("UTF-8", "UTF-8//IGNORE", "This is the Euro symbol '\''€'\''."));' \
\
&& dockerd -v \
\
&& unitd --version \
\
&& redis-server -v
RUN --mount=type=bind,from=khs1994/s6:2.1.0.1,source=/,target=/tmp/s6 \
set -x \
&& tar -zxvf /tmp/s6/s6-overlay.tar.gz -C / \
# https://github.com/MinchinWeb/docker-base/commit/f5e350dcf3523a424772a1e42a3dba3200d7a2aa
&& ln -s /init /s6-init
COPY --from=khs1994/php:nightly-composer-alpine /usr/bin/composer /usr/bin/composer
COPY .docker/unit/docker-entrypoint.sh /
COPY .docker/unit/config.json /etc/nginx-unit/
COPY .docker/unit/services.d /etc/services.d
ARG VCS_REF="unknow"
ARG UI_VCS_REF="unknow"
LABEL org.opencontainers.image.revision=$VCS_REF \
ui.revision=$UI_VCS_REF \
org.opencontainers.image.source="https://github.com/pcit-ce/pcit"
COPY --from=dump /app/pcit/ /app/pcit/
EXPOSE 80
ENV CI_DAEMON_ENABLED=true
ENV CI_REDIS_HOST=127.0.0.1
ENTRYPOINT [ "sh","/docker-entrypoint.sh" ]
CMD ["up"]
# CMD ["server"]
# dockerd
VOLUME [ "/var/lib/docker" ]
# redis-server
VOLUME [ "/data" ]
# nginx unit
VOLUME [ "/usr/local/nginx-unit/tmp", "/usr/local/nginx-unit/state" ]
# vscode remote
VOLUME [ "/root/.vscode-server", "/root/.vscode-server-insiders" ]
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 CMD [ "curl", "-f", "127.0.0.1:80/api/healthz" ]
# ==> 前端资源
FROM --platform=$TARGETPLATFORM alpine as frontend
ARG VCS_REF="unknow"
ARG UI_VCS_REF="unknow"
LABEL org.opencontainers.image.revision=$VCS_REF \
ui.revision=$UI_VCS_REF \
org.opencontainers.image.source="https://github.com/pcit-ce/ui"
COPY --from=dump /app/pcit/public/ /app/pcit/public/
VOLUME /var/www/pcit/public
CMD ["cp","-r","/app/pcit/public/","/var/www/pcit/"]
#
# $ docker buildx build -t pcit/pcit --target=pcit .
#
# $ docker buildx build -t pcit/pcit --target=frontend .
#
# @link https://docs.docker.com/develop/develop-images/multistage-build/#stop-at-a-specific-build-stage
#