FROM nginx:1.27.0-alpine-perl

RUN apk update
RUN apk add bash curl perl-cgi spawn-fcgi fcgiwrap openrc perl-app-cpanminus

EXPOSE 80

RUN mkdir -p /var/log/nginx /var/log/fcgiwrap

ADD ./nginx.conf /etc/nginx/nginx.conf
ADD ./survey.conf /etc/nginx/conf.d/survey.conf
ADD ./fcgiwrap /etc/init.d/fcgiwrap
ADD ./entrypoint.sh /usr/local/bin/entrypoint.sh

RUN chmod +x /etc/init.d/fcgiwrap
RUN rm /etc/nginx/conf.d/default.conf
RUN chmod +x /usr/local/bin/entrypoint.sh
ENV PERL5LIB=/usr/share/nginx/html/cgi-bin
EXPOSE 80

ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]