generated from NHSDigital/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
96 lines (75 loc) · 4.03 KB
/
Makefile
File metadata and controls
96 lines (75 loc) · 4.03 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
# This file is for you! Edit it to implement your own hooks (make targets) into
# the project as automated steps to be executed on locally and in the CD pipeline.
include scripts/init.mk
# Within the build container the `doas` command is required when running docker commands as we're running as a non-root user.
ifeq (${IN_BUILD_CONTAINER}, true)
docker := doas docker
else
docker := docker
endif
dockerNetwork := pathology-local
# ==============================================================================
# Example CI/CD targets are: dependencies, build, publish, deploy, clean, etc.
.PHONY: dependencies
dependencies: # Install dependencies needed to build and test the project @Pipeline
cd pathology-api && poetry sync
.PHONY: build
build: clean-artifacts dependencies
@cd pathology-api
@echo "Running type checks..."
@rm -rf target && rm -rf dist
@poetry run mypy --no-namespace-packages .
@echo "Packaging dependencies..."
@poetry build --format=wheel
VERSION=$$(poetry version -s)
@pip install "dist/pathology_api-$$VERSION-py3-none-any.whl" --target "./target/pathology-api" --platform manylinux2014_x86_64 --only-binary=:all:
# Copy lambda_handler file separately as it is not included within the package.
@cp lambda_handler.py ./target/pathology-api/
@cd ./target/pathology-api
@zip -r "../artifact.zip" .
.PHONY: build-images
build-images: build # Build the project artefact @Pipeline
@mkdir -p infrastructure/images/pathology-api/resources/build
@cp -r pathology-api/target/pathology-api infrastructure/images/pathology-api/resources/build
@echo "Building Docker image using Docker. Utilising python version: ${PYTHON_VERSION} ..."
@$(docker) buildx build --load --platform=linux/amd64 --provenance=false --build-arg PYTHON_VERSION=${PYTHON_VERSION} -t localhost/pathology-api-image infrastructure/images/pathology-api
@echo "Docker image 'pathology-api-image' built successfully!"
@echo "Building api-gateway-mock using Docker. Utilising python version: ${PYTHON_VERSION} ..."
@$(docker) buildx build --load --build-arg PYTHON_VERSION=${PYTHON_VERSION} -t localhost/api-gateway-mock-image infrastructure/images/api-gateway-mock
@echo "Docker image 'api-gateway-mock-image' built successfully!"
publish: # Publish the project artefact @Pipeline
# TODO: Implement the artefact publishing step
deploy: clean-docker build-images # Deploy the project artefact to the target environment @Pipeline
$(docker) network create $(dockerNetwork) || echo "Docker network '$(dockerNetwork)' already exists."
$(docker) run --platform linux/amd64 --name pathology-api -p 5001:8080 --network $(dockerNetwork) -d localhost/pathology-api-image
$(docker) run --name api-gateway-mock -p 5002:5000 --network $(dockerNetwork) -d localhost/api-gateway-mock-image
clean-artifacts:
@echo "Removing build artefacts..."
@rm -rf infrastructure/images/pathology-api/resources/build/
@rm -rf pathology-api/target && rm -rf pathology-api/dist
clean-docker: stop
@echo "Removing pathology API container..."
@$(docker) rm pathology-api || echo "No pathology API container currently exists."
@echo "Removing api-gateway-mock container..."
@$(docker) rm api-gateway-mock || echo "No api-gateway-mock container currently exists."
clean:: clean-artifacts clean-docker # Clean-up project resources (main) @Operations
.PHONY: stop
stop:
@echo "Stopping pathology API container..."
@$(docker) stop pathology-api || echo "No pathology API container currently running."
@echo "Stopping api-gateway-mock container..."
@$(docker) stop api-gateway-mock || echo "No api-gateway-mock container currently running."
config:: # Configure development environment (main) @Configuration
# Configure poetry to trust dev certificate if specified
@if [[ -n "$${DEV_CERTS_INCLUDED}" ]]; then \
echo "Configuring poetry to trust the dev certificate..." ; \
poetry config certificates.PyPI.cert /etc/ssl/cert.pem ; \
fi
make _install-dependencies
# ==============================================================================
${VERBOSE}.SILENT: \
build \
clean \
config \
dependencies \
deploy \