diff --git a/Dockerfile b/Dockerfile index 9411887..62a86cf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ FROM alpine:3.18 as build # making my own image for hugo because there doesn't seem to be an official one in repo, lazy so we're going with alpine RUN ["apk", "update"] -RUN ["apk", "add hugo"] +RUN ["apk", "add", "hugo"] ADD . /root/ WORKDIR /root # pass in the uri or ip of the comments api so nginx can forward to it @@ -10,7 +10,8 @@ ENV COMMENTS_BACKEND=${WITH_BACKEND} RUN ["hugo", "--minify"] FROM python:3.11-alpine as fiddling -RUN ["adduser", "-h", "/application", "application"] +RUN ["mkdir", "/application"] +RUN ["adduser", "-D", "-h", "/application", "application"] # might need to chown these ADD ./scripts/template_convert.py /application/template_convert.py ADD ./nginx.conf.template /application/nginx.conf.template @@ -18,6 +19,6 @@ WORKDIR /application USER application RUN ["python", "/application/template_convert.py"] -FROM nginx:1.25 -COPY --from=fiddling /application/nginx.conf -RUN +FROM nginx:1.25-alpine +COPY --from=fiddling /application/nginx.conf /etc/nginx/nginx.conf +COPY --from=build /root/public /usr/share/nginx/html diff --git a/nginx.conf.template b/nginx.conf.template index 7572587..c153a10 100644 --- a/nginx.conf.template +++ b/nginx.conf.template @@ -24,4 +24,6 @@ http { # we're going to use a python program to substitute this out proxy_pass http://${{COMMENTS_BACKEND}} } + ###---} } +} diff --git a/scripts/template_convert.py b/scripts/template_convert.py old mode 100644 new mode 100755 index e69de29..0015084 --- a/scripts/template_convert.py +++ b/scripts/template_convert.py @@ -0,0 +1,20 @@ +#!/bin/env python3 + +import os +import re + +var_name = "COMMENTS_BACKEND" +file_name = "nginx.conf" +back = os.environ.get(var_name) +buf = str() +with open(file_name+".template") as file: + buf = file.read() + +if back == None: + buf = re.sub("###{---(.|\n)*###---}", "", buf) +else: + # ${{\s*$var_name\s*}} + buf = re.sub(rf"\${{{{\s*{var_name}\s*}}}}",var_name,buf) + +with open(file_name, "w+") as file: + file.write(buf)