FROM nginx:alpine

RUN apk update && \
  apk -Uuv add python py-pip openssl && \
  pip install awscli && \
  apk --purge -v del py-pip && \
  rm /var/cache/apk/*

RUN openssl req -subj '/CN=localhost' -x509 -newkey rsa:4096 -nodes -keyout /etc/nginx/key.pem -out /etc/nginx/cert.pem -days 365

COPY s3_bucket.txt /etc/s3_bucket.txt
COPY nginx.conf /etc/nginx/nginx.conf
COPY update_nginx_config.cron /etc/cron.d/update_nginx_config.cron
COPY update_nginx_config.sh /usr/local/bin/update_nginx_config.sh

RUN chmod 755 /usr/local/bin/update_nginx_config.sh
RUN /usr/bin/crontab /etc/cron.d/update_nginx_config.cron

EXPOSE 8080 8443

CMD ["sh", "-c", "crond && nginx -g 'daemon off;'"]
