-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile.3.0.dynamic
122 lines (115 loc) · 6.29 KB
/
Dockerfile.3.0.dynamic
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
FROM alpine as env
WORKDIR /etc/tengine
ARG APK_MIRROR
ARG APK_MIRROR_HTTPS
RUN --mount=type=cache,target=/cache\
set -xe;\
[ ! -z "${APK_MIRROR}" -a "${APK_MIRROR}" != "dl-cdn.alpinelinux.org" ]\
&& sed -i "s/dl-cdn.alpinelinux.org/${APK_MIRROR}/g" /etc/apk/repositories ;\
[ ! -z "${APK_MIRROR_HTTPS}" ]\
&& sed -e "s!http://!https://!g" -i /etc/apk/repositories;\
apk add --update --cache-dir /cache/apk\
libmaxminddb pcre openssl zlib libxslt gd geoip libedit perl lua yajl\
&& addgroup tengine\
&& adduser -s /sbin/nologin -G tengine -D -H tengine
FROM env AS build_env
WORKDIR /cache
# For latest build deps, see https://github.com/nginxinc/docker-nginx/blob/master/mainline/alpine/Dockerfile
# 本来是看 https://github.com/nginxinc/docker-nginx/blob/master/mainline/alpine/Dockerfile 里面的依赖,但由于tengine依赖不同,我又加了一些
RUN --mount=type=cache,target=/cache\
set -xe\
&& apk add --update --cache-dir /cache/apk --virtual .build-deps \
gcc6 libc-dev make openssl-dev pcre-dev \
zlib-dev linux-headers libxslt-dev gd-dev \
geoip-dev libedit-dev perl-dev lua-dev yajl-dev mercurial \
gnupg alpine-sdk findutils cmake libevent-dev
# You can build with `--target=env` and `--target=build_env` to cache the environment.
# Then add `--cache-from boringcat/tengine:env --cache-from boringcat/tengine:build_env` to your main
# build.
# It is useful for multi version builded.
# 你可以在 build 的时候加参数 --target=env 和 --target=build_env 来创建环境缓存
# build 环境通常极大,并且各版本之间没有多大差异
# 通过在 build 命令行中添加 `--cache-from boringcat/tengine:env --cache-from boringcat/tengine:build_env`
# 以使用缓存
FROM build_env as builder
WORKDIR /usr/src/
ARG BUILD_THREADS=1
ARG TARGER=/dst
# modules info:
# 使用的模块信息:
# with all '--with' option and all modules exclude:
# 启用了所有'--with'的选型,并且加载了所有模块,除了下面的这些:
# --with-google_perftools_module enable ngx_google_perftools_module
# --with-compat dynamic modules compatibility
# --with-http_lua_module enable ngx_http_lua_module (will also enable --with-md5 and --with-sha1)
# --with-http_perl_module enable ngx_http_perl_module
# --with-pcre force PCRE library usage
# --with-pcre=DIR set path to PCRE library sources
# --with-pcre-opt=OPTIONS set additional build options for PCRE
# --with-pcre-jit build PCRE with JIT compilation support
# --with-libatomic force libatomic_ops library usage
# --with-libatomic=DIR set path to libatomic_ops library sources
# --with-jemalloc force jemalloc library usage
# --with-jemalloc=DIR set path to jemalloc library files
# --with-debug enable debug logging
# modules/mod_config
# modules/mod_dubbo
# modules/ngx_backtrace_module
# modules/ngx_debug_pool
# modules/ngx_debug_timer
# modules/ngx_http_lua_module
# modules/ngx_http_upstream_keepalive_module
# modules/ngx_http_tfs_module
# modules/ngx_ingress
# modules/ngx_http_xquic_module
# modules/ngx_tongsuo_ntls
# 编译 Tengine
## Set arg for downloaded source code version.
## 这里配置你下载的源码版本。必须与文件名对应
ARG TENGINE_VERSION
ARG BROTLI_VERISON=1.0.0rc
## Copy source code into container
## 这里复制源码到容器内
COPY sources/tengine-${TENGINE_VERSION}.tar.gz\
sources/ngx_brotli-${BROTLI_VERISON}.tar.gz\
/usr/src/
RUN set -xe\
&& MAKEARG="-j${BUILD_THREADS:-1}"\
&& tar -zxC /usr/src -f /usr/src/tengine-${TENGINE_VERSION}.tar.gz\
&& tar -zxC /usr/src/tengine-${TENGINE_VERSION}/modules -f /usr/src/ngx_brotli-${BROTLI_VERISON}.tar.gz\
&& mv /usr/src/tengine-${TENGINE_VERSION}/modules/ngx_brotli-${BROTLI_VERISON} /usr/src/tengine-${TENGINE_VERSION}/modules/ngx_brotli\
&& cd /usr/src/tengine-${TENGINE_VERSION}\
&& ADD_MODULES="${ADD_MODULES} "`./configure --help | grep -E '\--with-.+?=dynamic' | awk '{printf $1" "}'`\
&& ADD_MODULES="${ADD_MODULES} "`./configure --help | grep -E '\--with-[^ =]+?[^=] ' | grep -Ev 'with-(debug|compat|pcre|jemalloc|libatomic|google_perftools_module|http_lua|http_perl)' | awk '{printf $1" "}'`\
&& ADD_MODULES="${ADD_MODULES} "`ls modules/ | grep -Ev '^mod*|debug|ngx_(backtrace|http_lua|http_tfs|ingress|http_xquic_module|tongsuo_ntls)' | awk '{ if ($1 ~ /^ngx_multi_upstream_module$/) {printf "--add-module=modules/"$1" "} else {printf "--add-dynamic-module=modules/"$1" "}}'`\
&& ./configure --user=tengine --group=tengine --with-compat\
--sbin-path="/usr/local/sbin/nginx"\
--modules-path="/etc/tengine/modules"\
--conf-path="/etc/tengine/conf/nginx.conf"\
--error-log-path="/var/log/tengine/error.log"\
--pid-path="/var/log/tengine/nginx.pid"\
--lock-path="/var/log/tengine/nginx.lock"\
--http-client-body-temp-path="/var/cache/tengine/client_body_temp"\
--http-proxy-temp-path="/var/cache/tengine/proxy_temp"\
--http-fastcgi-temp-path="/var/cache/tengine/fastcgi_temp"\
--http-uwsgi-temp-path="/var/cache/tengine/uwsgi_temp"\
--http-scgi-temp-path="/var/cache/tengine/scgi_temp"\
--without-http_upstream_keepalive_module\
${ADD_MODULES}\
&& make ${MAKEARG} && env DESTDIR=${TARGER} make install\
&& mkdir -p ${TARGER}/var/cache/tengine/{client_body_temp,proxy_temp,fastcgi_temp,uwsgi_temp,scgi_temp}\
# Create custom environment for tengine
&& sed -e '/\s*server {$/,/^}$/!d' ${TARGER}/etc/tengine/conf/nginx.conf > ${TARGER}/etc/tengine/conf/example.conf\
&& sed -e '/\s*server {$/,/^}$/d' -i ${TARGER}/etc/tengine/conf/nginx.conf\
&& echo " include /etc/tengine/conf/conf.d/*.conf;" >> ${TARGER}/etc/tengine/conf/nginx.conf\
&& echo "}" >> ${TARGER}/etc/tengine/conf/nginx.conf\
&& sed -e 's/^}$//g;s/^ //g;/^$/d;' -i ${TARGER}/etc/tengine/conf/example.conf\
&& sed -e 's/worker_processes.*/worker_processes auto;/g;/worker_connections/i\ \ \ \ use epoll;' -i ${TARGER}/etc/tengine/conf/nginx.conf\
&& cat ${TARGER}/etc/tengine/conf/nginx.conf
FROM env as final
ARG TARGER=/dst
COPY --from=builder /${TARGER}/ /
STOPSIGNAL SIGTERM
VOLUME [ "/etc/tengine/conf/conf.d", "/var/log/tengine" ]
EXPOSE 80 443
CMD ["nginx", "-g", "daemon off;"]