<commit_before>SHELL := /bin/bash
PROJECT_ID := inasafedjango
DELAY = 10
LANG = en
TARGET_SERVER = realtime.inasafe.org

# ----------------------------------------------------------------------------
#    P R O D U C T I O N     C O M M A N D S
# ----------------------------------------------------------------------------

default: web

up: build web

down:
	@echo
	@echo "------------------------------------------------------------------"
	@echo "Shutdown docker containers"
	@echo "------------------------------------------------------------------"
	@docker-compose -p $(PROJECT_ID) down

complete-deploy: up wait migrate collectstatic makemessages compilemessages inasafe-worker indicator-worker realtime-worker headless-worker reload status

wait:
	@echo
	@echo "------------------------------------------------------------------"
	@echo "Gives $(DELAY) second delay before running additional command "
	@echo "------------------------------------------------------------------"
	sleep $(DELAY)

deploy: up wait inasafe-worker indicator-worker
	@echo
	@echo "------------------------------------------------------------------"
	@echo "Bringing up fresh instance "
	@echo "You can access it on http://localhost:61100"
	@echo "------------------------------------------------------------------"

restart: down deploy

ansible-check:
	@echo "Check ansible command"
	@ansible -i ansible/development/hosts all -m ping
	@ansible-playbook -i ansible/development/hosts ansible/development/site.yml --check --list-tasks --list-hosts $(ANSIBLE_ARGS)

setup-ansible:
	@echo "Setup configurations using ansible"
	@ansible-playbook -i ansible/development/hosts ansible/development/site.yml -v $(ANSIBLE_ARGS)

check-flake8:
	@echo "Check flake 8"
	@flake8 ../django_project

pull-external-services:
	@echo "Pull InaSAFE Realtime"
	@docker-compose -p $(PROJECT_ID) pull realtime-worker
	@echo "Pull InaSAFE Headless"
	@docker-compose -p $(PROJECT_ID) pull headless-worker

pull-external-services-docker:
	@echo "Pull InaSAFE Realtime"
	@docker pull inasafe/realtime_hazard-processor
	@echo "Pull InaSAFE Headless"
	@docker pull inasafe/headless_processor

coverage-tests:
	@docker-compose -p $(PROJECT_ID) exec uwsgi coverage run -p --branch --source='.' manage.py test realtime --noinput --liveserver=0.0.0.0:8080 -v 2

integration-tests-worker:
	@echo
	@echo "------------------------------------------------------------------"
	@echo "Running integration tests celery worker "
	@echo "------------------------------------------------------------------"
	@docker-compose -p $(PROJECT_ID) up -d integration-test-worker

integration-tests-worker-restart:
	@echo
	@echo "------------------------------------------------------------------"
	@echo "Restart integration tests celery worker "
	@echo "------------------------------------------------------------------"
	@docker-compose -p $(PROJECT_ID) restart integration-test-worker

integration-tests-worker-stop:
	@echo
	@echo "------------------------------------------------------------------"
	@echo "Stop integration tests celery worker "
	@echo "------------------------------------------------------------------"
	@docker-compose -p $(PROJECT_ID) stop integration-test-worker

integration-tests-worker-logs:
	@echo
	@echo "------------------------------------------------------------------"
	@echo "Running integration tests celery worker logs"
	@echo "------------------------------------------------------------------"
	@docker-compose -p $(PROJECT_ID) logs -f --tail=50 integration-test-worker

combined-worker-logs:
	@echo
	@echo "------------------------------------------------------------------"
	@echo "Showing combined worker logs"
	@echo "------------------------------------------------------------------"
	@{ make realtime-worker-logs & make headless-worker-logs & make inasafe-worker-logs; }

combined-integration-worker-logs:
	@echo
	@echo "------------------------------------------------------------------"
	@echo "Showing combined integration worker logs"
	@echo "------------------------------------------------------------------"
	@{ make realtime-worker-logs & make headless-worker-logs & make integration-tests-worker-logs & make integration-tests-runner-logs; }

integration-tests: realtime-worker headless-worker integration-tests-worker
	@docker-compose -p $(PROJECT_ID) exec uwsgi coverage run -p --branch --source='.' manage.py test --liveserver=0.0.0.0:8080 --noinput realtime.tests.test_scenarios.TestEarthquakeTasks
	@make integration-tests-worker-restart
	@docker-compose -p $(PROJECT_ID) exec uwsgi coverage run -p --branch --source='.' manage.py test --liveserver=0.0.0.0:8080 --noinput realtime.tests.test_scenarios.TestFloodTasks
	@make integration-tests-worker-restart
	@docker-compose -p $(PROJECT_ID) exec uwsgi coverage run -p --branch --source='.' manage.py test --liveserver=0.0.0.0:8080 --noinput realtime.tests.test_scenarios.TestAshTasks

integration-tests-with-logs: realtime-worker headless-worker integration-tests-worker
	@-{ make headless-worker-logs & make realtime-worker-logs & make integration-tests-worker-logs & docker-compose -p $(PROJECT_ID) exec uwsgi coverage run -p --branch --source='.' manage.py test --liveserver=0.0.0.0:8080 --noinput realtime.tests.test_scenarios.TestEarthquakeTasks; }
	@-make integration-tests-worker-restart
	@-{ make headless-worker-logs & make realtime-worker-logs & make integration-tests-worker-logs & docker-compose -p $(PROJECT_ID) exec uwsgi coverage run -p --branch --source='.' manage.py test --liveserver=0.0.0.0:8080 --noinput realtime.tests.test_scenarios.TestFloodTasks; }
	@-make integration-tests-worker-restart
	@-{ make headless-worker-logs & make realtime-worker-logs & make integration-tests-worker-logs & docker-compose -p $(PROJECT_ID) exec uwsgi coverage run -p --branch --source='.' manage.py test --liveserver=0.0.0.0:8080 --noinput realtime.tests.test_scenarios.TestAshTasks; }

retrieve-context-data:
	@docker run --rm -d --name analysis_context kartoza/analysis_context_image:v4.4.0 tail -f /dev/null
	@docker cp -a analysis_context:/data/. headless-data/contexts<commit_msg>Change repo name for analysis context to inasafe<commit_after>SHELL := /bin/bash
PROJECT_ID := inasafedjango
DELAY = 10
LANG = en
TARGET_SERVER = realtime.inasafe.org

# ----------------------------------------------------------------------------
#    P R O D U C T I O N     C O M M A N D S
# ----------------------------------------------------------------------------

default: web

up: build web

down:
	@echo
	@echo "------------------------------------------------------------------"
	@echo "Shutdown docker containers"
	@echo "------------------------------------------------------------------"
	@docker-compose -p $(PROJECT_ID) down

complete-deploy: up wait migrate collectstatic makemessages compilemessages inasafe-worker indicator-worker realtime-worker headless-worker reload status

wait:
	@echo
	@echo "------------------------------------------------------------------"
	@echo "Gives $(DELAY) second delay before running additional command "
	@echo "------------------------------------------------------------------"
	sleep $(DELAY)

deploy: up wait inasafe-worker indicator-worker
	@echo
	@echo "------------------------------------------------------------------"
	@echo "Bringing up fresh instance "
	@echo "You can access it on http://localhost:61100"
	@echo "------------------------------------------------------------------"

restart: down deploy

ansible-check:
	@echo "Check ansible command"
	@ansible -i ansible/development/hosts all -m ping
	@ansible-playbook -i ansible/development/hosts ansible/development/site.yml --check --list-tasks --list-hosts $(ANSIBLE_ARGS)

setup-ansible:
	@echo "Setup configurations using ansible"
	@ansible-playbook -i ansible/development/hosts ansible/development/site.yml -v $(ANSIBLE_ARGS)

check-flake8:
	@echo "Check flake 8"
	@flake8 ../django_project

pull-external-services:
	@echo "Pull InaSAFE Realtime"
	@docker-compose -p $(PROJECT_ID) pull realtime-worker
	@echo "Pull InaSAFE Headless"
	@docker-compose -p $(PROJECT_ID) pull headless-worker

pull-external-services-docker:
	@echo "Pull InaSAFE Realtime"
	@docker pull inasafe/realtime_hazard-processor
	@echo "Pull InaSAFE Headless"
	@docker pull inasafe/headless_processor

coverage-tests:
	@docker-compose -p $(PROJECT_ID) exec uwsgi coverage run -p --branch --source='.' manage.py test realtime --noinput --liveserver=0.0.0.0:8080 -v 2

integration-tests-worker:
	@echo
	@echo "------------------------------------------------------------------"
	@echo "Running integration tests celery worker "
	@echo "------------------------------------------------------------------"
	@docker-compose -p $(PROJECT_ID) up -d integration-test-worker

integration-tests-worker-restart:
	@echo
	@echo "------------------------------------------------------------------"
	@echo "Restart integration tests celery worker "
	@echo "------------------------------------------------------------------"
	@docker-compose -p $(PROJECT_ID) restart integration-test-worker

integration-tests-worker-stop:
	@echo
	@echo "------------------------------------------------------------------"
	@echo "Stop integration tests celery worker "
	@echo "------------------------------------------------------------------"
	@docker-compose -p $(PROJECT_ID) stop integration-test-worker

integration-tests-worker-logs:
	@echo
	@echo "------------------------------------------------------------------"
	@echo "Running integration tests celery worker logs"
	@echo "------------------------------------------------------------------"
	@docker-compose -p $(PROJECT_ID) logs -f --tail=50 integration-test-worker

combined-worker-logs:
	@echo
	@echo "------------------------------------------------------------------"
	@echo "Showing combined worker logs"
	@echo "------------------------------------------------------------------"
	@{ make realtime-worker-logs & make headless-worker-logs & make inasafe-worker-logs; }

combined-integration-worker-logs:
	@echo
	@echo "------------------------------------------------------------------"
	@echo "Showing combined integration worker logs"
	@echo "------------------------------------------------------------------"
	@{ make realtime-worker-logs & make headless-worker-logs & make integration-tests-worker-logs & make integration-tests-runner-logs; }

integration-tests: realtime-worker headless-worker integration-tests-worker
	@docker-compose -p $(PROJECT_ID) exec uwsgi coverage run -p --branch --source='.' manage.py test --liveserver=0.0.0.0:8080 --noinput realtime.tests.test_scenarios.TestEarthquakeTasks
	@make integration-tests-worker-restart
	@docker-compose -p $(PROJECT_ID) exec uwsgi coverage run -p --branch --source='.' manage.py test --liveserver=0.0.0.0:8080 --noinput realtime.tests.test_scenarios.TestFloodTasks
	@make integration-tests-worker-restart
	@docker-compose -p $(PROJECT_ID) exec uwsgi coverage run -p --branch --source='.' manage.py test --liveserver=0.0.0.0:8080 --noinput realtime.tests.test_scenarios.TestAshTasks

integration-tests-with-logs: realtime-worker headless-worker integration-tests-worker
	@-{ make headless-worker-logs & make realtime-worker-logs & make integration-tests-worker-logs & docker-compose -p $(PROJECT_ID) exec uwsgi coverage run -p --branch --source='.' manage.py test --liveserver=0.0.0.0:8080 --noinput realtime.tests.test_scenarios.TestEarthquakeTasks; }
	@-make integration-tests-worker-restart
	@-{ make headless-worker-logs & make realtime-worker-logs & make integration-tests-worker-logs & docker-compose -p $(PROJECT_ID) exec uwsgi coverage run -p --branch --source='.' manage.py test --liveserver=0.0.0.0:8080 --noinput realtime.tests.test_scenarios.TestFloodTasks; }
	@-make integration-tests-worker-restart
	@-{ make headless-worker-logs & make realtime-worker-logs & make integration-tests-worker-logs & docker-compose -p $(PROJECT_ID) exec uwsgi coverage run -p --branch --source='.' manage.py test --liveserver=0.0.0.0:8080 --noinput realtime.tests.test_scenarios.TestAshTasks; }

retrieve-context-data:
	@docker run --rm -d --name analysis_context inasafe/analysis_context_image:v4.4.0 tail -f /dev/null
	@docker cp -a analysis_context:/data/. headless-data/contexts
{'fraction_non_alphanumeric': 0.3177570093457944, 'fraction_numerical': 0.011702559934985778, 'mean_word_length': 1.7456492637215528, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 14, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1634967', 'n_tokens_mistral': 3516, 'n_tokens_neox': 3302, 'n_words': 852}