DEPLOY_HOST=halibut.cworth.org DEPLOY_DIR=/srv/halibut.cworth.org/turbot export DEPLOY_DIR DO_NOT_DEPLOY=env .gitignore DO_NOT_DELETE=.turbot.env help: @echo "Available targets (in rough order of expected use):" @echo @echo " make bootstrap Setup python virtual environment" @echo " make reqs Install dependencies into venv" @echo " make run Run a local server for testing" @echo " make deploy Deploy code to production" @echo .PHONY: require-venv require-venv: ifeq (, $(wildcard env)) $(error "No virtualenv found. Try 'make bootstrap'") endif ifndef VIRTUAL_ENV $(error "No virtualenv active. Try '. ./env/bin/activate'") endif .PHONY: bootstrap bootstrap: @echo "=== Creating python virtual environment ===" python3 -m virtualenv env @echo @echo "=== Installing pip-tools (to compile dependency list) ===" (. ./env/bin/activate && pip install pip-tools) @echo @echo "Virtual environment is now available." @echo "You must activate it by sourcing the activation script, such as:" @echo @echo " . ./env/bin/activate" @echo @echo "After that you can run 'make reqs' to install dependencies" .PHONY: reqs reqs: require-venv requirements.txt pip install --require-hashes --upgrade -r requirements.txt @echo @echo "Dependencies are now installed. You can now do 'make run' or 'make deploy'" requirements.txt: requirements.in ifeq (, $(shell which pip-compile)) $(error "No pip-compile found. Try 'make bootstrap'") endif pip-compile --no-index --generate-hashes --allow-unsafe run: require-venv FLASK_APP=turbot FLASK_DEBUG=true flask run turbot.wsgi: turbot.wsgi.in Makefile envsubst < turbot.wsgi.in > turbot.wsgi deploy: rm -rf .deploy-source git clone . .deploy-source rm -rf .deploy-source/.git make -C .deploy-source turbot.wsgi (cd .deploy-source; rsync -avz \ $(DO_NOT_DEPLOY:%=--exclude=%) \ --exclude=$(DO_NOT_DELETE) \ --delete \ --delete-after \ ./ $(DEPLOY_HOST):$(DEPLOY_DIR) ) rm -rf .deploy-source ssh $(DEPLOY_HOST) '(cd $(DEPLOY_DIR); make bootstrap; . env/bin/activate; make reqs)'