Dockerfile 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. # Dockerfile - alpine
  2. # https://github.com/openresty/docker-openresty
  3. ARG RESTY_IMAGE_BASE="alpine"
  4. ARG RESTY_IMAGE_TAG="3.13"
  5. FROM ${RESTY_IMAGE_BASE}:${RESTY_IMAGE_TAG}
  6. LABEL maintainer="Evan Wies <evan@neomantra.net>"
  7. # Docker Build Arguments
  8. ARG RESTY_IMAGE_BASE="alpine"
  9. ARG RESTY_IMAGE_TAG="3.13"
  10. ARG RESTY_VERSION="1.19.3.2"
  11. ARG RESTY_OPENSSL_VERSION="1.1.1k"
  12. ARG RESTY_OPENSSL_PATCH_VERSION="1.1.1f"
  13. ARG RESTY_OPENSSL_URL_BASE="https://www.openssl.org/source"
  14. ARG RESTY_PCRE_VERSION="8.44"
  15. ARG RESTY_J="1"
  16. ARG RESTY_CONFIG_OPTIONS="\
  17. --with-compat \
  18. --with-file-aio \
  19. --with-http_addition_module \
  20. --with-http_auth_request_module \
  21. --with-http_dav_module \
  22. --with-http_flv_module \
  23. --with-http_geoip_module=dynamic \
  24. --with-http_gunzip_module \
  25. --with-http_gzip_static_module \
  26. --with-http_image_filter_module=dynamic \
  27. --with-http_mp4_module \
  28. --with-http_random_index_module \
  29. --with-http_realip_module \
  30. --with-http_secure_link_module \
  31. --with-http_slice_module \
  32. --with-http_ssl_module \
  33. --with-http_stub_status_module \
  34. --with-http_sub_module \
  35. --with-http_v2_module \
  36. --with-http_xslt_module=dynamic \
  37. --with-ipv6 \
  38. --with-mail \
  39. --with-mail_ssl_module \
  40. --with-md5-asm \
  41. --with-pcre-jit \
  42. --with-sha1-asm \
  43. --with-stream \
  44. --with-stream_ssl_module \
  45. --with-threads \
  46. "
  47. ARG RESTY_CONFIG_OPTIONS_MORE="\
  48. --conf-path=/etc/nginx/nginx.conf \
  49. --error-log-path=/var/log/nginx/error.log \
  50. --http-log-path=/var/log/nginx/access.log \
  51. --pid-path=/var/run/nginx.pid \
  52. --user=www-data \
  53. --group=www-data \
  54. --with-http_iconv_module \
  55. --add-module=/tmp/nginx-ct-master \
  56. --add-module=/tmp/nginx-dav-ext-module-master \
  57. --add-module=/tmp/ngx_brotli-master \
  58. --add-module=/tmp/ngx_cache_purge-master \
  59. --add-module=/tmp/ngx_http_substitutions_filter_module-master \
  60. "
  61. ARG RESTY_LUAJIT_OPTIONS="--with-luajit-xcflags='-DLUAJIT_NUMMODE=2 -DLUAJIT_ENABLE_LUA52COMPAT'"
  62. ARG RESTY_ADD_PACKAGE_BUILDDEPS=""
  63. ARG RESTY_ADD_PACKAGE_RUNDEPS=""
  64. ARG RESTY_EVAL_PRE_CONFIGURE=""
  65. ARG RESTY_EVAL_POST_MAKE=""
  66. # These are not intended to be user-specified
  67. ARG _RESTY_CONFIG_DEPS="--with-pcre \
  68. --with-cc-opt='-DNGX_LUA_ABORT_AT_PANIC -I/usr/local/openresty/pcre/include -I/usr/local/openresty/openssl/include' \
  69. --with-ld-opt='-L/usr/local/openresty/pcre/lib -L/usr/local/openresty/openssl/lib -Wl,-rpath,/usr/local/openresty/pcre/lib:/usr/local/openresty/openssl/lib' \
  70. "
  71. LABEL resty_image_base="${RESTY_IMAGE_BASE}"
  72. LABEL resty_image_tag="${RESTY_IMAGE_TAG}"
  73. LABEL resty_version="${RESTY_VERSION}"
  74. LABEL resty_openssl_version="${RESTY_OPENSSL_VERSION}"
  75. LABEL resty_openssl_patch_version="${RESTY_OPENSSL_PATCH_VERSION}"
  76. LABEL resty_openssl_url_base="${RESTY_OPENSSL_URL_BASE}"
  77. LABEL resty_pcre_version="${RESTY_PCRE_VERSION}"
  78. LABEL resty_config_options="${RESTY_CONFIG_OPTIONS}"
  79. LABEL resty_config_options_more="${RESTY_CONFIG_OPTIONS_MORE}"
  80. LABEL resty_config_deps="${_RESTY_CONFIG_DEPS}"
  81. LABEL resty_add_package_builddeps="${RESTY_ADD_PACKAGE_BUILDDEPS}"
  82. LABEL resty_add_package_rundeps="${RESTY_ADD_PACKAGE_RUNDEPS}"
  83. LABEL resty_eval_pre_configure="${RESTY_EVAL_PRE_CONFIGURE}"
  84. LABEL resty_eval_post_make="${RESTY_EVAL_POST_MAKE}"
  85. ARG CHANGE_SOURCE=false
  86. RUN if [ ${CHANGE_SOURCE} = true ]; then \
  87. # Change application source from dl-cdn.alpinelinux.org to aliyun source
  88. sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/' /etc/apk/repositories \
  89. ;fi
  90. RUN set -x ; \
  91. addgroup -g 82 -S www-data ; \
  92. adduser -u 82 -D -S -G www-data www-data && exit 0 ; exit 1
  93. RUN apk add --no-cache --virtual .build-deps \
  94. build-base \
  95. coreutils \
  96. curl \
  97. gd-dev \
  98. geoip-dev \
  99. git \
  100. libxslt-dev \
  101. linux-headers \
  102. make \
  103. perl-dev \
  104. readline-dev \
  105. zlib-dev \
  106. ${RESTY_ADD_PACKAGE_BUILDDEPS} \
  107. && apk add --no-cache \
  108. gd \
  109. geoip \
  110. libgcc \
  111. libxslt \
  112. zlib \
  113. bash \
  114. logrotate \
  115. openssl \
  116. ${RESTY_ADD_PACKAGE_RUNDEPS} \
  117. && cd /tmp \
  118. && if [ -n "${RESTY_EVAL_PRE_CONFIGURE}" ]; then eval $(echo ${RESTY_EVAL_PRE_CONFIGURE}); fi \
  119. && cd /tmp \
  120. && curl -fSL "${RESTY_OPENSSL_URL_BASE}/openssl-${RESTY_OPENSSL_VERSION}.tar.gz" -o openssl-${RESTY_OPENSSL_VERSION}.tar.gz \
  121. && tar xzf openssl-${RESTY_OPENSSL_VERSION}.tar.gz \
  122. && cd openssl-${RESTY_OPENSSL_VERSION} \
  123. && if [ $(echo ${RESTY_OPENSSL_VERSION} | cut -c 1-5) = "1.1.1" ] ; then \
  124. echo 'patching OpenSSL 1.1.1 for OpenResty' \
  125. && curl -s https://raw.githubusercontent.com/openresty/openresty/master/patches/openssl-${RESTY_OPENSSL_PATCH_VERSION}-sess_set_get_cb_yield.patch | patch -p1 ; \
  126. fi \
  127. && if [ $(echo ${RESTY_OPENSSL_VERSION} | cut -c 1-5) = "1.1.0" ] ; then \
  128. echo 'patching OpenSSL 1.1.0 for OpenResty' \
  129. && curl -s https://raw.githubusercontent.com/openresty/openresty/ed328977028c3ec3033bc25873ee360056e247cd/patches/openssl-1.1.0j-parallel_build_fix.patch | patch -p1 \
  130. && curl -s https://raw.githubusercontent.com/openresty/openresty/master/patches/openssl-${RESTY_OPENSSL_PATCH_VERSION}-sess_set_get_cb_yield.patch | patch -p1 ; \
  131. fi \
  132. && ./config \
  133. no-threads shared zlib -g \
  134. enable-ssl3 enable-ssl3-method \
  135. --prefix=/usr/local/openresty/openssl \
  136. --libdir=lib \
  137. -Wl,-rpath,/usr/local/openresty/openssl/lib \
  138. && make -j${RESTY_J} \
  139. && make -j${RESTY_J} install_sw \
  140. && cd /tmp \
  141. && curl -fSL https://downloads.sourceforge.net/project/pcre/pcre/${RESTY_PCRE_VERSION}/pcre-${RESTY_PCRE_VERSION}.tar.gz -o pcre-${RESTY_PCRE_VERSION}.tar.gz \
  142. && tar xzf pcre-${RESTY_PCRE_VERSION}.tar.gz \
  143. && cd /tmp/pcre-${RESTY_PCRE_VERSION} \
  144. && ./configure \
  145. --prefix=/usr/local/openresty/pcre \
  146. --disable-cpp \
  147. --enable-jit \
  148. --enable-utf \
  149. --enable-unicode-properties \
  150. && make -j${RESTY_J} \
  151. && make -j${RESTY_J} install \
  152. && cd /tmp \
  153. && curl -fSL https://openresty.org/download/openresty-${RESTY_VERSION}.tar.gz -o openresty-${RESTY_VERSION}.tar.gz \
  154. && tar xzf openresty-${RESTY_VERSION}.tar.gz \
  155. && curl -fSL https://github.com/grahamedgecombe/nginx-ct/archive/master.tar.gz -o nginx-ct.tar.gz \
  156. && tar xzf nginx-ct.tar.gz \
  157. && curl -fSL https://github.com/arut/nginx-dav-ext-module/archive/master.tar.gz -o nginx-dav-ext-module.tar.gz \
  158. && tar xzf nginx-dav-ext-module.tar.gz \
  159. && cd /tmp && git clone --recursive https://github.com/google/ngx_brotli.git ngx_brotli-master \
  160. && curl -fSL https://github.com/yaoweibin/ngx_http_substitutions_filter_module/archive/master.tar.gz -o ngx_http_substitutions_filter_module.tar.gz \
  161. && tar xzf ngx_http_substitutions_filter_module.tar.gz \
  162. && curl -fSL https://github.com/FRiCKLE/ngx_cache_purge/archive/master.tar.gz -o ngx_cache_purge.tar.gz \
  163. && tar xzf ngx_cache_purge.tar.gz \
  164. && cd /tmp/openresty-${RESTY_VERSION} \
  165. && eval ./configure -j${RESTY_J} ${_RESTY_CONFIG_DEPS} ${RESTY_CONFIG_OPTIONS} ${RESTY_CONFIG_OPTIONS_MORE} ${RESTY_LUAJIT_OPTIONS} \
  166. && make -j${RESTY_J} \
  167. && make -j${RESTY_J} install \
  168. && cd /tmp \
  169. && if [ -n "${RESTY_EVAL_POST_MAKE}" ]; then eval $(echo ${RESTY_EVAL_POST_MAKE}); fi \
  170. && rm -rf \
  171. openssl-${RESTY_OPENSSL_VERSION}.tar.gz openssl-${RESTY_OPENSSL_VERSION} \
  172. pcre-${RESTY_PCRE_VERSION}.tar.gz pcre-${RESTY_PCRE_VERSION} \
  173. openresty-${RESTY_VERSION}.tar.gz openresty-${RESTY_VERSION} \
  174. && apk del .build-deps \
  175. && mkdir -p /etc/nginx/conf.d/ /var/run/openresty/
  176. # Add additional binaries into PATH for convenience
  177. ENV PATH=$PATH:/usr/local/openresty/luajit/bin:/usr/local/openresty/nginx/sbin:/usr/local/openresty/bin
  178. ARG PHP_UPSTREAM_CONTAINER=php-fpm
  179. ARG PHP_UPSTREAM_PORT=9000
  180. # Create 'messages' file used from 'logrotate'
  181. RUN touch /var/log/messages
  182. # Copy 'logrotate' config file
  183. COPY logrotate/nginx /etc/logrotate.d/
  184. # Set upstream conf and remove the default conf
  185. RUN echo "upstream php-upstream { server ${PHP_UPSTREAM_CONTAINER}:${PHP_UPSTREAM_PORT}; }" > /etc/nginx/conf.d/upstream.conf
  186. # Copy nginx configuration files
  187. COPY nginx.conf /etc/nginx/
  188. ADD ./startup.sh /opt/startup.sh
  189. RUN sed -i 's/\r//g' /opt/startup.sh
  190. CMD ["/bin/bash", "/opt/startup.sh"]
  191. EXPOSE 80 81 443