Improve docker build

- add .dockerignore
- add entrypoint.sh to ensure proper permissions in Docker volumes
- add TZ variable for consistent Celery timestamps
This commit is contained in:
Jan Dittberner 2023-02-20 15:39:14 +01:00
parent 38dae51a7a
commit f89de16f6e
7 changed files with 43 additions and 18 deletions

18
.dockerignore Normal file
View file

@ -0,0 +1,18 @@
**/*.pyc
**/.*.swp
**/.coverage
**/__pycache__
.dockerignore
.env
.envrc
.git
.gitignore
.idea
.isort.cfg
.vagrant
Dockerfile
Vagrantfile
docker-compose.yml
docs
media
static

View file

@ -51,22 +51,20 @@ ARG GVAAPP=gva
ARG GVAGID=2000
ARG GVAUID=2000
VOLUME /srv/$GVAAPP/media /srv/$GVAAPP/static
WORKDIR /srv/$GVAAPP
RUN addgroup --gid $GVAGID $GVAAPP ; \
adduser --home /home/$GVAAPP --shell /bin/bash --uid $GVAUID --gid $GVAGID --disabled-password \
--gecos "User for gnuviechadmin component $GVAAPP" $GVAAPP
COPY --chown=$GVAAPP:$GVAAPP --from=builder /srv/$GVAAPP/.venv /srv/$GVAAPP/.venv
USER $GVAAPP
WORKDIR /srv/$GVAAPP
VOLUME /srv/$GVAAPP
VOLUME /srv/$GVAAPP/media /srv/$GVAAPP/static
VOLUME /srv/$GVAAPP/gnuviechadmin
EXPOSE 8000
COPY ${GVAAPP}.sh /srv/
COPY ${GVAAPP}.sh entrypoint.sh /srv/
ENTRYPOINT ["dumb-init", "/srv/${GVAAPP}.sh"]
ENTRYPOINT ["dumb-init", "/srv/entrypoint.sh"]

View file

@ -1,3 +1,4 @@
---
version: "3"
services:
db:
@ -36,9 +37,9 @@ services:
GVA_DOMAIN_NAME: localhost
GVA_SITE_NAME: localhost
volumes:
- "./docker/django_media:/srv/gva/media"
- "./docker/django_static:/srv/gva/static"
- ".:/srv/gva"
- "django_media:/srv/gva/media"
- "django_static:/srv/gva/static"
- "./gnuviechadmin:/srv/gva/gnuviechadmin"
web:
image: gnuviech/gvaweb:buster
build:
@ -51,7 +52,7 @@ services:
- redis
env_file: ../gvaweb/.env
volumes:
- "../gvaweb:/srv/gvaweb"
- "../gvaweb/gvaweb:/srv/gvaweb/gvaweb"
ldap:
image: gnuviech/gvaldap:buster
build:
@ -64,7 +65,7 @@ services:
- redis
env_file: ../gvaldap/.env
volumes:
- "../gvaldap:/srv/gvaldap"
- "../gvaldap/gvaldap:/srv/gvaldap/gvaldap"
file:
image: gnuviech/gvafile:buster
build:
@ -77,7 +78,7 @@ services:
- redis
env_file: ../gvafile/.env
volumes:
- "../gvafile:/srv/gvafile"
- "../gvafile/gvafile:/srv/gvafile/gvafile"
pgsql:
image: gnuviech/gvapgsql:buster
build:
@ -90,7 +91,7 @@ services:
- redis
env_file: ../gvapgsql/.env
volumes:
- "../gvapgsql:/srv/gvapgsql"
- "../gvapgsql/gvapgsql:/srv/gvapgsql/gvapgsql"
mysql:
image: gnuviech/gvamysql:buster
build:
@ -103,7 +104,7 @@ services:
- redis
env_file: ../gvamysql/.env
volumes:
- "../gvamysql:/srv/gvamysql"
- "../gvamysql/gvamysql:/srv/gvamysql/gvamysql"
volumes:
django_media:
django_static:

7
entrypoint.sh Executable file
View file

@ -0,0 +1,7 @@
#!/bin/sh
set -e
chown -Rc gva.gva /srv/gva/media /srv/gva/static
su -c /srv/gva.sh gva

5
gva.sh
View file

@ -14,11 +14,12 @@ do
sleep 1
done
echo " db is ready"
echo ". db is ready"
export TZ="Europe/Berlin"
. /srv/gva/.venv/bin/activate
cd /srv/gva/gnuviechadmin
python3 manage.py compilemessages
python3 manage.py collectstatic --noinput
python3 manage.py migrate --noinput
python3 manage.py runserver 0.0.0.0:8000