-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
140 lines (115 loc) · 4.62 KB
/
Makefile
File metadata and controls
140 lines (115 loc) · 4.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
.PHONY: help prepare doc test serve build publish-production deploy-production promote-production production cloudbuild-production
.DEFAULT_GOAL := help
SHELL:=/bin/bash
ifndef version
override version = development
endif
ifndef region
override region = europe-north1
endif
ifndef project
override project = delta-entity-401706
endif
# Add help text after each target name starting with '\#\#'
help: ## show this help
@echo -e "Help for this makefile\n"
@echo "Possible commands are:"
@grep -h "##" $(MAKEFILE_LIST) | grep -v grep | sed -e 's/\(.*\):.*##\(.*\)/ \1: \2/'
prepare: ## Install dependencies and pre-commit hook
pip install -e ".[dev]"
pre-commit install
gcloud init
gcloud auth configure-docker europe-north1-docker.pkg.dev
# Doc and tests
clean-doc:
rm -rf docs/html docs/jupyter_execute
doc: clean-doc ## Build Sphinx documentation
sphinx-build -b html docs docs/html;open docs/html/index.html
test: ## Run tests with coverage
pytest --cov simdec --cov-report term-missing
# Dashboard commands
serve-dev: ## Serve Panel dashboard - Dev mode
panel serve panel/simdec_app.py panel/sampling.py \
--index panel/index.html \
--show --autoreload \
--static-dirs _static=docs/_static \
--reuse-sessions --warm
serve-oauth: ## Serve Panel dashboard - Prod mode with OAuth2. Needs: PANEL_OAUTH_REDIRECT_URI, PANEL_OAUTH_KEY, PANEL_OAUTH_SECRET, PANEL_OAUTH_ENCRYPTION
panel serve panel/simdec_app.py panel/sampling.py \
--index panel/index.html \
--show \
--cookie-secret panel_cookie_secret_oauth \
--basic-login-template panel/login.html \
--logout-template panel/logout.html \
--oauth-provider custom_google \
--login-endpoint app \
--static-dirs _static=docs/_static \
--reuse-sessions --warm
# Deployment commands
# --progress=plain
build-local: ## Build for local architecture
docker build -f ./panel/Dockerfile \
--tag simdec-panel-local:$(version) \
--pull \
./.
run-local: build-local
docker run --rm -it \
--name=simdec-panel-local \
--memory=1g \
--cpuset-cpus=0 \
-e ENV=development \
-e PANEL_OAUTH_REDIRECT_URI=$(PANEL_OAUTH_REDIRECT_URI) \
-e PANEL_OAUTH_SECRET=$(PANEL_OAUTH_SECRET) \
-e PANEL_OAUTH_KEY=$(PANEL_OAUTH_KEY) \
-e PANEL_OAUTH_ENCRYPTION=$(PANEL_OAUTH_ENCRYPTION) \
-p "5006:8080" \
simdec-panel-local:$(version)
# Need to specifically build on linux/amd64 to avoid issues on macOS M platform
build: ## Build for linux/amd64 (production)
docker build -f ./panel/Dockerfile \
--platform linux/amd64 \
--tag simdec-panel:$(version) \
--pull \
./.
run: build
docker run --rm -it \
--name=simdec-panel \
--memory=1g \
--cpuset-cpus=0 \
-e ENV=development \
-e PANEL_OAUTH_REDIRECT_URI=$(PANEL_OAUTH_REDIRECT_URI) \
-e PANEL_OAUTH_SECRET=$(PANEL_OAUTH_SECRET) \
-e PANEL_OAUTH_KEY=$(PANEL_OAUTH_KEY) \
-e PANEL_OAUTH_ENCRYPTION=$(PANEL_OAUTH_ENCRYPTION) \
-p "5006:8080" \
simdec-panel:$(version)
# Ship
publish-production: build ## Tag and push to GCP
docker tag simdec-panel:$(version) $(region)-docker.pkg.dev/$(project)/simdec-panel/simdec-panel:$(version)
docker push $(region)-docker.pkg.dev/$(project)/simdec-panel/simdec-panel:$(version)
deploy-production: publish-production ## Deploy new revision to GCP
@echo "Deploying '$(version)'."
gcloud run deploy simdec-panel \
--cpu=2 \
--concurrency=5 \
--min-instances=0 \
--max-instances=2 \
--region=$(region) \
--port=8080 \
--set-env-vars ENV=production \
--set-secrets=PANEL_OAUTH_REDIRECT_URI=PANEL_OAUTH_REDIRECT_URI:latest \
--set-secrets=PANEL_OAUTH_KEY=PANEL_OAUTH_KEY:latest \
--set-secrets=PANEL_OAUTH_SECRET=PANEL_OAUTH_SECRET:latest \
--set-secrets=PANEL_OAUTH_ENCRYPTION=PANEL_OAUTH_ENCRYPTION:latest \
--allow-unauthenticated \
--session-affinity \
--timeout=60m \
--service-account simdec-panel@delta-entity-401706.iam.gserviceaccount.com \
--image=$(region)-docker.pkg.dev/$(project)/simdec-panel/simdec-panel:$(version) \
--memory 2Gi \
--no-traffic
promote-production: ## Serve new revision to GCP
gcloud run services update-traffic simdec-panel --to-latest
production: promote-production ## Build, Deploy and Serve new revision to GCP
cloudbuild-production: ## Build, Deploy and Serve new revision to GCP using cloudbuild
gcloud builds submit --config panel/cloudbuild.yaml --substitutions COMMIT_SHA=$(git rev-list --max-count=1 HEAD) .