mirror of
https://github.com/eduardogsilva/routerfleet.git
synced 2025-08-02 01:04:26 +02:00
Additional variables to docker compose
This commit is contained in:
parent
a8c62c241e
commit
03f027f100
2 changed files with 60 additions and 18 deletions
|
@ -6,8 +6,8 @@ services:
|
||||||
volumes:
|
volumes:
|
||||||
- postgres_data:/var/lib/postgresql/data
|
- postgres_data:/var/lib/postgresql/data
|
||||||
environment:
|
environment:
|
||||||
- POSTGRES_DB=routerfleet
|
- POSTGRES_DB=${POSTGRES_DB}
|
||||||
- POSTGRES_USER=routerfleet
|
- POSTGRES_USER=${POSTGRES_USER}
|
||||||
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
|
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
|
||||||
|
|
||||||
routerfleet:
|
routerfleet:
|
||||||
|
@ -18,10 +18,17 @@ services:
|
||||||
environment:
|
environment:
|
||||||
- SERVER_ADDRESS=${SERVER_ADDRESS}
|
- SERVER_ADDRESS=${SERVER_ADDRESS}
|
||||||
- DEBUG_MODE=${DEBUG_MODE}
|
- DEBUG_MODE=${DEBUG_MODE}
|
||||||
|
- DATABASE_ENGINE=${DATABASE_ENGINE}
|
||||||
|
- POSTGRES_HOST=${POSTGRES_HOST}
|
||||||
|
- POSTGRES_PORT=${POSTGRES_PORT}
|
||||||
|
- POSTGRES_DB=${POSTGRES_DB}
|
||||||
|
- POSTGRES_USER=${POSTGRES_USER}
|
||||||
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
|
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
|
||||||
- TIMEZONE=${TIMEZONE}
|
- TIMEZONE=${TIMEZONE}
|
||||||
|
- COMPOSE_TYPE=with-postgres
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
|
- sqlite_volume:/var/lib/routerfleet_sqlite/
|
||||||
- media_root:/var/lib/routerfleet/
|
- media_root:/var/lib/routerfleet/
|
||||||
- static_volume:/app_static_files/
|
- static_volume:/app_static_files/
|
||||||
command: /bin/bash /app/init.sh
|
command: /bin/bash /app/init.sh
|
||||||
|
@ -54,7 +61,6 @@ services:
|
||||||
context: ./containers/nginx
|
context: ./containers/nginx
|
||||||
dockerfile: Dockerfile-nginx
|
dockerfile: Dockerfile-nginx
|
||||||
volumes:
|
volumes:
|
||||||
- ./containers/nginx/virtualhost.conf:/etc/nginx/conf.d/routerfleet.conf
|
|
||||||
- static_volume:/static
|
- static_volume:/static
|
||||||
- https_cert:/certificate
|
- https_cert:/certificate
|
||||||
ports:
|
ports:
|
||||||
|
@ -68,3 +74,4 @@ volumes:
|
||||||
https_cert:
|
https_cert:
|
||||||
media_root:
|
media_root:
|
||||||
postgres_data:
|
postgres_data:
|
||||||
|
sqlite_volume:
|
||||||
|
|
65
entrypoint.sh
Normal file → Executable file
65
entrypoint.sh
Normal file → Executable file
|
@ -1,4 +1,5 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
PRODUCTION_SETTINGS_FILE="/app/routerfleet/production_settings.py"
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
@ -7,8 +8,51 @@ if [ -z "$SERVER_ADDRESS" ]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$POSTGRES_PASSWORD" ]; then
|
if [[ "${DATABASE_ENGINE,,}" == "sqlite" ]]; then
|
||||||
echo "POSTGRES_PASSWORD environment variable is not set. Exiting."
|
if [[ "$COMPOSE_TYPE" != "no-postgres" ]]; then
|
||||||
|
echo "ERROR: Please use 'docker-compose-no-postgres.yml' when using sqlite as DATABASE_ENGINE. Exiting."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
DATABASES_CONFIG="DATABASES = {
|
||||||
|
'default': {
|
||||||
|
'ENGINE': 'django.db.backends.sqlite3',
|
||||||
|
'NAME': '/var/lib/routerfleet_sqlite/routerfleet-db.sqlite3',
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
elif [[ "${DATABASE_ENGINE,,}" == "postgres" ]]; then
|
||||||
|
if [ -n "$POSTGRES_HOST" ]; then
|
||||||
|
if [[ "$COMPOSE_TYPE" != "no-postgres" ]]; then
|
||||||
|
echo "ERROR: When using a remote PostgreSQL server, please use 'docker-compose-no-postgres.yml'. Exiting."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if [ -z "$POSTGRES_PORT" ]; then
|
||||||
|
POSTGRES_PORT="5432"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
if [[ "$COMPOSE_TYPE" != "with-postgres" ]]; then
|
||||||
|
echo "ERROR: Local postgres is selected. Please use 'docker-compose.yml'. Exiting."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
POSTGRES_HOST="routerfleet-postgres"
|
||||||
|
POSTGRES_PORT="5432"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$POSTGRES_DB" ] || [ -z "$POSTGRES_USER" ] || [ -z "$POSTGRES_PASSWORD" ]; then
|
||||||
|
echo "POSTGRES_DB, POSTGRES_USER, or POSTGRES_PASSWORD environment variable is not set. Exiting."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
DATABASES_CONFIG="DATABASES = {
|
||||||
|
'default': {
|
||||||
|
'ENGINE': 'django.db.backends.postgresql',
|
||||||
|
'NAME': '$POSTGRES_DB',
|
||||||
|
'USER': '$POSTGRES_USER',
|
||||||
|
'PASSWORD': '$POSTGRES_PASSWORD',
|
||||||
|
'HOST': '$POSTGRES_HOST',
|
||||||
|
'PORT': '$POSTGRES_PORT',
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
else
|
||||||
|
echo "Unsupported DATABASE_ENGINE. Exiting."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -17,27 +61,18 @@ if [[ "${DEBUG_MODE,,}" == "true" ]]; then
|
||||||
DEBUG_VALUE="True"
|
DEBUG_VALUE="True"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cat > /app/routerfleet/production_settings.py <<EOL
|
cat > $PRODUCTION_SETTINGS_FILE <<EOL
|
||||||
DEBUG = $DEBUG_VALUE
|
DEBUG = $DEBUG_VALUE
|
||||||
ALLOWED_HOSTS = ['routerfleet', '$SERVER_ADDRESS']
|
ALLOWED_HOSTS = ['routerfleet', '$SERVER_ADDRESS']
|
||||||
CSRF_TRUSTED_ORIGINS = ['http://routerfleet', 'https://$SERVER_ADDRESS']
|
CSRF_TRUSTED_ORIGINS = ['http://routerfleet', 'https://$SERVER_ADDRESS']
|
||||||
SECRET_KEY = '$(openssl rand -base64 32)'
|
SECRET_KEY = '$(openssl rand -base64 32)'
|
||||||
DATABASES = {
|
$DATABASES_CONFIG
|
||||||
'default': {
|
|
||||||
'ENGINE': 'django.db.backends.postgresql',
|
|
||||||
'NAME': 'routerfleet',
|
|
||||||
'USER': 'routerfleet',
|
|
||||||
'PASSWORD': '$POSTGRES_PASSWORD',
|
|
||||||
'HOST': 'routerfleet-postgres',
|
|
||||||
'PORT': '5432',
|
|
||||||
}
|
|
||||||
}
|
|
||||||
EOL
|
EOL
|
||||||
|
|
||||||
if [ -n "$TIMEZONE" ]; then
|
if [ -n "$TIMEZONE" ]; then
|
||||||
echo "TIME_ZONE = '$TIMEZONE'" >> /app/routerfleet/production_settings.py
|
echo "TIME_ZONE = '$TIMEZONE'" >> $PRODUCTION_SETTINGS_FILE
|
||||||
fi
|
fi
|
||||||
|
|
||||||
sed -i "/^ path('admin\/', admin.site.urls),/s/^ / # /" /app/routerfleet/urls.py
|
sed -i "/^ path('admin\/', admin.site.urls),/s/^ / # /" /app/routerfleet/urls.py
|
||||||
|
|
||||||
exec "$@"
|
exec "$@"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue