DEPLOY_HOST=halibut.cworth.org DEPLOY_DIR=/srv/halibut.cworth.org/turbot export DEPLOY_DIR DO_NOT_DEPLOY=env .gitignore DO_NOT_DELETE=.slack-creds.env .gsheets-creds.json .gsheets-token.pickle 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.turbot FLASK_DEBUG=true flask run turbot.wsgi: turbot.wsgi.in Makefile envsubst < turbot.wsgi.in > turbot.wsgi .PHONY: deploy-flask deploy-flask: rm -rf .deploy-flask-source git clone . .deploy-flask-source rm -rf .deploy-flask-source/.git make -C .deploy-flask-source turbot.wsgi (cd .deploy-flask-source; rsync -avz \ $(DO_NOT_DEPLOY:%=--exclude=%) \ $(patsubst %,--exclude %,$(DO_NOT_DELETE)) \ --delete \ --delete-after \ ./ $(DEPLOY_HOST):$(DEPLOY_DIR) ) rm -rf .deploy-flask-source ssh $(DEPLOY_HOST) '(cd $(DEPLOY_DIR); make bootstrap; . env/bin/activate; make reqs)' .PHONY: deploy-lambda deploy-lambda: rm -rf .deploy-lambda-source git clone . .deploy-lambda-source make -C .deploy-lambda-source bootstrap (cd .deploy-lambda-source; . env/bin/activate; make reqs) (cd .deploy-lambda-source/env/lib/python*/site-packages; zip -r ../../../../turbot.zip .) (cd .deploy-lambda-source/turbot_lambda; zip ../turbot.zip turbot_lambda.py) (cd .deploy-lambda-source; zip turbot.zip $$(git ls-files -- turbot)) (cd .deploy-lambda-source; \ aws lambda update-function-code \ --profile halibut \ --function-name turbot \ --zip-file fileb://turbot.zip ) rm -rf .deploy-lambda-source .PHONY: deploy deploy: deploy-lambda