From 64e1805b5387ca3ab7cad55b85b8ae54be076d35 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Sat, 18 Jan 2020 23:20:34 +0000 Subject: [PATCH] Add more util scripts --- utils/bash.sh | 2 ++ utils/create_migration.sh | 9 +++++++++ utils/db.sh | 5 +++++ utils/reload.sh | 2 ++ utils/run_migrations.sh | 5 +++++ utils/start.sh | 2 ++ utils/update.sh | 1 + 7 files changed, 26 insertions(+) create mode 100755 utils/create_migration.sh create mode 100755 utils/db.sh create mode 100755 utils/run_migrations.sh diff --git a/utils/bash.sh b/utils/bash.sh index f75fc413..8a3c6a0e 100755 --- a/utils/bash.sh +++ b/utils/bash.sh @@ -1,3 +1,5 @@ #!/bin/bash +# Open SSH to app instance + docker exec -it contentdb_app_1 bash diff --git a/utils/create_migration.sh b/utils/create_migration.sh new file mode 100755 index 00000000..910344c5 --- /dev/null +++ b/utils/create_migration.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +# Create a database migration, and copy it back to the host. + +docker exec -it contentdb_app_1 sh -c "FLASK_CONFIG=../config.cfg FLASK_APP=app/__init__.py flask db migrate" +docker exec -u root -it contentdb_app_1 sh -c "cp /home/cdb/migrations/versions/* /source/migrations/versions/" + +USER=$(whoami) +sudo chown -R $USER:$USER migrations/versions diff --git a/utils/db.sh b/utils/db.sh new file mode 100755 index 00000000..f7f6af29 --- /dev/null +++ b/utils/db.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +# Open SQL console for the database + +docker exec -it contentdb_db_1 sh -c "psql contentdb contentdb" diff --git a/utils/reload.sh b/utils/reload.sh index e3995153..2b21e799 100755 --- a/utils/reload.sh +++ b/utils/reload.sh @@ -1,3 +1,5 @@ #!/bin/bash +# Hot/live reload - only works in debug mode + docker exec -it contentdb_app_1 sh -c "cp -r /source/* ." diff --git a/utils/run_migrations.sh b/utils/run_migrations.sh new file mode 100755 index 00000000..ac96a95d --- /dev/null +++ b/utils/run_migrations.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +# Run all pending migrations + +docker exec -it contentdb_app_1 sh -c "FLASK_CONFIG=../config.cfg FLASK_APP=app/__init__.py flask db update" diff --git a/utils/start.sh b/utils/start.sh index 0fa9e795..c69b676b 100755 --- a/utils/start.sh +++ b/utils/start.sh @@ -2,6 +2,8 @@ # # Call from a docker host to build and start CDB. +# This is really only for production mode, for debugging it's better to use +# docker-compose directly: docker-compose up --build # sudo docker-compose up --build -d --scale worker=2 diff --git a/utils/update.sh b/utils/update.sh index 97e25930..aeba314e 100755 --- a/utils/update.sh +++ b/utils/update.sh @@ -2,6 +2,7 @@ # # Call from a docker host to rebuild and update running instances of CDB. +# This is for production use. See reload.sh for debug mode hot/live reloading. # sudo docker-compose build app