-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
179 lines (128 loc) · 5.24 KB
/
Copy pathMakefile
File metadata and controls
179 lines (128 loc) · 5.24 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
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
SHELL = /bin/bash
.DEFAULT_GOAL := help
SERVICE_NAME := service-print-renderer
CURRENT_DIR := $(shell pwd)
# Docker metadata
GIT_HASH := $(shell git rev-parse HEAD)
GIT_HASH_SHORT := $(shell git rev-parse --short HEAD)
GIT_BRANCH := $(shell git symbolic-ref HEAD --short 2>/dev/null)
GIT_DIRTY := $(shell git status --porcelain)
GIT_TAG := $(shell git describe --tags || echo "no version info")
AUTHOR := $(USER)
# App source dir
APP_SRC_DIR := app
# Commands
UV_RUN := uv run
PYTHON := $(UV_RUN) python3
TEST := $(UV_RUN) pytest
RUFF := $(UV_RUN) ruff
TY := $(UV_RUN) ty
# Docker variables
DOCKER_REGISTRY = 074597099015.dkr.ecr.eu-central-1.amazonaws.com
DOCKER_IMG_LOCAL_TAG := $(DOCKER_REGISTRY)/swissgeo/$(SERVICE_NAME):local-$(USER)-$(GIT_HASH_SHORT)
# AWS variables
AWS_REGION = eu-central-1
# Env file for dockerrun, defaults to .env.local / .env
ENV_FILE ?= $(if $(wildcard .env.local),.env.local,.env)
# include the env file
-include $(ENV_FILE)
# export the env file so that uv picks it up in all recipes below
export UV_ENV_FILE := $(ENV_FILE)
# Logging
LOGS_DIR = $(PWD)/logs
.env:
cp .env.default .env
.PHONY: git-info
git-info:
@echo "GIT_HASH=$(GIT_HASH)"
@echo "GIT_HASH_SHORT=$(GIT_HASH_SHORT)"
@echo "GIT_BRANCH=$(GIT_BRANCH)"
@echo "GIT_DIRTY=$(GIT_DIRTY)"
@echo "GIT_TAG=$(GIT_TAG)"
@echo "AUTHOR=$(AUTHOR)"
@echo "DOCKER_IMG_LOCAL_TAG=$(DOCKER_IMG_LOCAL_TAG)"
.PHONY: ci
ci: .env
# Create virtual env with all packages for development using the lock file
uv sync --frozen
.PHONY: setup
setup: .env $(LOGS_DIR) ## Create virtualenv with all packages for development
uv sync
# Start a new shell with the virtualenv activated and the .env file loaded into the environment
uv run $$SHELL
.PHONY: format
format: ## Call ruff format to make sure your code is easier to read and respects some conventions.
$(RUFF) format
$(RUFF) check --select I --fix
.PHONY: ci-check-format
ci-check-format: format ## Check the format (CI)
@if [[ -n `git status --porcelain --untracked-files=no` ]]; then \
>&2 echo "ERROR: the following files are not formatted correctly"; \
>&2 echo "'git status --porcelain' reported changes in those files after a 'make format' :"; \
>&2 git status --porcelain --untracked-files=no; \
exit 1; \
fi
.PHONY: run
run: ## Run the worker locally
ENV_FILE=.env $(UV_RUN) python -m app.worker
.PHONY: renderer-info
renderer-info: ## Print GPU/WebGL renderer info and exit
ENV_FILE=.env $(UV_RUN) python -m app.worker --renderer-info
.PHONY: docker-renderer-info
docker-renderer-info: ## Print GPU/WebGL renderer info from inside Docker
docker compose --env-file=${ENV_FILE} --profile renderer-info run --rm renderer-info
.PHONY: dockerlogin
dockerlogin: ## Login to the AWS Docker Registry (ECR)
aws --profile swisstopo-swissgeo-builder ecr get-login-password --region $(AWS_REGION) | docker login --username AWS --password-stdin $(DOCKER_REGISTRY)
.PHONY: dockerbuild
dockerbuild: $(LOGS_DIR) ## Create a docker image
docker build --no-cache \
--build-arg GIT_HASH="$(GIT_HASH)" \
--build-arg GIT_BRANCH="$(GIT_BRANCH)" \
--build-arg GIT_DIRTY="$(GIT_DIRTY)" \
--build-arg VERSION="$(GIT_TAG)" \
--build-arg AUTHOR="$(AUTHOR)" -t $(DOCKER_IMG_LOCAL_TAG) .
.PHONY: dockerpush
dockerpush: dockerbuild ## Push to the docker registry
docker push $(DOCKER_IMG_LOCAL_TAG)
.PHONY: dockerrun
dockerrun: start-moto dockerbuild ## Run the locally built docker image
docker run \
-it \
--env-file=${ENV_FILE} \
--network shared_network_local \
-e MOTO_HOST=moto-server \
$(DOCKER_IMG_LOCAL_TAG)
.PHONY: lint
lint: ## Run the linter on the code base and type-checker ty
$(RUFF) check
$(TY) check
.PHONY: start-moto
start-moto: ## Run moto server locally and initialize resources (DynamoDB, SQS, S3)
docker network create shared_network_local 2>/dev/null || true
# reuse existing container if present, otherwise create it via compose
docker inspect moto-server >/dev/null 2>&1 && docker start moto-server || docker compose --env-file=${ENV_FILE} up -d moto-server
# run one-shot init containers to create DynamoDB table, SQS queues and S3 bucket
docker compose --env-file=${ENV_FILE} up --remove-orphans init-dynamo init-sqs init-s3
.PHONY: stop-moto
stop-moto: ## Stop the moto server container
docker stop moto-server 2>/dev/null || true
.PHONY: test-ci
test-ci: $(LOGS_DIR) ## Run tests in the CI
$(TEST) --cov --cov-branch --cov-report=xml:coverage.xml
.PHONY: test
test: $(LOGS_DIR) ## Run tests locally
$(TEST) --cov --cov-branch --cov-report=html
.PHONY: start-otel
start-otel: ## Run otel collector, jaeger (traces) and prometheus (metrics) locally
docker compose -p service-print-local-otel -f docker-compose-otel.yml up -d
.PHONY: stop-otel
stop-otel: ## Stop the otel collector, jaeger and prometheus
docker compose -p service-print-local-otel -f docker-compose-otel.yml down
.PHONY: help
help: ## Display this help
# automatically generate the help page based on the documentation after each make target
# from https://gist.github.com/prwhite/8168133
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n"} /^[$$()% a-zA-Z_-]+:.*?##/ { printf " \033[36m%-20s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
$(LOGS_DIR):
mkdir -p -m=777 $(LOGS_DIR)