Run as alpine docker image and server static files with gunicorn
This commit is contained in:
parent
97e2593f72
commit
cc931189e8
@ -7,4 +7,12 @@ docker-compose*
|
||||
.gitignore
|
||||
README.md
|
||||
LICENSE
|
||||
.vscode
|
||||
.vscode
|
||||
.env
|
||||
.env.template
|
||||
.github
|
||||
.idea
|
||||
LICENSE.md
|
||||
docs
|
||||
nginx
|
||||
update.sh
|
41
Dockerfile
41
Dockerfile
@ -1,24 +1,23 @@
|
||||
FROM python:3.8-slim-buster
|
||||
|
||||
RUN mkdir /Recipes
|
||||
WORKDIR /Recipes
|
||||
|
||||
ADD . /Recipes/
|
||||
|
||||
RUN apt-get update
|
||||
RUN apt-get -y upgrade
|
||||
RUN apt-get install -y \
|
||||
python3 \
|
||||
python3-pip \
|
||||
postgresql-client \
|
||||
gettext
|
||||
|
||||
RUN pip3 install --upgrade pip
|
||||
|
||||
RUN pip3 install -r requirements.txt
|
||||
|
||||
RUN apt-get autoremove -y
|
||||
FROM python:3.8-alpine
|
||||
|
||||
RUN apk add --no-cache postgresql-libs gettext zlib libjpeg libxml2-dev libxslt-dev
|
||||
ENV PYTHONUNBUFFERED 1
|
||||
EXPOSE 8080
|
||||
|
||||
EXPOSE 8080
|
||||
# Don't run container as root
|
||||
RUN adduser -D recipes
|
||||
|
||||
RUN mkdir /opt/recipes
|
||||
RUN chown recipes:recipes /opt/recipes
|
||||
WORKDIR /opt/recipes
|
||||
COPY --chown=recipes:recipes . ./
|
||||
RUN pwd && ls -lha
|
||||
RUN chmod +x boot.sh
|
||||
|
||||
RUN apk add --no-cache --virtual .build-deps gcc musl-dev postgresql-dev zlib-dev jpeg-dev && \
|
||||
python -m venv venv && \
|
||||
venv/bin/pip install -r requirements.txt --no-cache-dir &&\
|
||||
apk --purge del .build-deps
|
||||
|
||||
USER recipes
|
||||
ENTRYPOINT ["/opt/recipes/boot.sh"]
|
9
boot.sh
Normal file
9
boot.sh
Normal file
@ -0,0 +1,9 @@
|
||||
#!/bin/sh
|
||||
source venv/bin/activate
|
||||
|
||||
echo "Updating database"
|
||||
python3 manage.py migrate
|
||||
python3 manage.py collectstatic --noinput
|
||||
echo "Done"
|
||||
|
||||
exec gunicorn -b :8080 --access-logfile - --error-logfile - recipes.wsgi
|
@ -15,9 +15,6 @@ services:
|
||||
restart: always
|
||||
env_file:
|
||||
- ./.env
|
||||
command: "gunicorn --bind 0.0.0.0:8080 recipes.wsgi"
|
||||
volumes:
|
||||
- .:/Recipes
|
||||
depends_on:
|
||||
- db_recipes
|
||||
networks:
|
||||
|
@ -57,6 +57,9 @@ INSTALLED_APPS = [
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
# Simplified static file serving.
|
||||
# https://warehouse.python.org/project/whitenoise/
|
||||
'whitenoise.middleware.WhiteNoiseMiddleware',
|
||||
'django.middleware.security.SecurityMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
@ -145,3 +148,6 @@ STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")
|
||||
|
||||
MEDIA_URL = '/media/'
|
||||
MEDIA_ROOT = os.path.join(BASE_DIR, "mediafiles")
|
||||
|
||||
# Serve static files with gzip
|
||||
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
|
@ -17,4 +17,5 @@ lxml
|
||||
webdavclient3
|
||||
python-dotenv
|
||||
psycopg2-binary
|
||||
whitenoise
|
||||
gunicorn
|
||||
|
Loading…
Reference in New Issue
Block a user