FROM debian:stable-slim AS builder
WORKDIR /app
ADD ./openresty-1.27.1.2.tar.gz /app
RUN /bin/rm -f /etc/apt/sources.list.d/* && \
echo "deb http://mirrors.nju.edu.cn/debian/ bookworm main contrib non-free non-free-firmware" >/etc/apt/sources.list && \
echo "deb http://mirrors.nju.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware" >>/etc/apt/sources.list && \
echo "deb http://mirrors.nju.edu.cn/debian-security bookworm-security/updates main contrib non-free non-free-firmware" >> /etc/apt/sources.list && \
apt-get update && \
apt-get -y install gcc make libpcre3-dev libssl-dev zlib1g-dev perl && \
cd openresty-1.27.1.2 && \
sed -i '/^#define NGX_MAX_ERROR_STR/s/4096/10240000/g' ./bundle/nginx-1.27.1/src/core/ngx_log.h && \
./configure --prefix=/usr/local/openresty && \
gmake && \
gmake install && \
strip /usr/local/openresty/nginx/sbin/nginx

FROM debian:stable-slim
RUN /bin/rm -f /etc/apt/sources.list.d/* && \
echo "deb http://mirrors.nju.edu.cn/debian/ bookworm main contrib non-free non-free-firmware" >/etc/apt/sources.list && \
echo "deb http://mirrors.nju.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware" >>/etc/apt/sources.list && \
echo "deb http://mirrors.nju.edu.cn/debian-security bookworm-security/updates main contrib non-free non-free-firmware" >> /etc/apt/sources.list && \
apt-get update && \
apt-get -y install libpcre3-dev libssl-dev zlib1g-dev && \
apt clean && \
/bin/rm -rf /var/lib/apt/lists/*
COPY  --from=builder /usr/local/openresty/ /usr/local/openresty/
ENV PATH "/usr/local/openresty/bin:/usr/local/openresty/nginx/sbin:$PATH"
ENTRYPOINT ["nginx", "-g", "daemon off;"]
