RUN sed -i "s/dl-cdn.alpinelinux.org/mirrors.cernet.edu.cn/g" /etc/apk/repositories;
FROM base as build
ENV ECHO_NGINX_MODULE_VERSION 0.63
RUN sed -i "s/dl-cdn.alpinelinux.org/mirrors.cernet.edu.cn/g" /etc/apk/repositories;
RUN NGINX_VER=`nginx -v 2>&1 | cut -d '/' -f 2` \ && cd /tmp \ && wget http://nginx.org/download/nginx-${NGINX_VER}.tar.gz -O nginx-${NGINX_VER}.tar.gz \ && wget https://github.com/openresty/echo-nginx-module/archive/refs/tags/v${ECHO_NGINX_MODULE_VERSION}.tar.gz -O echo-nginx-module-${ECHO_NGINX_MODULE_VERSION}.tar.gz \ && apk add --no-cache --virtual dependency gcc libc-dev make openssl-dev pcre-dev zlib-dev linux-headers \ && tar zxf nginx-${NGINX_VER}.tar.gz \ && tar zxf echo-nginx-module-${ECHO_NGINX_MODULE_VERSION}.tar.gz \ && cd nginx-${NGINX_VER} \ && CONFARGS=$(nginx -V 2>&1 | sed -n -e 's/^configure arguments: //p') \ && echo$CONFARGS \ && sh -c "./configure --with-compat ${CONFARGS} --add-dynamic-module=../echo-nginx-module-${ECHO_NGINX_MODULE_VERSION}" \ && make modules \ && apk del dependency \ && rm -rf /var/cache/apk/* \ && mkdir -p /tmp/objs \ && cp /tmp/nginx-${NGINX_VER}/objs/*.so /tmp/objs/ \ && ls /tmp/objs -al
FROM base
COPY --from=build /tmp/objs/ngx_http_echo_module.so /etc/nginx/modules RUN sed -i '1s/^/load_module \/etc\/nginx\/modules\/ngx_http_echo_module.so;\n/' /etc/nginx/nginx.conf