1 DEPLOY_HOST=halibut.cworth.org
2 DEPLOY_DIR=/srv/halibut.cworth.org/turbot
4 DO_NOT_DEPLOY=env .gitignore
5 DO_NOT_DELETE=.slack-creds.env .gsheets-creds.json .gsheets-token.pickle
8 @echo "Available targets (in rough order of expected use):"
10 @echo " make bootstrap Setup python virtual environment"
11 @echo " make reqs Install dependencies into venv"
12 @echo " make run Run a local server for testing"
13 @echo " make deploy Deploy code to production"
18 ifeq (, $(wildcard env))
19 $(error "No virtualenv found. Try 'make bootstrap'")
22 $(error "No virtualenv active. Try '. ./env/bin/activate'")
27 flake8 --exclude=env,.deploy*
31 @echo "=== Creating python virtual environment ==="
32 python3 -m virtualenv env
35 @echo "=== Installing pip-tools (to compile dependency list) ==="
36 (. ./env/bin/activate && pip install pip-tools)
39 @echo "Virtual environment is now available."
40 @echo "You must activate it by sourcing the activation script, such as:"
42 @echo " . ./env/bin/activate"
44 @echo "After that you can run 'make reqs' to install dependencies"
47 reqs: require-venv requirements.txt
48 pip install --require-hashes --upgrade -r requirements.txt
50 @echo "Dependencies are now installed. You can now do 'make run' or 'make deploy'"
52 requirements.txt: requirements.in
53 ifeq (, $(shell which pip-compile))
54 $(error "No pip-compile found. Try 'make bootstrap'")
56 pip-compile --no-index --generate-hashes --allow-unsafe
59 FLASK_APP=turbot.turbot FLASK_DEBUG=true flask run
61 turbot.wsgi: turbot.wsgi.in Makefile
62 envsubst < turbot.wsgi.in > turbot.wsgi
66 rm -rf .deploy-flask-source
67 git clone . .deploy-flask-source
68 rm -rf .deploy-flask-source/.git
69 make -C .deploy-flask-source turbot.wsgi
70 (cd .deploy-flask-source; rsync -avz \
71 $(DO_NOT_DEPLOY:%=--exclude=%) \
72 $(patsubst %,--exclude %,$(DO_NOT_DELETE)) \
75 ./ $(DEPLOY_HOST):$(DEPLOY_DIR) )
76 rm -rf .deploy-flask-source
77 ssh $(DEPLOY_HOST) '(cd $(DEPLOY_DIR); make bootstrap; . env/bin/activate; make reqs)'
81 rm -rf .deploy-lambda-source
82 git clone . .deploy-lambda-source
83 make -C .deploy-lambda-source flake
84 make -C .deploy-lambda-source bootstrap
85 (cd .deploy-lambda-source; . env/bin/activate; make reqs)
86 (cd .deploy-lambda-source/env/lib/python*/site-packages; zip -r ../../../../turbot.zip .)
87 (cd .deploy-lambda-source/turbot_lambda; zip ../turbot.zip turbot_lambda.py)
88 (cd .deploy-lambda-source; zip turbot.zip $$(git ls-files -- turbot))
89 (cd .deploy-lambda-source; \
90 aws lambda update-function-code \
92 --function-name turbot \
93 --zip-file fileb://turbot.zip )
94 rm -rf .deploy-lambda-source