diff --git a/images/base/entrypoint.sh b/images/base/entrypoint.sh index cf3942b..07b11d8 100755 --- a/images/base/entrypoint.sh +++ b/images/base/entrypoint.sh @@ -1,71 +1,69 @@ #!/bin/bash set -e +source /srv/softwareheritage/utils/pgsql.sh + # generate the config file from the 'template' if [ -f /etc/softwareheritage/config.yml.tmpl ]; then # I know... I know! eval "echo \"`cat /etc/softwareheritage/config.yml.tmpl`\"" > \ /etc/softwareheritage/config.yml fi # generate the pgservice file if any if [ -f /run/secrets/postgres-password ]; then - echo 'Available secrets:' - ls -l /run/secrets/ + echo 'Available secrets:' + ls -l /run/secrets/ - cat >~/.pg_service.conf <~/.pgpass - chmod 0600 ~/.pgpass + setup_pgsql fi # For debugging purpose echo "### CONFIG FILE ###" cat /etc/softwareheritage/config.yml echo "###################" case "$1" in "shell") exec bash -i ;; - "db-init") + "db-init") + wait_pgsql echo "Initialize the SWH database" - exec swh db init - ;; - "graph-replayer") + exec swh db init + ;; + "graph-replayer") echo "Starting the SWH mirror graph replayer" - exec sh -c "trap : TERM INT; while :; do swh journal replay; done" - ;; - "content-replayer") + exec sh -c "trap : TERM INT; while :; do swh journal replay; done" + ;; + "content-replayer") echo "Starting the SWH mirror content replayer" - exec sh -c "trap : TERM INT; while :; do swh journal content-replay; done" - ;; + exec sh -c "trap : TERM INT; while :; do swh journal content-replay; done" + ;; "objstorage") echo "Starting the SWH $1 RPC server" exec gunicorn3 \ - --bind 0.0.0.0:${PORT:-5000} \ - --bind unix:/var/run/gunicorn/swh/$1.sock \ - --worker-class aiohttp.worker.GunicornWebWorker \ + --bind 0.0.0.0:${PORT:-5000} \ + --bind unix:/var/run/gunicorn/swh/$1.sock \ + --worker-class aiohttp.worker.GunicornWebWorker \ + --threads 4 \ + --workers 2 \ --log-level "${LOG_LEVEL:-WARNING}" \ --timeout 3600 \ - swh.$1.api.wsgi + "swh.$1.api.server:make_app_from_configfile()" ;; *) + wait_pgsql echo "Starting the SWH $1 RPC server" - swh db init || echo "swh db init failed, database is probably already initialized; ignored" + swh db init || echo "swh db init failed, database is probably already initialized; ignored" exec gunicorn3 \ - --bind 0.0.0.0:${PORT:-5000} \ - --bind unix:/var/run/gunicorn/swh/$1.sock \ + --bind 0.0.0.0:${PORT:-5000} \ + --bind unix:/var/run/gunicorn/swh/$1.sock \ --threads 4 \ --workers 2 \ --log-level "${LOG_LEVEL:-WARNING}" \ --timeout 3600 \ - swh.$1.api.wsgi + "swh.$1.api.server:make_app_from_configfile()" ;; esac diff --git a/images/web/entrypoint.sh b/images/web/entrypoint.sh index 2d5272d..9730548 100755 --- a/images/web/entrypoint.sh +++ b/images/web/entrypoint.sh @@ -1,32 +1,47 @@ #!/bin/bash set -e +create_admin_script=" +from django.contrib.auth import get_user_model; + +username = 'admin'; +password = 'admin'; +email = 'admin@swh-web.org'; + +User = get_user_model(); + +if not User.objects.filter(username = username).exists(): + User.objects.create_superuser(username, email, password); +" + # generate the config file from the 'template' if [ -f /etc/softwareheritage/config.yml.tmpl ]; then # I know... I know! eval "echo \"`cat /etc/softwareheritage/config.yml.tmpl`\"" > \ /etc/softwareheritage/config.yml fi case "$1" in "shell") exec bash -i ;; - "migrate") + + "serve") echo "Migrating db using ${DJANGO_SETTINGS_MODULE}" django-admin migrate --settings=${DJANGO_SETTINGS_MODULE} + echo "Creating admin user" - echo "from django.contrib.auth import get_user_model; User = get_user_model(); User.objects.create_superuser('admin', 'admin@swh-web.org', 'admin')" | python3 -m swh.web.manage shell || true - ;; - "serve") + echo "$create_admin_script" | python3 -m swh.web.manage shell + echo "starting the swh-web server" mkdir -p /var/run/gunicorn/swh/web - exec gunicorn3 --bind 0.0.0.0:5004 \ - --bind unix:/var/run/gunicorn/swh/web/sock \ - --threads 2 \ - --workers 2 \ - --timeout 3600 \ - swh.web.wsgi + exec gunicorn3 \ + --bind 0.0.0.0:5004 \ + --bind unix:/var/run/gunicorn/swh/web/sock \ + --threads 2 \ + --workers 2 \ + --timeout 3600 \ + 'django.core.wsgi:get_wsgi_application()' ;; esac