generated from Code-Institute-Org/gitpod-full-template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
289 lines (240 loc) · 8.72 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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
APP := change
NAME := ${APP}
TAG := $$(git log -1 --pretty=%h) # eg 5d72e2b
SHA := $$(git log -1 --pretty=%H) # eg 5d72e2b158be269390d4b3931ed5d0febd784fb5
# sha-${TAG} is what's being built by the custom action
# docker/[email protected]
# in .github/workflows/main.yml
IMAGE := merkely/${APP}:sha-${TAG}
LATEST := merkely/${APP}:latest
CONTAINER := ${NAME}
MERKELY_HOST = https://app.merkely.com
MERKELYPIPE = Merkelypipe.json
# all non-latest images - for prune target
IMAGES := $(shell docker image ls --format '{{.Repository}}:{{.Tag}}' $(NAME) | grep -v latest)
ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
CI_ENV_FILE := ${ROOT_DIR}/.github/merkely.env
ifeq ($(CI),true)
# no tty on CI
DOCKER_RUN_TTY=
DOCKER_RUN_INTERACTIVE=
else
# colour on terminal needs tty
DOCKER_RUN_TTY=--tty
# pdb needs interactive
DOCKER_RUN_INTERACTIVE=--interactive
endif
# list the targets: from https://stackoverflow.com/questions/4219255/how-do-you-get-the-list-of-targets-in-a-makefile
.PHONY: list
list:
@$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | xargs
# list installed Python packages and their version numbers
pip_list:
@docker run --rm -it --entrypoint="" ${IMAGE} pip3 list
# - - - - - - - - - - - - - - - - - - - -
# full image rebuilds, with fresh base image, and no Docker caching
rebuild: delete_base_image
@docker build \
--file Dockerfile \
--no-cache \
--tag ${IMAGE} .
@docker tag ${IMAGE} ${LATEST}
delete_base_image:
$(eval BASE_IMAGE = $(shell cat "${PWD}/Dockerfile" | head -n 1 | awk '{print $$2}'))
@docker image rm ${BASE_IMAGE} 2> /dev/null || true
# - - - - - - - - - - - - - - - - - - - -
build:
@echo ${IMAGE}
@docker build \
--file Dockerfile \
--tag ${IMAGE} .
@docker tag ${IMAGE} ${LATEST}
# - - - - - - - - - - - - - - - - - - - -
# run tests without building, by volume-mounting
define SOURCE_VOLUME_MOUNTS
--volume ${ROOT_DIR}/source:/app/source
endef
define TESTS_VOLUME_MOUNT
--volume ${ROOT_DIR}/tests:/app/tests
endef
# Don't add build as a dependency to test_unit.
# If you do then .github/workflows/main.yml
# will create a new docker image, overwriting the previous
# one (which was pushed to dockerhub) thus losing the digest.
test_unit:
docker rm --force ${CONTAINER} 2> /dev/null || true
$(eval COVERAGE_DIR = tmp/coverage/unit)
rm -rf ${COVERAGE_DIR} && mkdir -p ${COVERAGE_DIR}
docker run \
--env TEST_ARG=${TEST_ARG} \
--name ${CONTAINER} \
${DOCKER_RUN_TTY} \
${DOCKER_RUN_INTERACTIVE} \
${SOURCE_VOLUME_MOUNTS} \
${TESTS_VOLUME_MOUNT} \
--volume ${ROOT_DIR}/${COVERAGE_DIR}/htmlcov:/app/htmlcov \
--entrypoint ./tests/unit/coverage_entrypoint.sh \
${IMAGE} tests/unit/${TARGET}
pytest_help:
@docker run \
--entrypoint="" \
--rm \
${IMAGE} \
python3 -m pytest --help
# - - - - - - - - - - - - - - - - - - - -
DOCS_IMAGE := merkely/docs
build_docs_image:
@docker build --tag ${DOCS_IMAGE} ${ROOT_DIR}/docs.merkely.com/
build_docs:
@docker run \
--rm \
-v ${ROOT_DIR}/docs.merkely.com:/docs \
-v ${ROOT_DIR}:/app \
-v ${ROOT_DIR}:/docs/source/app \
${DOCS_IMAGE} make clean html
@cp -RP ${ROOT_DIR}/docs.merkely.com/build/html/. docs/.
refresh_doc_ref_cache:
@docker run \
--entrypoint="" \
--rm \
-v ${ROOT_DIR}:/app \
${IMAGE} python /app/source/docs/doc_ref_cache.py
# - - - - - - - - - - - - - - - - - - - -
push:
@docker push ${IMAGE}
pull:
@docker pull ${IMAGE}
# Enter running container with a shell
enter:
@docker exec -ti ${CONTAINER} sh
# Follow the container logs
follow:
@docker container logs -f ${CONTAINER}
# Start a container with shell
shell:
@docker run -it --rm --name ${CONTAINER} ${IMAGE} sh
# Delete all the non-latest images
prune:
@docker image rm $(IMAGES)
# Get the repo statistics
stats:
@echo Commits: $$(git rev-list --count master)
@cloc .
# - - - - - - - - - - - - - - - - - - - -
# Merkely commands
merkely_declare_pipeline:
docker run \
--env MERKELY_COMMAND=declare_pipeline \
--env MERKELY_API_TOKEN=${MERKELY_API_TOKEN} \
--env MERKELY_HOST=${MERKELY_HOST} \
--env MERKELY_DRY_RUN=${MERKELY_DRY_RUN} \
--env-file ${CI_ENV_FILE} \
--rm \
--volume ${PWD}/${MERKELYPIPE}:/data/Merkelypipe.json \
${LATEST}
merkely_log_artifact:
docker run \
--env MERKELY_COMMAND=log_artifact \
--env MERKELY_FINGERPRINT=${MERKELY_FINGERPRINT} \
--env MERKELY_IS_COMPLIANT=${MERKELY_IS_COMPLIANT} \
--env MERKELY_ARTIFACT_GIT_COMMIT=${MERKELY_ARTIFACT_GIT_COMMIT} \
--env MERKELY_ARTIFACT_GIT_URL=${MERKELY_ARTIFACT_GIT_URL} \
--env MERKELY_CI_BUILD_NUMBER=${MERKELY_CI_BUILD_NUMBER} \
--env MERKELY_CI_BUILD_URL=${MERKELY_CI_BUILD_URL} \
--env MERKELY_API_TOKEN=${MERKELY_API_TOKEN} \
--env MERKELY_HOST=${MERKELY_HOST} \
--env MERKELY_DRY_RUN=${MERKELY_DRY_RUN} \
--env-file ${CI_ENV_FILE} \
--rm \
--volume=${PWD}:${PWD} \
--volume=/var/run/docker.sock:/var/run/docker.sock \
${LATEST}
merkely_log_evidence:
docker run \
--env MERKELY_COMMAND=log_evidence \
--env MERKELY_FINGERPRINT=${MERKELY_FINGERPRINT} \
--env MERKELY_EVIDENCE_TYPE=${MERKELY_EVIDENCE_TYPE} \
--env MERKELY_IS_COMPLIANT=${MERKELY_IS_COMPLIANT} \
--env MERKELY_DESCRIPTION="${MERKELY_DESCRIPTION}" \
--env MERKELY_CI_BUILD_URL=${MERKELY_CI_BUILD_URL} \
--env MERKELY_API_TOKEN=${MERKELY_API_TOKEN} \
--env MERKELY_HOST=${MERKELY_HOST} \
--env MERKELY_DRY_RUN=${MERKELY_DRY_RUN} \
--env-file ${CI_ENV_FILE} \
--rm \
--volume=/var/run/docker.sock:/var/run/docker.sock \
${IMAGE}
merkely_log_test:
docker run \
--env MERKELY_COMMAND=log_test \
--env MERKELY_FINGERPRINT=${MERKELY_FINGERPRINT} \
--env MERKELY_EVIDENCE_TYPE=${MERKELY_EVIDENCE_TYPE} \
--env MERKELY_CI_BUILD_URL=${MERKELY_CI_BUILD_URL} \
--env MERKELY_API_TOKEN=${MERKELY_API_TOKEN} \
--env MERKELY_HOST=${MERKELY_HOST} \
--env MERKELY_DRY_RUN=${MERKELY_DRY_RUN} \
--env-file ${CI_ENV_FILE} \
--rm \
--volume ${MERKELY_TEST_RESULTS_DIR}:/data/junit \
--volume /var/run/docker.sock:/var/run/docker.sock \
${IMAGE}
merkely_request_approval:
docker run \
--env MERKELY_COMMAND=request_approval \
--env MERKELY_FINGERPRINT="${MERKELY_FINGERPRINT}" \
--env MERKELY_OLDEST_SRC_COMMITISH="${MERKELY_OLDEST_SRC_COMMITISH}" \
--env MERKELY_NEWEST_SRC_COMMITISH="${MERKELY_NEWEST_SRC_COMMITISH}" \
--env MERKELY_DESCRIPTION="${MERKELY_DESCRIPTION}" \
--env MERKELY_SRC_REPO_ROOT="${MERKELY_SRC_REPO_ROOT}" \
--env MERKELY_USER_DATA="${MERKELY_USER_DATA}" \
--env MERKELY_API_TOKEN="${MERKELY_API_TOKEN}" \
--env MERKELY_HOST="${MERKELY_HOST}" \
--env MERKELY_DRY_RUN=${MERKELY_DRY_RUN} \
--env-file ${CI_ENV_FILE} \
--rm \
--volume ${PWD}:/src \
--volume /var/run/docker.sock:/var/run/docker.sock \
merkely/change
merkely_approve_deployment:
docker run \
--env MERKELY_COMMAND=approve_deployment \
--env MERKELY_FINGERPRINT="${MERKELY_FINGERPRINT}" \
--env MERKELY_OLDEST_SRC_COMMITISH="${MERKELY_OLDEST_SRC_COMMITISH}" \
--env MERKELY_NEWEST_SRC_COMMITISH="${MERKELY_NEWEST_SRC_COMMITISH}" \
--env MERKELY_DESCRIPTION="${MERKELY_DESCRIPTION}" \
--env MERKELY_SRC_REPO_ROOT="${MERKELY_SRC_REPO_ROOT}" \
--env MERKELY_USER_DATA="${MERKELY_USER_DATA}" \
--env MERKELY_API_TOKEN="${MERKELY_API_TOKEN}" \
--env MERKELY_HOST="${MERKELY_HOST}" \
--env MERKELY_DRY_RUN=${MERKELY_DRY_RUN} \
--env-file ${CI_ENV_FILE} \
--rm \
--volume ${PWD}:/src \
--volume /var/run/docker.sock:/var/run/docker.sock \
merkely/change
merkely_control_deployment:
docker run \
--env MERKELY_COMMAND=control_deployment \
--env MERKELY_FINGERPRINT=${MERKELY_FINGERPRINT} \
--env MERKELY_API_TOKEN=${MERKELY_API_TOKEN} \
--env MERKELY_HOST=${MERKELY_HOST} \
--env MERKELY_DRY_RUN=${MERKELY_DRY_RUN} \
--env-file ${CI_ENV_FILE} \
--rm \
--volume /var/run/docker.sock:/var/run/docker.sock \
merkely/change
merkely_log_deployment:
docker run \
--env MERKELY_COMMAND=log_deployment \
--env MERKELY_FINGERPRINT=${MERKELY_FINGERPRINT} \
--env MERKELY_CI_BUILD_URL=${MERKELY_CI_BUILD_URL} \
--env MERKELY_DESCRIPTION="${MERKELY_DESCRIPTION}" \
--env MERKELY_ENVIRONMENT=${MERKELY_ENVIRONMENT} \
--env MERKELY_USER_DATA=${MERKELY_USER_DATA} \
--env MERKELY_API_TOKEN=${MERKELY_API_TOKEN} \
--env MERKELY_HOST=${MERKELY_HOST} \
--env MERKELY_DRY_RUN=${MERKELY_DRY_RUN} \
--env-file ${CI_ENV_FILE} \
--rm \
--volume=/var/run/docker.sock:/var/run/docker.sock \
${IMAGE}