feat(docker): Install NginX to serve site

ref: #363 #371
This commit is contained in:
2024-10-30 00:12:20 +09:30
parent cfa284d4ad
commit 7a0f85c556
4 changed files with 60 additions and 2 deletions

View File

@ -7,5 +7,6 @@
"streetsidesoftware.code-spell-checker",
"qwtel.sqlite-viewer",
"jebbs.markdown-extended",
"william-voyek.vscode-nginx",
]
}

View File

@ -3,6 +3,7 @@ ARG CI_COMMIT_SHA=''
ARG CI_COMMIT_TAG=''
ARG ALPINE_VERSION=3.20
ARG NGINX_VERSION=1.27.2-r1
ARG PYTHON_VERSION=3.11.10
FROM python:${PYTHON_VERSION}-alpine${ALPINE_VERSION} as build
@ -30,8 +31,24 @@ RUN apk add --update \
pkgconf \
postgresql16-dev \
postgresql16-client \
libpq-dev
libpq-dev \
# NginX: to download items
openssl \
curl \
ca-certificates
RUN printf "%s%s%s%s\n" \
"@nginx " \
"http://nginx.org/packages/mainline/alpine/v" \
`egrep -o '^[0-9]+\.[0-9]+' /etc/alpine-release` \
"/main" \
| tee -a /etc/apk/repositories
RUN curl -o /tmp/nginx_signing.rsa.pub https://nginx.org/keys/nginx_signing.rsa.pub; \
openssl rsa -pubin -in /tmp/nginx_signing.rsa.pub -text -noout;
RUN pip install --upgrade \
setuptools \
wheel \
@ -77,6 +94,8 @@ ARG CI_PROJECT_URL
ARG CI_COMMIT_SHA
ARG CI_COMMIT_TAG
ARG NGINX_VERSION
ENV CI_PROJECT_URL=${CI_PROJECT_URL}
ENV CI_COMMIT_SHA=${CI_COMMIT_SHA}
ENV CI_COMMIT_TAG=${CI_COMMIT_TAG}
@ -89,6 +108,11 @@ COPY ./app/. app
COPY --from=build /tmp/python_builds /tmp/python_builds
COPY --from=build /etc/apk/repositories /etc/apk/repositories
COPY --from=build /tmp/nginx_signing.rsa.pub /etc/apk/keys/nginx_signing.rsa.pub
COPY includes/ /
RUN pip --disable-pip-version-check list --outdated --format=json | \
@ -98,10 +122,14 @@ RUN pip --disable-pip-version-check list --outdated --format=json | \
apk add --no-cache \
mariadb-client \
mariadb-dev \
postgresql16-client; \
postgresql16-client \
nginx@nginx=${NGINX_VERSION}; \
pip install --no-cache-dir /tmp/python_builds/*.*; \
python /app/manage.py collectstatic --noinput; \
rm -rf /tmp/python_builds; \
ln -s /etc/nginx/sites-available/myproject /etc/nginx/sites-enabled; \
# Check for errors and fail if so
nginx -t; \
export

View File

@ -0,0 +1,21 @@
server {
listen 8000;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /app/static;
}
location / {
include proxy_params;
proxy_pass http://unix:/run/gunicorn.sock;
}
}

View File

@ -0,0 +1,8 @@
[program:nginx]
startsecs=0
stopwaitsecs=55
command=nginx -g daemon off
autorestart=true
autostart=true
stdout_logfile=/var/log/%(program_name)s.log
stderr_logfile=/var/log/%(program_name)s.log