From 7a606b9b7696b4d9ab4686a2e85ea202ca0cde82 Mon Sep 17 00:00:00 2001 From: PCoder Date: Sun, 20 Jun 2021 16:47:06 +0530 Subject: [PATCH 1/2] Create a new Makefile As we are moving away from docker, I propose to save the current `Makefile` as `Makefile.docker-compose` and create a new makefile `Makefile.native` and soft link it to Makefile `Makefile.native` is identical to `Makefile.docker-compose` --- Makefile | 122 +--------------------------------------- Makefile.docker-compose | 121 +++++++++++++++++++++++++++++++++++++++ Makefile.native | 79 ++++++++++++++++++++++++++ 3 files changed, 201 insertions(+), 121 deletions(-) mode change 100644 => 120000 Makefile create mode 100644 Makefile.docker-compose create mode 100644 Makefile.native diff --git a/Makefile b/Makefile deleted file mode 100644 index b21f3c4..0000000 --- a/Makefile +++ /dev/null @@ -1,121 +0,0 @@ -export COMPOSE_FILE=./docker-compose.yml -export COMPOSE_PROJECT_NAME=publichealth -export EMAIL=change_me@localhost.localhost - -default: build - -local-loaddata: - sed -i 's/\"is_default_site\": true/\"is_default_site\": false/g' publichealth.home.json - python manage.py loaddata publichealth.home.json - -upgrade: - docker-compose pull - -build-cached: - docker-compose build - -build: - docker-compose build --no-cache - -run-here: - docker-compose stop web # for restart cases, when already running - docker-compose up - -run: - docker-compose up -d # detach by default - -stop: - docker-compose stop web - -restart: stop run - -migrate: - docker-compose exec web ./manage.py migrate - -migrations: - docker-compose exec web ./manage.py makemigrations --merge - -apply-migrations: migrations migrate - -setup: - docker-compose exec web ./manage.py migrate - docker-compose exec web ./manage.py createsuperuser --username admin --email $(EMAIL) --noinput - -rebuild: - docker-compose pull - docker-compose build web - docker-compose stop web - docker-compose kill web - -compress: - docker-compose exec web ./manage.py collectstatic --noinput -i media - docker-compose exec web ./manage.py compress - -release: rebuild compress run - -reindex: - docker-compose exec web ./manage.py update_index - -clear_index: - docker-compose exec elasticsearch curl -XDELETE localhost:9200/_all - -django-exec-bash: - # execute bash in the currently running container - docker-compose exec web bash - -django-run-bash: - # run new django container, with bash, and remove it after usage - docker-compose run --rm --no-deps web bash - -django-shell: - docker-compose exec web ./manage.py shell - -logs: - docker-compose exec web tail /var/log/wagtail/publichealth.log /var/log/wagtail/wagtail.log /var/log/wagtail/error.log - -docker-logs: - docker-compose logs -f --tail=500 - -backup-data: - docker-compose exec web ./manage.py dumpdata --natural-foreign -e auth.permission -e contenttypes -e wagtailcore.GroupCollectionPermission -e wagtailcore.GroupPagePermission -e wagtailimages.rendition -e sessions -e feedler.feedlysettings > ~/publichealth.home.json - zip ~/publichealth.home.json.`date +"%d%m%Y-%H%M"`.zip ~/publichealth.home.json - rm ~/publichealth.home.json - -backup-images: - echo "Backing up images ..." - sudo chown -R ansible media - zip -ruq ~/media.zip media - -backup: backup-data backup-images - -loaddata: - docker-compose exec web ./manage.py loaddata publichealth.home.json - -restore: django-loaddata restart - -psql: - docker-compose exec postgres psql -U postgres -d postgres - -pg-run-detached: - # start pg service - docker-compose up -d postgres - -pg-exec: - docker-compose exec postgres bash - -pg-dump: - docker-compose exec postgres bash -c 'pg_dump -U postgres -d postgres -f ./latest.sql' - -pg-backup: - docker-compose exec postgres bash -c 'pg_dump -U postgres -d postgres' > ~/pg-backup.sql - zip ~/pg-backup.sql.`date +"%d%m%Y-%H%M"`.zip ~/pg-backup.sql - rm ~/pg-backup.sql - -pg-restore: - docker-compose exec postgres bash -c 'psql -U postgres -d postgres -f ./latest.sql' - -pg-surefire-drop-restore-db: - # drop existing database, recreate it, and then restore its content from backup. - docker-compose exec postgres bash -c 'dropdb -h localhost -U postgres postgres' - docker-compose exec postgres bash -c 'createdb -h localhost -U postgres postgres' - make pg-restore diff --git a/Makefile b/Makefile new file mode 120000 index 0000000..d7c907f --- /dev/null +++ b/Makefile @@ -0,0 +1 @@ +Makefile.native \ No newline at end of file diff --git a/Makefile.docker-compose b/Makefile.docker-compose new file mode 100644 index 0000000..b21f3c4 --- /dev/null +++ b/Makefile.docker-compose @@ -0,0 +1,121 @@ +export COMPOSE_FILE=./docker-compose.yml +export COMPOSE_PROJECT_NAME=publichealth +export EMAIL=change_me@localhost.localhost + +default: build + +local-loaddata: + sed -i 's/\"is_default_site\": true/\"is_default_site\": false/g' publichealth.home.json + python manage.py loaddata publichealth.home.json + +upgrade: + docker-compose pull + +build-cached: + docker-compose build + +build: + docker-compose build --no-cache + +run-here: + docker-compose stop web # for restart cases, when already running + docker-compose up + +run: + docker-compose up -d # detach by default + +stop: + docker-compose stop web + +restart: stop run + +migrate: + docker-compose exec web ./manage.py migrate + +migrations: + docker-compose exec web ./manage.py makemigrations --merge + +apply-migrations: migrations migrate + +setup: + docker-compose exec web ./manage.py migrate + docker-compose exec web ./manage.py createsuperuser --username admin --email $(EMAIL) --noinput + +rebuild: + docker-compose pull + docker-compose build web + docker-compose stop web + docker-compose kill web + +compress: + docker-compose exec web ./manage.py collectstatic --noinput -i media + docker-compose exec web ./manage.py compress + +release: rebuild compress run + +reindex: + docker-compose exec web ./manage.py update_index + +clear_index: + docker-compose exec elasticsearch curl -XDELETE localhost:9200/_all + +django-exec-bash: + # execute bash in the currently running container + docker-compose exec web bash + +django-run-bash: + # run new django container, with bash, and remove it after usage + docker-compose run --rm --no-deps web bash + +django-shell: + docker-compose exec web ./manage.py shell + +logs: + docker-compose exec web tail /var/log/wagtail/publichealth.log /var/log/wagtail/wagtail.log /var/log/wagtail/error.log + +docker-logs: + docker-compose logs -f --tail=500 + +backup-data: + docker-compose exec web ./manage.py dumpdata --natural-foreign -e auth.permission -e contenttypes -e wagtailcore.GroupCollectionPermission -e wagtailcore.GroupPagePermission -e wagtailimages.rendition -e sessions -e feedler.feedlysettings > ~/publichealth.home.json + zip ~/publichealth.home.json.`date +"%d%m%Y-%H%M"`.zip ~/publichealth.home.json + rm ~/publichealth.home.json + +backup-images: + echo "Backing up images ..." + sudo chown -R ansible media + zip -ruq ~/media.zip media + +backup: backup-data backup-images + +loaddata: + docker-compose exec web ./manage.py loaddata publichealth.home.json + +restore: django-loaddata restart + +psql: + docker-compose exec postgres psql -U postgres -d postgres + +pg-run-detached: + # start pg service + docker-compose up -d postgres + +pg-exec: + docker-compose exec postgres bash + +pg-dump: + docker-compose exec postgres bash -c 'pg_dump -U postgres -d postgres -f ./latest.sql' + +pg-backup: + docker-compose exec postgres bash -c 'pg_dump -U postgres -d postgres' > ~/pg-backup.sql + zip ~/pg-backup.sql.`date +"%d%m%Y-%H%M"`.zip ~/pg-backup.sql + rm ~/pg-backup.sql + +pg-restore: + docker-compose exec postgres bash -c 'psql -U postgres -d postgres -f ./latest.sql' + +pg-surefire-drop-restore-db: + # drop existing database, recreate it, and then restore its content from backup. + docker-compose exec postgres bash -c 'dropdb -h localhost -U postgres postgres' + docker-compose exec postgres bash -c 'createdb -h localhost -U postgres postgres' + make pg-restore diff --git a/Makefile.native b/Makefile.native new file mode 100644 index 0000000..06937f8 --- /dev/null +++ b/Makefile.native @@ -0,0 +1,79 @@ +export EMAIL=change_me@localhost.localhost + +default: release + +local-loaddata: + sed -i 's/\"is_default_site\": true/\"is_default_site\": false/g' publichealth.home.json + python manage.py loaddata publichealth.home.json + +migrate: + . /home/app/pyvenv/bin/activate && ./manage.py migrate + +migrations: + . /home/app/pyvenv/bin/activate && ./manage.py makemigrations --merge + +apply-migrations: migrations migrate + +setup: + . /home/app/pyvenv/bin/activate && ./manage.py migrate + . /home/app/pyvenv/bin/activate && ./manage.py createsuperuser --username admin --email $(EMAIL) --noinput + +rebuild: + rm -rf node_modules + yarn install + cp -rf node_modules/@bower_components/* /home/app/app/publichealth/static/libs + +restart-uwsgi: + sudo /etc/init.d/uwsgi restart + +compress: + . /home/app/pyvenv/bin/activate && ./manage.py collectstatic --noinput -i media + . /home/app/pyvenv/bin/activate && ./manage.py compress + +release: rebuild compress restart-uwsgi + +reindex: + . /home/app/pyvenv/bin/activate && ./manage.py update_index + +clear_index: + elasticsearch curl -XDELETE localhost:9200/_all + +django-shell: + . /home/app/pyvenv/bin/activate && ./manage.py shell + +logs: + tail /var/log/wagtail/publichealth.log /var/log/wagtail/wagtail.log /var/log/wagtail/error.log + +backup-data: + . /home/app/pyvenv/bin/activate && ./manage.py dumpdata --natural-foreign -e auth.permission -e contenttypes -e wagtailcore.GroupCollectionPermission -e wagtailcore.GroupPagePermission -e wagtailimages.rendition -e sessions -e feedler.feedlysettings > ~/publichealth.home.json + zip ~/publichealth.home.json.`date +"%d%m%Y-%H%M"`.zip ~/publichealth.home.json + rm ~/publichealth.home.json + +backup-images: + echo "Backing up images ..." + sudo chown -R app:app media + zip -ruq ~/media.zip media + +backup: backup-data backup-images + +loaddata: + . /home/app/pyvenv/bin/activate && ./manage.py loaddata publichealth.home.json + +restore: django-loaddata restart + +pg-dump: + pg_dump -U app -d publichealth -f ./latest.sql + +pg-backup: + pg_dump -U app -d publichealth > ~/pg-backup.sql + zip ~/pg-backup.sql.`date +"%d%m%Y-%H%M"`.zip ~/pg-backup.sql + rm ~/pg-backup.sql + +pg-restore: + psql -U app -d publichealth -f ./latest.sql + +pg-surefire-drop-restore-db: + # drop existing database, recreate it, and then restore its content from backup. + dropdb -h localhost -U app publichealth + createdb -h localhost -U app publichealth + make pg-restore From ac97190ce0a5a11d9a152fb976a0eb6bd794dd1b Mon Sep 17 00:00:00 2001 From: PCoder Date: Tue, 22 Jun 2021 08:26:56 +0530 Subject: [PATCH 2/2] Get changes to original Makefile before merge --- Makefile.docker-compose | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.docker-compose b/Makefile.docker-compose index b21f3c4..3f97d8e 100644 --- a/Makefile.docker-compose +++ b/Makefile.docker-compose @@ -51,7 +51,7 @@ compress: docker-compose exec web ./manage.py collectstatic --noinput -i media docker-compose exec web ./manage.py compress -release: rebuild compress run +release: rebuild run compress restart reindex: docker-compose exec web ./manage.py update_index