This repository has been archived by the owner on May 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Makefile
200 lines (167 loc) · 5.8 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
.PHONY: lint test clean clean-dist update-deps list-outdated-deps dist \
build-docker build-python3-docker build-pypy-docker push-docker \
push-python3-docker push-pypy-docker push-latest-docker \
deployment-test release-test
TESTFILES := $(wildcard test/test_*.py)
TESTS := $(subst test/,,$(subst .py,,${TESTFILES}))
CODEFILES := $(wildcard orm/*.py *.py)
LINTFILES := $(patsubst %.py,lint_%,${CODEFILES})
ACTIVATE_VENV := @. env/bin/activate &&
ORM_TAG := $(shell git describe --tags)
DOCKER ?= docker
DOCKER_IMAGE_BASE_NAME ?= svtwebcoreinfra/orm
PYPI_PACKAGE_NAME = origin-routing-machine
ifdef CI
ENV_PREP_COMMAND = true
env: requirements.txt
@echo "CI detected!"
make env-install
else
ENV_PREP_COMMAND = . env/bin/activate
PYTHON ?= python3
env: requirements.txt
@echo "This is a local build, I will use virtualenv"
virtualenv -p ${PYTHON} env
. env/bin/activate && make env-install
endif
env-install: requirements.txt
python --version && pip --version
pip install -r build_requirements.txt
pip-sync build_requirements.txt requirements.txt
touch env
ifndef CI
update-deps:
virtualenv -p ${PYTHON} update_deps
@. update_deps/bin/activate && \
export CUSTOM_COMPILE_COMMAND="make $@" && \
pip install 'pip-tools>=2.0,<3' && \
pip-compile --upgrade --output-file requirements.txt setup.py && \
pip-compile --upgrade --output-file build_requirements.txt build_requirements.in
rm -rf update_deps
endif
list-outdated-deps: env
$(ENV_PREP_COMMAND) && \
pip list --outdated
lint: env
$(ENV_PREP_COMMAND) && \
echo 'lint code' && pylint ${CODEFILES} && \
echo 'lint tests' && pylint --disable=similarities ${TESTFILES}
formatting:
$(ENV_PREP_COMMAND) && pip install black
@echo 'check formatting'
black --check orm || (echo "Run 'make black' to run the formatter"; exit 1)
black:
$(ENV_PREP_COMMAND) && pip install black
$(ENV_PREP_COMMAND) && black orm
${LINTFILES}:
$(ENV_PREP_COMMAND) && \
pylint $(subst lint_,,$@).py
test: env ${TESTS}
${TESTS}:
@echo "Test: $@"
$(ENV_PREP_COMMAND) && \
PYTHONPATH=. python test/$@.py
dist: clean-dist env
$(ENV_PREP_COMMAND) && \
ORM_TAG=${ORM_TAG} python setup.py sdist
clean-deployment-test:
rm -f orm-rules-tests/globals-test/cache.pkl
rm -f orm-rules-tests/rules-test/cache.pkl
clean-dist:
rm -rf dist *.egg-info
clean: clean-dist clean-deployment-test
rm -rf env
rm -rf out
rm -rf orm/__pycache__
@echo "all clean. here we go."
build-docker: build-python3-docker build-pypy-docker
build-python3-docker: clean-dist
${DOCKER} build \
--build-arg ORM_TAG=${ORM_TAG} \
-t ${DOCKER_IMAGE_BASE_NAME}:${ORM_TAG}-python3 \
-f .docker/Dockerfile-python3 .
# Build the pypy image and tag it with latest and the ORM_TAG.
# This enables pypy to be the default docker image
build-pypy-docker: clean-dist
ifeq (,$(findstring -,$(ORM_TAG)))
@echo "Building and tagging with latest."
${DOCKER} build \
--build-arg ORM_TAG=${ORM_TAG} \
-t ${DOCKER_IMAGE_BASE_NAME}:${ORM_TAG}-pypy \
-t ${DOCKER_IMAGE_BASE_NAME}:${ORM_TAG} \
-t ${DOCKER_IMAGE_BASE_NAME}:latest \
-f .docker/Dockerfile-pypy .
else
@echo "Not tagging latest for pre-release versions"
${DOCKER} build \
--build-arg ORM_TAG=${ORM_TAG} \
-t ${DOCKER_IMAGE_BASE_NAME}:${ORM_TAG}-pypy \
-t ${DOCKER_IMAGE_BASE_NAME}:${ORM_TAG} \
-f .docker/Dockerfile-pypy .
endif
push-docker: push-python3-docker push-pypy-docker push-latest-docker
${DOCKER} push "${DOCKER_IMAGE_BASE_NAME}:${ORM_TAG}"
push-python3-docker: build-python3-docker
${DOCKER} push "${DOCKER_IMAGE_BASE_NAME}:${ORM_TAG}-python3"
push-pypy-docker: build-pypy-docker
${DOCKER} push "${DOCKER_IMAGE_BASE_NAME}:${ORM_TAG}-pypy"
# Only push the latest tag for non pre-release versions
# NOTICE: The following will only match "-" as part of the tag.
push-latest-docker: build-pypy-docker
ifeq (,$(findstring -,$(ORM_TAG)))
@echo "Pushing latest tag to the hub"
${DOCKER} push "${DOCKER_IMAGE_BASE_NAME}:latest"
else
@echo "Not pushing latest for pre-release versions"
endif
dist/orm-%.tar.gz: orm
make dist
build-orm-deployment:
make -C lxd
lxd/dist/orm-image.tar.gz:
mkdir lxd/dist
make build-orm-deployment
start-orm-deployment: lxd/dist/orm-image.tar.gz
lxc image show orm >/dev/null 2>&1 || lxc image import lxd/dist/orm-image.tar.gz --alias orm
lxc info orm >/dev/null 2>&1 || lxc launch orm orm
(lxc info orm | grep -q 'Status: Running') || lxc start orm
deployment-test: env dist/orm-${ORM_TAG}.tar.gz start-orm-deployment
$(ENV_PREP_COMMAND) && \
pip install dist/${PYPI_PACKAGE_NAME}-${ORM_TAG}.tar.gz
@echo "Linting deployment test rules"
$(ENV_PREP_COMMAND) && \
yamllint -c orm-rules-tests/.yamllint orm-rules-tests/
@echo "Testing rules without globals actions"
mkdir -p out/rules-test
orm-rules-tests/start_echo_servers.sh
$(ENV_PREP_COMMAND) && \
orm \
-r 'orm-rules-tests/rules-test/rules/**/*.yml' \
-G 'orm-rules-tests/rules-test/globals.yml' \
--cache-path 'orm-rules-tests/rules-test/cache.pkl' \
-o out/rules-test
lxd/update-orm-config.sh out/rules-test
orm-rules-tests/wait_for_orm.sh
$(ENV_PREP_COMMAND) && \
lxd/test-orm-config.sh 'orm-rules-tests/rules-test/rules/**/*.yml' && \
lxc file push orm-rules-tests/test-maxconn-maxqueue-haproxy-output.sh orm/root/ && \
lxc exec orm /root/test-maxconn-maxqueue-haproxy-output.sh
@echo "Testing rules with globals actions"
mkdir -p out/globals-test
orm-rules-tests/start_echo_servers.sh
$(ENV_PREP_COMMAND) && \
orm \
-r 'orm-rules-tests/globals-test/rules/**/*.yml' \
-G 'orm-rules-tests/globals-test/globals.yml' \
--cache-path 'orm-rules-tests/globals-test/cache.pkl' \
-o out/globals-test
lxd/update-orm-config.sh out/globals-test
orm-rules-tests/wait_for_orm.sh
$(ENV_PREP_COMMAND) && \
lxd/test-orm-config.sh 'orm-rules-tests/globals-test/rules/**/*.yml'
release-test:
make clean
make lint
make black
make test
make deployment-test