]> git.cworth.org Git - turbot/blob - Makefile
Move top-level flask app from turbot/turbot.py to turbot_flask/turbot.py
[turbot] / Makefile
1 DEPLOY_HOST=halibut.cworth.org
2 DEPLOY_DIR=/srv/halibut.cworth.org/turbot
3 export DEPLOY_DIR
4 DO_NOT_DEPLOY=env .gitignore
5 DO_NOT_DELETE=.slack-creds.env .gsheets-creds.json .gsheets-token.pickle
6
7 help:
8         @echo "Available targets (in rough order of expected use):"
9         @echo
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"
14         @echo
15
16 .PHONY: require-venv
17 require-venv:
18 ifeq (, $(wildcard env))
19         $(error "No virtualenv found. Try 'make bootstrap'")
20 endif
21 ifndef VIRTUAL_ENV
22         $(error "No virtualenv active. Try '. ./env/bin/activate'")
23 endif
24
25 .PHONY: bootstrap
26 bootstrap:
27         @echo "=== Creating python virtual environment ==="
28         python3 -m virtualenv env
29
30         @echo
31         @echo "=== Installing pip-tools (to compile dependency list) ==="
32         (. ./env/bin/activate && pip install pip-tools)
33
34         @echo
35         @echo "Virtual environment is now available."
36         @echo "You must activate it by sourcing the activation script, such as:"
37         @echo
38         @echo " . ./env/bin/activate"
39         @echo
40         @echo "After that you can run 'make reqs' to install dependencies"
41
42 .PHONY: reqs
43 reqs: require-venv requirements.txt
44         pip install --require-hashes --upgrade -r requirements.txt
45         @echo
46         @echo "Dependencies are now installed. You can now do 'make run' or 'make deploy'"
47
48 requirements.txt: requirements.in
49 ifeq (, $(shell which pip-compile))
50         $(error "No pip-compile found. Try 'make bootstrap'")
51 endif
52         pip-compile --no-index --generate-hashes --allow-unsafe
53
54 run: require-venv
55         FLASK_APP=turbot.turbot FLASK_DEBUG=true flask run
56
57 turbot.wsgi: turbot.wsgi.in Makefile
58         envsubst < turbot.wsgi.in > turbot.wsgi
59
60 .PHONY: deploy-flask
61 deploy-flask:
62         rm -rf .deploy-flask-source
63         git clone . .deploy-flask-source
64         rm -rf .deploy-flask-source/.git
65         make -C .deploy-flask-source turbot.wsgi
66         (cd .deploy-flask-source; rsync -avz \
67                 $(DO_NOT_DEPLOY:%=--exclude=%) \
68                 $(patsubst %,--exclude %,$(DO_NOT_DELETE)) \
69                 --delete \
70                 --delete-after \
71                 ./ $(DEPLOY_HOST):$(DEPLOY_DIR) )
72         rm -rf .deploy-flask-source
73         ssh $(DEPLOY_HOST) '(cd $(DEPLOY_DIR); make bootstrap; . env/bin/activate; make reqs)'
74
75 .PHONY: deploy-lambda
76 deploy-lambda:
77         rm -rf .deploy-lambda-source
78         git clone . .deploy-lambda-source
79         rm -rf .deploy-lambda-source/.git
80         (cd .deploy-lambda-source/turbot_lambda; zip ../turbot.zip lambda_function.py)
81         (cd .deploy-lambda-source; \
82                 aws lambda update-function-code \
83                 --profile halibut \
84                 --function-name turbot \
85                 --zip-file fileb://turbot.zip )
86         rm -rf .deploy-lambda-source
87
88 .PHONY: deploy
89 deploy: deploy-flask deploy-lambda