-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile.3.0.xquic
167 lines (158 loc) · 8.09 KB
/
Dockerfile.3.0.xquic
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
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_tongsuo_ntls
# 编译 tongsuo
## Set arg for downloaded source code version.
## 这里配置你下载的源码版本。必须与文件名对应
ARG TONGSUO_VERISON=8.3.2
## Copy source code into container
## 这里复制源码到容器内
COPY sources/Tongsuo-${TONGSUO_VERISON}.tar.gz /usr/src/
RUN set -xe\
&& MAKEARG="-j${BUILD_THREADS:-1}"\
# 参考 https://github.com/alibaba/tengine/blob/master/modules/ngx_http_xquic_module/README.md#%E7%BC%96%E8%AF%91
&& tar -zxC /usr/src -f /usr/src/Tongsuo-${TONGSUO_VERISON}.tar.gz\
&& cd /usr/src/Tongsuo-${TONGSUO_VERISON}\
&& ./config --prefix=/usr/local/babassl\
&& make ${MAKEARG}\
# 精简内容
&& rm -rf doc\
&& make install\
# 复制到dst目录
&& mkdir -p ${TARGER}/usr/local/ && cp -rv /usr/local/babassl ${TARGER}/usr/local/babassl
# 编译 xquic
## Set arg for downloaded source code version.
## 这里配置你下载的源码版本。必须与文件名对应
ARG XQUIC_VERISON=1.6.1
## Copy source code into container
## 这里复制源码到容器内
COPY sources/xquic-${XQUIC_VERISON}.tar.gz /usr/src/
RUN set -xe\
&& MAKEARG="-j${BUILD_THREADS:-1}"\
&& tar -zxC /usr/src -f /usr/src/xquic-${XQUIC_VERISON}.tar.gz\
&& mkdir -p /usr/local/xquic\
&& cd /usr/local/xquic\
&& cmake -DGCOV=on -DXQC_ENABLE_TESTING=1 -DXQC_SUPPORT_SENDMMSG_BUILD=1\
-DXQC_ENABLE_EVENT_LOG=1 -DXQC_ENABLE_BBR2=1 -DXQC_ENABLE_RENO=1\
-DSSL_TYPE="babassl" -DSSL_PATH="/usr/local/babassl"\
-DSSL_INC_PATH="/usr/local/babassl/include"\
-DSSL_LIB_PATH="/usr/local/babassl/lib/libssl.a;/usr/local/babassl/lib/libcrypto.a" /usr/src/xquic-${XQUIC_VERISON}\
&& make ${MAKEARG}\
&& mkdir -p /usr/local/lib/ ${TARGER}/usr/local/lib/\
&& ln -s ../xquic/libxquic.so /usr/local/lib/libxquic.so\
&& ln -s ../xquic/libxquic.so ${TARGER}/usr/local/lib/libxquic.so\
&& cp -rv /usr/local/xquic ${TARGER}/usr/local/xquic
# 编译 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/
COPY patchs/${TENGINE_VERSION}/ /usr/src/patchs/
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}\
&& (for file in /usr/src/patchs/*.diff; do patch -p0 < ${file}; done)\
&& ADD_MODULES="${ADD_MODULES} "`./configure --help | grep '\-\-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_upstream_keepalive|http_lua|http_tfs|ingress|tongsuo_ntls)' | awk '{printf "--add-module=modules/"$1" "}'`\
&& ./configure --user=tengine --group=tengine\
--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"\
${ADD_MODULES}\
--with-xquic-inc="/usr/src/xquic-${XQUIC_VERISON}/include" \
--with-xquic-lib="/usr/local/xquic" \
--with-openssl="/usr/src/Tongsuo-${TONGSUO_VERISON}"\
&& 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;"]