-
Notifications
You must be signed in to change notification settings - Fork 26
/
Makefile
165 lines (139 loc) · 3.97 KB
/
Makefile
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
.PHONY: all environment lint start
OS ?= $(shell python -c 'import platform; print(platform.system())')
IMAGE_NAME = electionguard_web_api
AZURE_LOCATION = eastus
RESOURCE_GROUP = EG-Deploy-Demo
DEPLOY_REGISTRY = deploydemoregistry
REGISTRY_SKU = Basic
ACI_CONTEXT = egacicontext
TENANT_ID = xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
GROUP_EXISTS ?= $(shell az group exists --name $(RESOURCE_GROUP))
# Supports either "guardian" or "mediator" modes
API_MODE ?= mediator
ifeq ($(API_MODE), mediator)
PORT ?= 8000
else
PORT ?= 8001
endif
all: environment lint start
environment: no-windows
@echo 🔧 SETUP
make install-gmp
pip3 install 'poetry==1.1.6'
poetry config virtualenvs.in-project true
poetry install
install: no-windows
@echo 🔧 INSTALL
poetry install
install-gmp: no-windows
@echo 📦 Install Module
@echo Operating System identified as $(OS)
ifeq ($(OS), Linux)
make install-gmp-linux
endif
ifeq ($(OS), Darwin)
make install-gmp-mac
endif
install-gmp-mac: no-windows
@echo 🍎 MACOS INSTALL
# gmpy2 requirements
brew install gmp || true
brew install mpfr || true
brew install libmpc || true
install-gmp-linux: no-windows
@echo 🐧 LINUX INSTALL
# gmpy2 requirements
sudo apt-get install libgmp-dev
sudo apt-get install libmpfr-dev
sudo apt-get install libmpc-dev
# install azure command line
install-azure-cli:
@echo Install Azure CLI
ifeq ($(OS), Linux)
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
endif
ifeq ($(OS), Darwin)
brew install azure-cli
az upgrade
endif
ifeq ($(OS), Windows)
Invoke-WebRequest -Uri https://aka.ms/installazurecliwindows -OutFile .\AzureCLI.msi; Start-Process msiexec.exe -Wait -ArgumentList '/I AzureCLI.msi /quiet'; rm .\AzureCLI.msi
endif
# deploy to azure
deploy-azure:
@echo Deploy to Azure
az login --tenant $(TENANT_ID)
ifeq ($(GROUP_EXISTS), false)
az group create -l $(AZURE_LOCATION) -n $(RESOURCE_GROUP)
endif
az acr create --resource-group $(RESOURCE_GROUP) --name $(DEPLOY_REGISTRY) --sku $(REGISTRY_SKU)
az acr login --name $(DEPLOY_REGISTRY)
docker context use default
docker build . -t $(DEPLOY_REGISTRY).azurecr.io/electionguard-api-python:latest
docker push $(DEPLOY_REGISTRY).azurecr.io/electionguard-api-python:latest
docker login azure --tenant-id $(TENANT_ID)
# docker context create aci $(ACI_CONTEXT)
docker context use $(ACI_CONTEXT)
docker compose -f docker-compose.azure.yml up
docker logout
docker context use default
az logout
# Dev Server
start: no-windows
poetry run uvicorn app.main:app --reload --port $(PORT)
start-server:
docker compose -f docker-compose.support.yml up -d
QUEUE_MODE=remote
STORAGE_MODE=mongo
poetry run uvicorn app.main:app --reload --port $(PORT)
stop:
docker compose -f docker-compose.support.yml down
# Docker
docker-build:
docker build -t $(IMAGE_NAME) .
docker-run:
docker-compose up --build
docker-dev:
docker-compose -f docker-compose.support.yml -f docker-compose.dev.yml up --build
docker-postman-test:
@echo 🧪 RUNNING POSTMAN TESTS IN DOCKER
docker-compose \
-f tests/postman/docker-compose.yml up \
--build \
--abort-on-container-exit \
--exit-code-from test-runner
# Linting
lint:
@echo 💚 LINT
@echo 1.Pylint
poetry run pylint --extension-pkg-whitelist=pydantic app tests
@echo 2.Black Formatting
poetry run black --diff --check app tests
@echo 3.Mypy Static Typing
poetry run mypy --config-file=pyproject.toml app tests
@echo 4.Documentation
poetry run mkdocs build --strict
auto-lint:
poetry run black app tests
make lint
test-integration: no-windows
@echo ✅ INTEGRATION TESTS
poetry run pytest -s . -x
# Documentation
docs-serve:
poetry run mkdocs serve
docs-build:
poetry run mkdocs build
docs-deploy:
@echo 🚀 DEPLOY to Github Pages
poetry run mkdocs gh-deploy --force
docs-deploy-ci:
@echo 🚀 DEPLOY to Github Pages
pip install mkdocs
mkdocs gh-deploy --force
# PRIVATE RECIPIES
no-windows:
ifeq ($(OS), Windows_NT)
@echo Windows is not supported. Instead run this command in WSL2. For more details see README.md.
exit 1
endif