Skip to content

Commit

Permalink
uv migration (#4790)
Browse files Browse the repository at this point in the history
The PR migrates the project to uv.

This includes the following significant changes:

* qontract-reconcile pre-release versions will change from X.Y.ZrcAAAA to X.Y.Z.devAAAA
* ⚰️ RIP tox: tox doesn't play nicely with the requirements defined in pyproject.toml, and we don't use any important tox feature
* Some preparation work for the future Konflux migration
  • Loading branch information
chassing authored Dec 10, 2024
1 parent 01bccf8 commit f865f98
Show file tree
Hide file tree
Showing 29 changed files with 3,144 additions and 662 deletions.
6 changes: 0 additions & 6 deletions .coveragerc

This file was deleted.

1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ build
.pytest_cache
.tox
venv
.venv
throughput

**/__pycache__
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ coverage.xml
dev/localstack/volume
dist
venv
.venv
throughput
config.toml
config.*.toml
Expand Down
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# this file is used by asdf to automatically select the correct tool versions
# but it also serves as a reference for non-asdf users
python 3.11.4
uv
terraform 1.6.6
oc 4.12.46
helm 3.11.1
81 changes: 46 additions & 35 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ IMAGE_NAME := quay.io/app-sre/qontract-reconcile
COMMIT_AUTHOR_EMAIL := $(shell git show -s --format='%ae' HEAD)
COMMIT_SHA := $(shell git rev-parse HEAD)
IMAGE_TAG := $(shell git rev-parse --short=7 HEAD)
VENV_CMD := . venv/bin/activate &&
BUILD_TARGET := prod-image
UUID := $(shell python3 -c 'import uuid; print(str(uuid.uuid4()))')
EXPECTED_QENERATE_VERSION := $(shell grep qenerate requirements/requirements-type.txt | cut -d = -f3)

.EXPORT_ALL_VARIABLES:
# TWINE_USERNAME & TWINE_PASSWORD are available in jenkins job
UV_PUBLISH_TOKEN = $(TWINE_PASSWORD)


ifneq (,$(wildcard $(CURDIR)/.docker))
DOCKER_CONF := $(CURDIR)/.docker
Expand All @@ -24,37 +25,29 @@ 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 $(BUILD_TARGET) . --progress=plain
build:
@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 .
build-dev:
@DOCKER_BUILDKIT=1 $(CONTAINER_ENGINE) build --progress=plain --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
rc:
@$(CONTAINER_ENGINE) build -t $(IMAGE_NAME):$(IMAGE_TAG)-rc --build-arg quay_expiration=3d -f dockerfiles/Dockerfile --target prod-image .
@$(CONTAINER_ENGINE) --config=$(DOCKER_CONF) push $(IMAGE_NAME):$(IMAGE_TAG)-rc

generate:
@mkdir -p openshift
@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-app: ## Target to test app in a container
@$(CONTAINER_ENGINE) build --progress=plain -t $(IMAGE_TEST) -f dockerfiles/Dockerfile --target test-image .

print-host-versions:
@$(CONTAINER_ENGINE) --version
Expand Down Expand Up @@ -87,37 +80,35 @@ dev-reconcile-loop: build-dev ## Trigger the reconcile loop inside a container f
-e CONFIG=/work/config.dev.toml \
$(IMAGE_NAME)-dev:latest

clean:
@rm -rf .tox .eggs reconcile.egg-info build .pytest_cache venv GIT_VERSION
clean: ## Clean up the local development environment
@rm -rf .tox .eggs reconcile.egg-info build .pytest_cache venv .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
@$(CONTAINER_ENGINE) build --progress=plain --build-arg TWINE_USERNAME --build-arg TWINE_PASSWORD --target pypi -f dockerfiles/Dockerfile .

pypi:
uv build --sdist --wheel
uv publish

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
uv sync --python 3.11

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) ruff format
@$(VENV_CMD) ruff check
@uv run ruff format
@uv run ruff check

gql-introspection:
# TODO: make url configurable
@$(VENV_CMD) qenerate introspection http://localhost:4000/graphql > reconcile/gql_definitions/introspection.json
@uv run 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" \;
@uv run 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" \;

qenerate: gql-introspection gql-query-classes

Expand All @@ -129,3 +120,23 @@ sqs:
AWS_SECRET_ACCESS_KEY=$(APP_INTERFACE_SQS_AWS_SECRET_ACCESS_KEY) \
AWS_REGION=$(APP_INTERFACE_SQS_AWS_REGION) \
aws sqs send-message --queue-url $(APP_INTERFACE_SQS_QUEUE_URL) --message-body "{\"pr_type\": \"promote_qontract_reconcile\", \"version\": \"$(IMAGE_TAG)\", \"commit_sha\": \"$(COMMIT_SHA)\", \"author_email\": \"$(COMMIT_AUTHOR_EMAIL)\"}"

all-tests: linter-test types-test qenerate-test helm-test unittest

linter-test:
uv run ruff check --no-fix
uv run ruff format --check

types-test:
uv run mypy

qenerate-test: gql-query-classes
git diff --exit-code reconcile/gql_definitions

helm-test: generate
git diff --exit-code helm openshift

unittest: ## Run unit tests
uv run pytest --cov=reconcile --cov-report=term-missing --cov-report xml
uv run coverage html
uv run coverage xml
Loading

0 comments on commit f865f98

Please sign in to comment.