Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
123 lines (93 loc) · 3.64 KB
/
Copy pathMakefile
File metadata and controls
123 lines (93 loc) · 3.64 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
SHELL = /bin/bash
.DEFAULT_GOAL := help
SERVICE_NAME := service-airflow
HTTP_PORT ?= 8080
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)
# Commands
UV_RUN := uv run
PYTHON := $(UV_RUN) python3
TEST := $(UV_RUN) pytest
RUFF := $(UV_RUN) ruff
TY := $(UV_RUN) ty
PRE_COMMIT := $(UV_RUN) pre-commit
# 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
.PHONY: git-info
git-info: ## Print the current version information
@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:
# Create virtual env with all packages for development
uv sync --frozen
.PHONY: setup
setup:
uv sync
$(PRE_COMMIT) install
# Start a new shell with the virtualenv activated
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: 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: ## Create a docker image
docker build \
--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
set -o pipefail; \
docker push $(DOCKER_IMG_LOCAL_TAG) 2>&1 | grep --color=always -E "tag invalid: .*|$$"
.PHONY: lint
lint: ## Run the linter and type checker on the code base
$(RUFF) check
$(TY) check
.PHONY: test-ci
test-ci: ## Run tests in the CI
# NOTE on the CI we do not fail the build if the coverage is below 100% because we want to be
# able to merge PRs even if they decrease the coverage. The coverage report will be used in
# codecov.io to track the coverage over time and to check if it decreases or not. Also
# the coverage report is only loaded if make test-ci is successful.
$(TEST) --cov --cov-branch --cov-report=xml:coverage.xml -n 10
.PHONY: test
test: ## Run tests locally
$(TEST) --cov --cov-branch --cov-report=term --cov-report=html -n 10
.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 = ":.*##"} \
/^[a-zA-Z0-9_.-]+:.*##/ { printf "%-15s %s\n", $$1, $$2 }' $(MAKEFILE_LIST) \
| sort \
| awk 'BEGIN { printf "\nUsage:\n make \033[36m<target>\033[0m\n\n" } \
{ printf " \033[36m%-15s\033[0m %s\n", $$1, substr($$0, index($$0,$$2)) }'