FROM nginx:1.19.5-alpine

RUN apk update \
    && apk add --no-progress \
            bash certbot openssl  \
    && rm /var/cache/apk/* \
    && echo "preparing certbot webroot" \
    && mkdir -p /var/lib/certbot \
    && echo "generating initial self-signed certificate" \
    && mkdir -p /etc/nginx/ssl/crm.localhost/ \
    && openssl req -x509 -nodes -newkey rsa:4096 \
           -keyout /etc/nginx/ssl/crm.localhost/privkey.pem \
           -out /etc/nginx/ssl/crm.localhost/fullchain.pem \
           -subj "/C=/ST=/L=/O=/CN=crm.localhost" \
    && ln -sf /etc/nginx/ssl/crm.localhost /etc/nginx/ssl/latest
	
	


COPY certbot.sh /etc/nginx/ssl/