mirror of
https://github.com/eduardogsilva/routerfleet.git
synced 2025-06-21 01:25:41 +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:
|
||||
- postgres_data:/var/lib/postgresql/data
|
||||
environment:
|
||||
- POSTGRES_DB=routerfleet
|
||||
- POSTGRES_USER=routerfleet
|
||||
- POSTGRES_DB=${POSTGRES_DB}
|
||||
- POSTGRES_USER=${POSTGRES_USER}
|
||||
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
|
||||
|
||||
routerfleet:
|
||||
|
@ -18,10 +18,17 @@ services:
|
|||
environment:
|
||||
- SERVER_ADDRESS=${SERVER_ADDRESS}
|
||||
- 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}
|
||||
- TIMEZONE=${TIMEZONE}
|
||||
- COMPOSE_TYPE=with-postgres
|
||||
|
||||
volumes:
|
||||
- sqlite_volume:/var/lib/routerfleet_sqlite/
|
||||
- media_root:/var/lib/routerfleet/
|
||||
- static_volume:/app_static_files/
|
||||
command: /bin/bash /app/init.sh
|
||||
|
@ -54,7 +61,6 @@ services:
|
|||
context: ./containers/nginx
|
||||
dockerfile: Dockerfile-nginx
|
||||
volumes:
|
||||
- ./containers/nginx/virtualhost.conf:/etc/nginx/conf.d/routerfleet.conf
|
||||
- static_volume:/static
|
||||
- https_cert:/certificate
|
||||
ports:
|
||||
|
@ -68,3 +74,4 @@ volumes:
|
|||
https_cert:
|
||||
media_root:
|
||||
postgres_data:
|
||||
sqlite_volume:
|
||||
|
|
65
entrypoint.sh
Normal file → Executable file
65
entrypoint.sh
Normal file → Executable file
|
@ -1,4 +1,5 @@
|
|||
#!/bin/bash
|
||||
PRODUCTION_SETTINGS_FILE="/app/routerfleet/production_settings.py"
|
||||
|
||||
set -e
|
||||
|
||||
|
@ -7,8 +8,51 @@ if [ -z "$SERVER_ADDRESS" ]; then
|
|||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "$POSTGRES_PASSWORD" ]; then
|
||||
echo "POSTGRES_PASSWORD environment variable is not set. Exiting."
|
||||
if [[ "${DATABASE_ENGINE,,}" == "sqlite" ]]; then
|
||||
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
|
||||
fi
|
||||
|
||||
|
@ -17,27 +61,18 @@ if [[ "${DEBUG_MODE,,}" == "true" ]]; then
|
|||
DEBUG_VALUE="True"
|
||||
fi
|
||||
|
||||
cat > /app/routerfleet/production_settings.py <<EOL
|
||||
cat > $PRODUCTION_SETTINGS_FILE <<EOL
|
||||
DEBUG = $DEBUG_VALUE
|
||||
ALLOWED_HOSTS = ['routerfleet', '$SERVER_ADDRESS']
|
||||
CSRF_TRUSTED_ORIGINS = ['http://routerfleet', 'https://$SERVER_ADDRESS']
|
||||
SECRET_KEY = '$(openssl rand -base64 32)'
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.postgresql',
|
||||
'NAME': 'routerfleet',
|
||||
'USER': 'routerfleet',
|
||||
'PASSWORD': '$POSTGRES_PASSWORD',
|
||||
'HOST': 'routerfleet-postgres',
|
||||
'PORT': '5432',
|
||||
}
|
||||
}
|
||||
$DATABASES_CONFIG
|
||||
EOL
|
||||
|
||||
if [ -n "$TIMEZONE" ]; then
|
||||
echo "TIME_ZONE = '$TIMEZONE'" >> /app/routerfleet/production_settings.py
|
||||
echo "TIME_ZONE = '$TIMEZONE'" >> $PRODUCTION_SETTINGS_FILE
|
||||
fi
|
||||
|
||||
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