]> git.cworth.org Git - turbot/blob - Makefile
Allow tag values to have numbers
[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: flake
26 flake:
27         flake8 --exclude=env,.deploy*
28
29 .PHONY: bootstrap
30 bootstrap:
31         @echo "=== Creating python virtual environment ==="
32         python3 -m virtualenv env
33
34         @echo
35         @echo "=== Installing pip-tools (to compile dependency list) ==="
36         (. ./env/bin/activate && pip install pip-tools)
37
38         @echo
39         @echo "Virtual environment is now available."
40         @echo "You must activate it by sourcing the activation script, such as:"
41         @echo
42         @echo " . ./env/bin/activate"
43         @echo
44         @echo "After that you can run 'make reqs' to install dependencies"
45
46 .PHONY: reqs
47 reqs: require-venv requirements.txt
48         pip install --require-hashes --upgrade -r requirements.txt
49         @echo
50         @echo "Dependencies are now installed. You can now do 'make run' or 'make deploy'"
51
52 requirements.txt: requirements.in
53 ifeq (, $(shell which pip-compile))
54         $(error "No pip-compile found. Try 'make bootstrap'")
55 endif
56         pip-compile --no-index --generate-hashes --allow-unsafe
57
58 run: require-venv
59         FLASK_APP=turbot.turbot FLASK_DEBUG=true flask run
60
61 turbot.wsgi: turbot.wsgi.in Makefile
62         envsubst < turbot.wsgi.in > turbot.wsgi
63
64 .PHONY: deploy-flask
65 deploy-flask:
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)) \
73                 --delete \
74                 --delete-after \
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)'
78
79 .PHONY: deploy-lambda
80 deploy-lambda:
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 \
91                 --profile halibut \
92                 --function-name turbot \
93                 --zip-file fileb://turbot.zip )
94         rm -rf .deploy-lambda-source
95
96 .PHONY: deploy
97 deploy: deploy-lambda