-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from ixcat/alyx-docker-202101
ingest-entrypoint.sh: adjust mkdb/rotatedb for 2 database usage
- Loading branch information
Showing
3 changed files
with
109 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,7 @@ services: | |
- "8888:8888" | ||
networks: | ||
- ibl | ||
command: [ "dev" ] | ||
|
||
networks: | ||
ibl: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
# ------- | ||
|
||
dbdump="/tmp/dump.sql.gz" | ||
dbcreated="/src/alyx/alyx/db_created" | ||
dbloaded="/src/alyx/alyx/db_loaded" | ||
sucreated="/src/alyx/alyx/superuser_created" | ||
|
||
|
@@ -37,36 +38,34 @@ fetchdump() { | |
# ---- | ||
|
||
mkdb() { | ||
if [ -f "${dbloaded}" ]; then | ||
if [ -f "${dbcreated}" ]; then | ||
echo '# => using existing database'; | ||
else | ||
echo '#==> creating database'; | ||
echo '# ==> creating database'; | ||
|
||
[ ! -f "${dbdump}" ] \ | ||
&& err_exit ".. no database dump in $dbdump"; | ||
|
||
createdb alyx_old; | ||
createdb alyx; | ||
|
||
touch ${dbcreated}; | ||
fi | ||
} | ||
|
||
# loaddb | ||
# ------ | ||
|
||
loaddb() { | ||
echo "# => loading database ${dbdump}" | ||
gzip -dc ${dbdump} |psql -d alyx; | ||
touch ${dbloaded}; | ||
} | ||
|
||
# rotatedb | ||
# -------- | ||
|
||
rotatedb() { | ||
echo "# => rotating databases"; | ||
echo "# ==> NOT IMPLEMENTED"; | ||
if [ -f "${dbloaded}" ]; then | ||
echo '# => database loaded - skipping load.'; | ||
else | ||
echo "# => loading database ${dbdump}" | ||
gzip -dc ${dbdump} |psql -d alyx; | ||
touch ${dbloaded}; | ||
fi | ||
} | ||
|
||
|
||
# configure alyx/django | ||
# --------------------- | ||
|
||
|
@@ -76,15 +75,47 @@ alyxcfg() { | |
if [ ! -f "$sucreated" ]; then | ||
|
||
echo '# ==> configuring settings_secret.py' | ||
|
||
|
||
# custom settings_secret for multiple DBs | ||
# see also :alyx/alyx/alyx/settings_secret_template.py | ||
|
||
cnf="/src/alyx/alyx/alyx/settings_secret.py"; | ||
sed \ | ||
-e "s/%SECRET_KEY%/0xdeadbeef/" \ | ||
-e "s/%DBNAME%/alyx/" \ | ||
-e "s/%DBUSER%/$PGUSER/" \ | ||
-e "s/%DBPASSWORD%/$PGPASSWORD/" \ | ||
-e "s/127.0.0.1/$PGHOST/" \ | ||
< /src/alyx/alyx/alyx/settings_secret_template.py \ | ||
> /src/alyx/alyx/alyx/settings_secret.py | ||
> $cnf <<-EOF | ||
SECRET_KEY = '%SECRET_KEY%' | ||
DATABASES = { | ||
'default': { | ||
'ENGINE': 'django.db.backends.postgresql_psycopg2', | ||
'NAME': '%DBNAME%', | ||
'USER': '%DBUSER%', | ||
'PASSWORD': '%DBPASSWORD%', | ||
'HOST': '127.0.0.1', | ||
'PORT': '5432', | ||
}, | ||
'old': { | ||
'ENGINE': 'django.db.backends.postgresql_psycopg2', | ||
'NAME': '%DBNAME%_old', | ||
'USER': '%DBUSER%', | ||
'PASSWORD': '%DBPASSWORD%', | ||
'HOST': '127.0.0.1', | ||
'PORT': '5432', | ||
} | ||
} | ||
EMAIL_HOST = 'mail.superserver.net' | ||
EMAIL_HOST_USER = '[email protected]' | ||
EMAIL_HOST_PASSWORD = 'UnbreakablePassword' | ||
EMAIL_PORT = 587 | ||
EMAIL_USE_TLS = True | ||
EOF | ||
|
||
echo '# ==> creating alyx superuser' | ||
|
||
|
@@ -113,7 +144,7 @@ alyxcfg() { | |
admin.save() | ||
exit() | ||
EOF | ||
|
||
touch ${sucreated}; | ||
fi | ||
|
||
|
@@ -128,7 +159,6 @@ alyxprep() { | |
/src/alyx/alyx/manage.py migrate; | ||
} | ||
|
||
|
||
# alyxstart | ||
# --------- | ||
|
||
|
@@ -137,28 +167,76 @@ alyxstart() { | |
/src/alyx/alyx/manage.py runserver --insecure 0.0.0.0:8888; | ||
} | ||
|
||
# run | ||
# --- | ||
# create/load/etc full-command | ||
# renamedb | ||
# -------- | ||
|
||
renamedb() { | ||
echo "# => renaming databases:"; | ||
|
||
echo "# ==> ... dropping alyx_old"; | ||
dropdb alyx_old || err_exit "couldn't drop alyx_old"; | ||
|
||
echo "# ==> ... renaming alyx to alyx_old"; | ||
psql -c 'alter database alyx rename to alyx_old;' \ | ||
> /dev/null \ | ||
|| err_exit "couldn't rename alyx to alyx_old"; | ||
|
||
echo "# ==> ... creating new alyx"; | ||
createdb alyx || err_exit "couldn't rename alyx to alyx_old"; | ||
|
||
rm -f ${dbloaded}; | ||
rm -f ${sucreated}; | ||
|
||
echo "# => ok."; | ||
} | ||
|
||
|
||
run() { | ||
# init | ||
# ---- | ||
# perform all initialization steps | ||
|
||
init() { | ||
fetchdump; | ||
mkdb; | ||
loaddb; | ||
alyxcfg; | ||
alyxprep; | ||
} | ||
|
||
|
||
# www | ||
# --- | ||
# initialize environment and run alyx web | ||
|
||
www() { | ||
init; | ||
alyxstart; | ||
} | ||
|
||
# dev | ||
# --- | ||
# initialize environment and wait indefinitely | ||
|
||
dev() { | ||
init; | ||
exec tail -f /dev/null; | ||
} | ||
|
||
# _start: | ||
|
||
case "$1" in | ||
"fetchdump") fetchdump;; | ||
"createdb") createdb;; | ||
"mkdb") mkdb;; | ||
"loaddb") loaddb;; | ||
"alyxcfg") alyxcfg;; | ||
"alyxprep") alyxprep;; | ||
"alyxstart") alyxstart;; | ||
"renamedb") renamedb;; | ||
"www") www;; | ||
"dev") dev;; | ||
"sh") exec /bin/sh -c "$*";; | ||
*) run;; | ||
"help") \ | ||
echo "usage: `basename $0` [fetchdump|mkdb|loaddb|alyxcfg|alyxprep|alyxstart|renamedb|www|dev|sh]";; | ||
*) ;; # ... sourceable | ||
esac | ||
|