#######################
#1. pull ubuntu image
#######################
FROM ubuntu:20.04 AS temp
LABEL maintainer="Tengine docker admin  <zhangpeng@linuxjk.cn>"  author="linuxjk.cn"
ENV  Web_User="nginx"
ENV  Web_Server="tengine"
ENV  Web_Version="3.0.0"
ENV  Server_Dir="/app/tools/tengine-3.0.0"
ENV  Server_Dir_Soft="/app/tools/tengine"
#######################
#####ENV vars###########
#######################
#######################
#2. 编译安装     ######
#######################
RUN  set -eux \
   && sed -ri 's#archive.ubuntu.com|security.ubuntu.com#mirrors.aliyun.com#g'   /etc/apt/sources.list \
   && apt-get update \
   && apt-get install  -y wget libssl-dev make gcc pcre2-utils   libpcre3-dev zlib1g-dev
RUN  set -eux \
   && wget -P /tmp/ http://tengine.taobao.org/download/${Web_Server}-${Web_Version}.tar.gz \
   && cd /tmp \
   && tar xf ${Web_Server}-${Web_Version}.tar.gz \
   && cd ${Web_Server}-${Web_Version} \
   && ./configure --prefix=${Server_Dir} \
         --user=${Web_User} \
         --group=${Web_User} \
         --with-http_ssl_module \
         --with-http_v2_module   \
         --with-http_realip_module \
         --with-http_stub_status_module \
         --with-http_mp4_module \
         --with-stream \
         --with-stream_ssl_module   \
         --with-stream_realip_module   \
         --add-module=modules/ngx_http_upstream_check_module/ \
         --add-module=modules/ngx_http_upstream_session_sticky_module
#编译
RUN  set -eux \
   &&    cd /tmp/ \
   && cd ${Web_Server}-${Web_Version} \
   &&  make -j `nproc` \
   &&  make install
#后续操作
RUN  set -eux \
   &&  groupadd  ${Web_User} \
   && useradd   -g ${Web_User}  ${Web_User} \
   &&  ln -s ${Server_Dir}   ${Server_Dir_Soft} \
   &&  ln -s ${Server_Dir_Soft}/sbin/nginx /sbin/

###################################
######创建新的镜像#################
######把上面结果传递到新的镜像#####
###################################
FROM ubuntu:20.04
COPY --from=temp /app/ /app/
ADD bunengsi.tar.gz   /app/tools/tengine/html/
RUN   set -eux \
     && sed -ri 's#archive.ubuntu.com|security.ubuntu.com#mirrors.aliyun.com#g'   /etc/apt/sources.list \
     && apt-get update \
     && apt-get install  -y libssl-dev pcre2-utils   libpcre3-dev zlib1g-dev \
     &&  ln -s /app/tools/tengine/sbin/nginx /sbin/ \
     && groupadd nginx \
     && useradd  -g nginx nginx \
     &&  rm -fr /var/cache/* \
     && apt clean \
     &&  ln -sf /dev/stdout /app/tools/tengine/logs/access.log \
     &&  ln -sf /dev/stderr /app/tools/tengine/logs/error.log
EXPOSE 80 443
CMD ["nginx","-g","daemon off;"]
