Dockerfile 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. # Dockerfile - alpine
  2. # https://github.com/openresty/docker-openresty
  3. ARG RESTY_IMAGE_BASE="alpine"
  4. ARG RESTY_IMAGE_TAG="3.21.3"
  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.21.3"
  10. ARG RESTY_VERSION="1.27.1.1"
  11. # https://github.com/openresty/openresty-packaging/blob/master/alpine/openresty-openssl3/APKBUILD
  12. ARG RESTY_OPENSSL_VERSION="3.0.16"
  13. ARG RESTY_OPENSSL_PATCH_VERSION="3.0.15"
  14. ARG RESTY_OPENSSL_URL_BASE="https://github.com/openssl/openssl/releases/download/openssl-${RESTY_OPENSSL_VERSION}"
  15. # LEGACY: "https://www.openssl.org/source/old/1.1.1"
  16. ARG RESTY_OPENSSL_BUILD_OPTIONS="enable-camellia enable-seed enable-rfc3779 enable-cms enable-md2 enable-rc5 \
  17. enable-weak-ssl-ciphers enable-ssl3 enable-ssl3-method enable-md2 enable-ktls enable-fips \
  18. "
  19. # https://github.com/openresty/openresty-packaging/blob/master/alpine/openresty-pcre2/APKBUILD
  20. ARG RESTY_PCRE_VERSION="10.44"
  21. ARG RESTY_PCRE_SHA256="86b9cb0aa3bcb7994faa88018292bc704cdbb708e785f7c74352ff6ea7d3175b"
  22. ARG RESTY_PCRE_BUILD_OPTIONS="--enable-jit --enable-pcre2grep-jit --disable-bsr-anycrlf --disable-coverage --disable-ebcdic --disable-fuzz-support \
  23. --disable-jit-sealloc --disable-never-backslash-C --enable-newline-is-lf --enable-pcre2-8 --enable-pcre2-16 --enable-pcre2-32 \
  24. --enable-pcre2grep-callout --enable-pcre2grep-callout-fork --disable-pcre2grep-libbz2 --disable-pcre2grep-libz --disable-pcre2test-libedit \
  25. --enable-percent-zt --disable-rebuild-chartables --enable-shared --disable-static --disable-silent-rules --enable-unicode --disable-valgrind \
  26. "
  27. ARG RESTY_J="1"
  28. # https://github.com/openresty/openresty-packaging/blob/master/alpine/openresty/APKBUILD
  29. ARG RESTY_CONFIG_OPTIONS="\
  30. --with-compat \
  31. --without-http_rds_json_module \
  32. --without-http_rds_csv_module \
  33. --without-lua_rds_parser \
  34. --without-mail_pop3_module \
  35. --without-mail_imap_module \
  36. --without-mail_smtp_module \
  37. --with-http_addition_module \
  38. --with-http_auth_request_module \
  39. --with-http_dav_module \
  40. --with-http_flv_module \
  41. --with-http_geoip_module=dynamic \
  42. --with-http_gunzip_module \
  43. --with-http_gzip_static_module \
  44. --with-http_image_filter_module=dynamic \
  45. --with-http_mp4_module \
  46. --with-http_random_index_module \
  47. --with-http_realip_module \
  48. --with-http_secure_link_module \
  49. --with-http_slice_module \
  50. --with-http_ssl_module \
  51. --with-http_stub_status_module \
  52. --with-http_sub_module \
  53. --with-http_v2_module \
  54. --with-http_v3_module \
  55. --with-http_xslt_module=dynamic \
  56. --with-ipv6 \
  57. --with-mail \
  58. --with-mail_ssl_module \
  59. --with-md5-asm \
  60. --with-sha1-asm \
  61. --with-stream \
  62. --with-stream_ssl_module \
  63. --with-stream_ssl_preread_module \
  64. --with-threads \
  65. "
  66. ARG RESTY_CONFIG_OPTIONS_MORE=""
  67. ARG RESTY_LUAJIT_OPTIONS="--with-luajit-xcflags='-DLUAJIT_NUMMODE=2 -DLUAJIT_ENABLE_LUA52COMPAT'"
  68. ARG RESTY_PCRE_OPTIONS="--with-pcre-jit"
  69. ARG RESTY_ADD_PACKAGE_BUILDDEPS=""
  70. ARG RESTY_ADD_PACKAGE_RUNDEPS=""
  71. ARG RESTY_EVAL_PRE_CONFIGURE=""
  72. ARG RESTY_EVAL_POST_DOWNLOAD_PRE_CONFIGURE=""
  73. ARG RESTY_EVAL_POST_MAKE=""
  74. # These are not intended to be user-specified
  75. ARG _RESTY_CONFIG_DEPS="--with-pcre \
  76. --with-cc-opt='-DNGX_LUA_ABORT_AT_PANIC -I/usr/local/openresty/pcre2/include -I/usr/local/openresty/openssl3/include' \
  77. --with-ld-opt='-L/usr/local/openresty/pcre2/lib -L/usr/local/openresty/openssl3/lib -Wl,-rpath,/usr/local/openresty/pcre2/lib:/usr/local/openresty/openssl3/lib' \
  78. "
  79. LABEL resty_image_base="${RESTY_IMAGE_BASE}"
  80. LABEL resty_image_tag="${RESTY_IMAGE_TAG}"
  81. LABEL resty_version="${RESTY_VERSION}"
  82. LABEL resty_openssl_version="${RESTY_OPENSSL_VERSION}"
  83. LABEL resty_openssl_patch_version="${RESTY_OPENSSL_PATCH_VERSION}"
  84. LABEL resty_openssl_url_base="${RESTY_OPENSSL_URL_BASE}"
  85. LABEL resty_openssl_build_options="${RESTY_OPENSSL_BUILD_OPTIONS}"
  86. LABEL resty_pcre_version="${RESTY_PCRE_VERSION}"
  87. LABEL resty_pcre_build_options="${RESTY_PCRE_BUILD_OPTIONS}"
  88. LABEL resty_pcre_sha256="${RESTY_PCRE_SHA256}"
  89. LABEL resty_config_options="${RESTY_CONFIG_OPTIONS}"
  90. LABEL resty_config_options_more="${RESTY_CONFIG_OPTIONS_MORE}"
  91. LABEL resty_config_deps="${_RESTY_CONFIG_DEPS}"
  92. LABEL resty_add_package_builddeps="${RESTY_ADD_PACKAGE_BUILDDEPS}"
  93. LABEL resty_add_package_rundeps="${RESTY_ADD_PACKAGE_RUNDEPS}"
  94. LABEL resty_eval_pre_configure="${RESTY_EVAL_PRE_CONFIGURE}"
  95. LABEL resty_eval_post_download_pre_configure="${RESTY_EVAL_POST_DOWNLOAD_PRE_CONFIGURE}"
  96. LABEL resty_eval_post_make="${RESTY_EVAL_POST_MAKE}"
  97. LABEL resty_luajit_options="${RESTY_LUAJIT_OPTIONS}"
  98. LABEL resty_pcre_options="${RESTY_PCRE_OPTIONS}"
  99. RUN apk add --no-cache --virtual .build-deps \
  100. build-base \
  101. coreutils \
  102. curl \
  103. gd-dev \
  104. geoip-dev \
  105. libxslt-dev \
  106. linux-headers \
  107. make \
  108. perl-dev \
  109. readline-dev \
  110. zlib-dev \
  111. ${RESTY_ADD_PACKAGE_BUILDDEPS} \
  112. && apk add --no-cache \
  113. gd \
  114. geoip \
  115. libgcc \
  116. libxslt \
  117. tzdata \
  118. zlib \
  119. ${RESTY_ADD_PACKAGE_RUNDEPS} \
  120. && cd /tmp \
  121. && if [ -n "${RESTY_EVAL_PRE_CONFIGURE}" ]; then eval $(echo ${RESTY_EVAL_PRE_CONFIGURE}); fi \
  122. && cd /tmp \
  123. && curl -fSL "${RESTY_OPENSSL_URL_BASE}/openssl-${RESTY_OPENSSL_VERSION}.tar.gz" -o openssl-${RESTY_OPENSSL_VERSION}.tar.gz \
  124. && tar xzf openssl-${RESTY_OPENSSL_VERSION}.tar.gz \
  125. && cd openssl-${RESTY_OPENSSL_VERSION} \
  126. && if [ $(echo ${RESTY_OPENSSL_VERSION} | cut -c 1-4) = "3.0." ] ; then \
  127. echo 'patching OpenSSL 3.0.15 for OpenResty' \
  128. && curl -s https://raw.githubusercontent.com/openresty/openresty/master/patches/openssl-${RESTY_OPENSSL_PATCH_VERSION}-sess_set_get_cb_yield.patch | patch -p1 ; \
  129. fi \
  130. && if [ $(echo ${RESTY_OPENSSL_VERSION} | cut -c 1-5) = "1.1.1" ] ; then \
  131. echo 'patching OpenSSL 1.1.1 for OpenResty' \
  132. && curl -s https://raw.githubusercontent.com/openresty/openresty/master/patches/openssl-${RESTY_OPENSSL_PATCH_VERSION}-sess_set_get_cb_yield.patch | patch -p1 ; \
  133. fi \
  134. && if [ $(echo ${RESTY_OPENSSL_VERSION} | cut -c 1-5) = "1.1.0" ] ; then \
  135. echo 'patching OpenSSL 1.1.0 for OpenResty' \
  136. && curl -s https://raw.githubusercontent.com/openresty/openresty/ed328977028c3ec3033bc25873ee360056e247cd/patches/openssl-1.1.0j-parallel_build_fix.patch | patch -p1 \
  137. && curl -s https://raw.githubusercontent.com/openresty/openresty/master/patches/openssl-${RESTY_OPENSSL_PATCH_VERSION}-sess_set_get_cb_yield.patch | patch -p1 ; \
  138. fi \
  139. && ./config \
  140. shared zlib -g \
  141. --prefix=/usr/local/openresty/openssl3 \
  142. --libdir=lib \
  143. -Wl,-rpath,/usr/local/openresty/openssl3/lib \
  144. ${RESTY_OPENSSL_BUILD_OPTIONS} \
  145. && make -j${RESTY_J} \
  146. && make -j${RESTY_J} install_sw \
  147. && cd /tmp \
  148. && curl -fSL "https://github.com/PCRE2Project/pcre2/releases/download/pcre2-${RESTY_PCRE_VERSION}/pcre2-${RESTY_PCRE_VERSION}.tar.gz" -o pcre2-${RESTY_PCRE_VERSION}.tar.gz \
  149. && echo "${RESTY_PCRE_SHA256} pcre2-${RESTY_PCRE_VERSION}.tar.gz" | shasum -a 256 --check \
  150. && tar xzf pcre2-${RESTY_PCRE_VERSION}.tar.gz \
  151. && cd /tmp/pcre2-${RESTY_PCRE_VERSION} \
  152. && CFLAGS="-g -O3" ./configure \
  153. --prefix=/usr/local/openresty/pcre2 \
  154. --libdir=/usr/local/openresty/pcre2/lib \
  155. ${RESTY_PCRE_BUILD_OPTIONS} \
  156. && CFLAGS="-g -O3" make -j${RESTY_J} \
  157. && CFLAGS="-g -O3" make -j${RESTY_J} install \
  158. && cd /tmp \
  159. && curl -fSL https://openresty.org/download/openresty-${RESTY_VERSION}.tar.gz -o openresty-${RESTY_VERSION}.tar.gz \
  160. && tar xzf openresty-${RESTY_VERSION}.tar.gz \
  161. && cd /tmp/openresty-${RESTY_VERSION} \
  162. && if [ -n "${RESTY_EVAL_POST_DOWNLOAD_PRE_CONFIGURE}" ]; then eval $(echo ${RESTY_EVAL_POST_DOWNLOAD_PRE_CONFIGURE}); fi \
  163. && eval ./configure -j${RESTY_J} ${_RESTY_CONFIG_DEPS} ${RESTY_CONFIG_OPTIONS} ${RESTY_CONFIG_OPTIONS_MORE} ${RESTY_LUAJIT_OPTIONS} ${RESTY_PCRE_OPTIONS} \
  164. && make -j${RESTY_J} \
  165. && make -j${RESTY_J} install \
  166. && cd /tmp \
  167. && if [ -n "${RESTY_EVAL_POST_MAKE}" ]; then eval $(echo ${RESTY_EVAL_POST_MAKE}); fi \
  168. && rm -rf \
  169. openssl-${RESTY_OPENSSL_VERSION}.tar.gz openssl-${RESTY_OPENSSL_VERSION} \
  170. pcre2-${RESTY_PCRE_VERSION}.tar.gz pcre2-${RESTY_PCRE_VERSION} \
  171. openresty-${RESTY_VERSION}.tar.gz openresty-${RESTY_VERSION} \
  172. && apk del .build-deps \
  173. && mkdir -p /var/run/openresty \
  174. && ln -sf /dev/stdout /usr/local/openresty/nginx/logs/access.log \
  175. && ln -sf /dev/stderr /usr/local/openresty/nginx/logs/error.log
  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. # Copy nginx configuration files
  185. COPY nginx.conf /usr/local/openresty/nginx/conf/nginx.conf
  186. ADD ./startup.sh /opt/startup.sh
  187. RUN sed -i 's/\r//g' /opt/startup.sh
  188. CMD ["/bin/sh", "/opt/startup.sh"]
  189. EXPOSE 80 81 443