diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index f8c5fadb..e123b373 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -20,8 +20,8 @@ jobs: with: cache: poetry - - name: Install dependencies - run: poetry build + - name: Build package + run: make build - name: Publish a Python distribution to PyPI uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3156ff71..a8d724dc 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -33,7 +33,7 @@ jobs: python-version: ${{ matrix.python-version }} - name: Build package - run: poetry build + run: make build black: runs-on: ubuntu-latest @@ -93,8 +93,5 @@ jobs: cache: poetry python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: poetry install - - name: Run tests - run: poetry run pytest + run: make test diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..649776e0 --- /dev/null +++ b/Makefile @@ -0,0 +1,17 @@ +clean: + rm -rfv magnum_cluster_api/charts/cluster-autoscaler + +vendor: clean + helm repo add autoscaler https://kubernetes.github.io/autoscaler + helm repo update + helm fetch autoscaler/cluster-autoscaler --version 9.27.0 --untar --untardir magnum_cluster_api/charts + patch -p0 magnum_cluster_api/charts/cluster-autoscaler/templates/clusterrole.yaml < hack/add-omt-to-clusterrole.patch + +build: vendor + poetry build + +install: build + poetry install + +test: install + poetry run pytest diff --git a/hack/build.py b/hack/build.py deleted file mode 100755 index c91163f7..00000000 --- a/hack/build.py +++ /dev/null @@ -1,48 +0,0 @@ -import shutil -import subprocess - -AUTOSCALER_HELM_REPO_NAME = "autoscaler" -AUTOSCALER_HELM_REPO_URL = "https://kubernetes.github.io/autoscaler" -AUTOSCALER_HELM_CHART = "cluster-autoscaler" -AUTOSCALER_HELM_VERSION = "9.27.0" - - -def setup_helm_repository(name, url): - subprocess.run(["helm", "repo", "add", name, url]) - subprocess.run(["helm", "repo", "update"]) - - -def download_helm_chart(repo, chart, version): - shutil.rmtree(f"magnum_cluster_api/charts/{chart}", ignore_errors=True) - subprocess.run( - [ - "helm", - "fetch", - f"{repo}/{chart}", - "--version", - version, - "--untar", - "--untardir", - "magnum_cluster_api/charts", - ] - ) - - -def download_autoscaler_chart(): - setup_helm_repository(AUTOSCALER_HELM_REPO_NAME, AUTOSCALER_HELM_REPO_URL) - download_helm_chart( - AUTOSCALER_HELM_REPO_NAME, AUTOSCALER_HELM_CHART, AUTOSCALER_HELM_VERSION - ) - with open("hack/add-omt-to-clusterrole.patch", "rb", 0) as fd: - subprocess.check_call( - [ - "patch", - "-p0", - ], - cwd=f"magnum_cluster_api/charts/{AUTOSCALER_HELM_CHART}/templates", - stdin=fd, - ) - - -if __name__ == "__main__": - download_autoscaler_chart() diff --git a/hack/stack.sh b/hack/stack.sh index 37e4aa63..2ad81a78 100755 --- a/hack/stack.sh +++ b/hack/stack.sh @@ -114,6 +114,9 @@ clusterctl init \ sudo curl -Lo /usr/local/bin/skopeo https://github.com/lework/skopeo-binary/releases/download/v1.10.0/skopeo-linux-amd64 sudo chmod +x /usr/local/bin/skopeo +# Vendor the chart +make vendor + # Install `magnum-cluster-api` pip install -U setuptools pip $HOME/.local/bin/pip3 install -e . diff --git a/pyproject.toml b/pyproject.toml index 302a9955..615d3a14 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,10 +24,6 @@ pytest-mock = "^3.6.1" requires = ["setuptools", "poetry-core"] build-backend = "poetry.core.masonry.api" -[tool.poetry.build] -generate-setup-file = false -script = "hack/build.py" - [tool.poetry.scripts] magnum-cluster-api-image-builder = "magnum_cluster_api.cmd.image_builder:main" magnum-cluster-api-image-loader = "magnum_cluster_api.cmd.image_loader:main"