forked from app-sre/qontract-reconcile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
116 lines (92 loc) · 5.08 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
.PHONY: help build push rc build-test test-app test-container-image test clean
CONTAINER_ENGINE ?= $(shell which podman >/dev/null 2>&1 && echo podman || echo docker)
CONTAINER_UID ?= $(shell id -u)
IMAGE_TEST := reconcile-test
IMAGE_NAME := quay.io/app-sre/qontract-reconcile
IMAGE_TAG := $(shell git rev-parse --short=7 HEAD)
VENV_CMD := . venv/bin/activate &&
UUID := $(shell python3 -c 'import uuid; print(str(uuid.uuid4()))')
EXPECTED_QENERATE_VERSION := $(shell grep qenerate requirements/requirements-type.txt | cut -d = -f3)
ifneq (,$(wildcard $(CURDIR)/.docker))
DOCKER_CONF := $(CURDIR)/.docker
else
DOCKER_CONF := $(HOME)/.docker
endif
CTR_STRUCTURE_IMG := quay.io/app-sre/container-structure-test:latest
help: ## Prints help for targets with comments
@grep -E '^[a-zA-Z0-9.\ _-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
# this will write a GIT_VERSION file in the current dir, which allows to get the info from a non-git-repo folder, like during docker build
git_version:
rm -f GIT_VERSION
python3 --version
./version --git
build: git_version
@DOCKER_BUILDKIT=1 $(CONTAINER_ENGINE) build -t $(IMAGE_NAME):latest -f dockerfiles/Dockerfile --target prod-image . --progress=plain
@$(CONTAINER_ENGINE) tag $(IMAGE_NAME):latest $(IMAGE_NAME):$(IMAGE_TAG)
build-dev: git_version
@DOCKER_BUILDKIT=1 $(CONTAINER_ENGINE) build --build-arg CONTAINER_UID=$(CONTAINER_UID) -t $(IMAGE_NAME)-dev:latest -f dockerfiles/Dockerfile --target dev-image .
push:
@$(CONTAINER_ENGINE) --config=$(DOCKER_CONF) push $(IMAGE_NAME):latest
@$(CONTAINER_ENGINE) --config=$(DOCKER_CONF) push $(IMAGE_NAME):$(IMAGE_TAG)
rc: git_version
@$(CONTAINER_ENGINE) build -t $(IMAGE_NAME):$(IMAGE_TAG)-rc -f dockerfiles/Dockerfile --target prod-image .
@$(CONTAINER_ENGINE) --config=$(DOCKER_CONF) push $(IMAGE_NAME):$(IMAGE_TAG)-rc
generate:
@helm lint helm/qontract-reconcile
@helm template helm/qontract-reconcile -n qontract-reconcile -f helm/qontract-reconcile/values-manager.yaml > openshift/qontract-manager.yaml
@helm template helm/qontract-reconcile -n qontract-reconcile -f helm/qontract-reconcile/values-manager-fedramp.yaml > openshift/qontract-manager-fedramp.yaml
build-test:
@$(CONTAINER_ENGINE) build -t $(IMAGE_TEST) -f dockerfiles/Dockerfile.test .
test-app: build-test ## Target to test app with tox on docker
@$(CONTAINER_ENGINE) run --rm $(IMAGE_TEST)
test-container-image: build ## Target to test the final image
@$(CONTAINER_ENGINE) run --rm \
-v /var/run/docker.sock:/var/run/docker.sock \
-v $(CURDIR):/work \
$(CTR_STRUCTURE_IMG) test \
--config /work/dockerfiles/structure-test.yaml \
-i $(IMAGE_NAME):$(IMAGE_TAG)
test: test-app test-container-image
dev-reconcile-loop: build-dev ## Trigger the reconcile loop inside a container for an integration
@$(CONTAINER_ENGINE) run --rm -it \
--add-host=host.docker.internal:host-gateway \
-v "$(CURDIR)":/work \
-p 5678:5678 \
-e INTEGRATION_NAME="$(INTEGRATION_NAME)" \
-e INTEGRATION_EXTRA_ARGS="$(INTEGRATION_EXTRA_ARGS)" \
-e SLEEP_DURATION_SECS="$(SLEEP_DURATION_SECS)" \
-e APP_INTERFACE_STATE_BUCKET="$(APP_INTERFACE_STATE_BUCKET)" \
-e APP_INTERFACE_STATE_BUCKET_ACCOUNT="$(APP_INTERFACE_STATE_BUCKET_ACCOUNT)" \
-e gitlab_pr_submitter_queue_url="$(gitlab_pr_submitter_queue_url)" \
-e LOG_LEVEL="$(LOG_LEVEL)" \
-e DRY_RUN="$(DRY_RUN)" \
-e DEBUGGER="$(DEBUGGER)" \
-e CONFIG=/work/config.dev.toml \
$(IMAGE_NAME)-dev:latest
clean:
@rm -rf .tox .eggs reconcile.egg-info build .pytest_cache venv GIT_VERSION
@find . -name "__pycache__" -type d -print0 | xargs -0 rm -rf
@find . -name "*.pyc" -delete
pypi-release:
@$(CONTAINER_ENGINE) build -t $(UUID):latest -f dockerfiles/Dockerfile.publish-release .
@$(CONTAINER_ENGINE) run -e TWINE_USERNAME -e TWINE_PASSWORD --rm $(UUID):latest ./build_tag.sh
@$(CONTAINER_ENGINE) rmi $(UUID):latest
dev-venv: clean ## Create a local venv for your IDE and remote debugging
python3.11 -m venv venv
@$(VENV_CMD) pip install --upgrade pip
@$(VENV_CMD) pip install -e .
@$(VENV_CMD) pip install -r requirements/requirements-dev.txt
print-files-modified-in-last-30-days:
@git log --since '$(shell date --date='-30 day' +"%m/%d/%y")' --until '$(shell date +"%m/%d/%y")' --oneline --name-only --pretty=format: | sort | uniq | grep -E '.py$$'
format:
@$(VENV_CMD) isort reconcile tools release dockerfiles/hack setup.py
@$(VENV_CMD) black reconcile tools release dockerfiles/hack setup.py
gql-introspection:
# TODO: make url configurable
@$(VENV_CMD) qenerate introspection http://localhost:4000/graphql > reconcile/gql_definitions/introspection.json
gql-query-classes:
@$(VENV_CMD) qenerate --version | grep -q $(EXPECTED_QENERATE_VERSION) || (echo "Bad qenerate version. Make sure you have version $(EXPECTED_QENERATE_VERSION) installed" && exit 1)
@$(VENV_CMD) qenerate code -i reconcile/gql_definitions/introspection.json reconcile/gql_definitions
find reconcile/gql_definitions -path '*/__pycache__' -prune -o -type d -exec touch "{}/__init__.py" \;
@$(VENV_CMD) black reconcile/gql_definitions
qenerate: gql-introspection gql-query-classes