remove nginx and serve static files with uwsgi

This commit is contained in:
FuzzyGrim
2023-03-05 22:12:49 +01:00
parent b37f60d44d
commit 6460f02717
6 changed files with 18 additions and 85 deletions

View File

@@ -5,15 +5,12 @@ ENV PYTHONDONTWRITEBYTECODE 1
WORKDIR /app
COPY ./requirements.txt /requirements.txt
COPY install-nginx-debian.sh /install-nginx-debian.sh
RUN apt-get update && apt-get install -y --no-install-recommends g++ gcc gosu && \
bash /install-nginx-debian.sh && \
pip install --no-cache-dir --upgrade -r /requirements.txt && \
rm -rf /var/lib/apt/lists/* && \
apt-get remove -y --purge g++ gcc && apt-get autoremove -y && \
gosu nobody true && \
ln -sf /dev/stdout /var/log/nginx/access.log && ln -sf /dev/stderr /var/log/nginx/error.log
gosu nobody true
COPY ./default.conf /etc/nginx/conf.d/default.conf
@@ -25,6 +22,4 @@ RUN chmod +x /entrypoint.sh && \
COPY src ./
STOPSIGNAL SIGQUIT
CMD ["/entrypoint.sh"]

View File

@@ -50,12 +50,12 @@ services:
# - REGISTRATION=False
volumes:
- ./db:/app/db
- assets:/app/assets
- media:/app/assets/media
ports:
- "8080:80"
- "8000:8000"
volumes:
assets:
media:
```
## Environment variables

View File

@@ -16,9 +16,9 @@ services:
# - REGISTRATION=False
volumes:
- ./db:/app/db
- assets:/app/assets
- media:/app/assets/media
ports:
- "8080:80"
- "8000:8000"
volumes:
assets:
media:

View File

@@ -14,5 +14,4 @@ usermod -o -u "$PUID" abc
chown -R abc:abc db
chown -R abc:abc assets
nginx
exec gosu abc:abc uwsgi --socket :8000 --master --enable-threads --module base.wsgi
exec gosu abc:abc uwsgi --ini /app/base/uwsgi.ini

View File

@@ -1,71 +0,0 @@
#! /usr/bin/env bash
# From official Nginx Docker image, as a script to re-use it, removing internal comments
# Ref: https://github.com/nginxinc/docker-nginx/blob/fef51235521d1cdf8b05d8cb1378a526d2abf421/mainline/debian/Dockerfile
# Standard set up Nginx
export NGINX_VERSION=1.23.3
export PKG_RELEASE=1~bullseye
set -x \
&& apt-get update \
&& apt-get install --no-install-recommends --no-install-suggests -y gnupg1 ca-certificates \
&& \
NGINX_GPGKEY=573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62; \
found=''; \
for server in \
hkp://keyserver.ubuntu.com:80 \
pgp.mit.edu \
; do \
echo "Fetching GPG key $NGINX_GPGKEY from $server"; \
apt-key adv --keyserver "$server" --keyserver-options timeout=10 --recv-keys "$NGINX_GPGKEY" && found=yes && break; \
done; \
test -z "$found" && echo >&2 "error: failed to fetch GPG key $NGINX_GPGKEY" && exit 1; \
apt-get remove --purge --auto-remove -y gnupg1 && rm -rf /var/lib/apt/lists/* \
&& dpkgArch="$(dpkg --print-architecture)" \
&& nginxPackages=" \
nginx=${NGINX_VERSION}-${PKG_RELEASE} \
" \
&& case "$dpkgArch" in \
amd64|arm64) \
echo "deb https://nginx.org/packages/mainline/debian/ bullseye nginx" >> /etc/apt/sources.list.d/nginx.list \
&& apt-get update \
;; \
*) \
echo "deb-src https://nginx.org/packages/mainline/debian/ bullseye nginx" >> /etc/apt/sources.list.d/nginx.list \
\
&& tempDir="$(mktemp -d)" \
&& chmod 777 "$tempDir" \
\
&& savedAptMark="$(apt-mark showmanual)" \
\
&& apt-get update \
&& apt-get build-dep -y $nginxPackages \
&& ( \
cd "$tempDir" \
&& DEB_BUILD_OPTIONS="nocheck parallel=$(nproc)" \
apt-get source --compile $nginxPackages \
) \
\
&& apt-mark showmanual | xargs apt-mark auto > /dev/null \
&& { [ -z "$savedAptMark" ] || apt-mark manual $savedAptMark; } \
\
&& ls -lAFh "$tempDir" \
&& ( cd "$tempDir" && dpkg-scanpackages . > Packages ) \
&& grep '^Package: ' "$tempDir/Packages" \
&& echo "deb [ trusted=yes ] file://$tempDir ./" > /etc/apt/sources.list.d/temp.list \
&& apt-get -o Acquire::GzipIndexes=false update \
;; \
esac \
\
&& apt-get install --no-install-recommends --no-install-suggests -y \
$nginxPackages \
gettext-base \
curl \
&& apt-get remove --purge --auto-remove -y && rm -rf /var/lib/apt/lists/* /etc/apt/sources.list.d/nginx.list \
\
&& if [ -n "$tempDir" ]; then \
apt-get purge -y --auto-remove \
&& rm -rf "$tempDir" /etc/apt/sources.list.d/temp.list; \
fi
# Standard set up Nginx finished

10
src/base/uwsgi.ini Normal file
View File

@@ -0,0 +1,10 @@
[uwsgi]
http = :8000
master = true
enable-threads = true
module = base.wsgi
static-map = /static=/app/assets/static
static-map = /media=/app/assets/media
static-expires = 7776000
offload-threads = %k
die-on-term = true