From ee70bc9dafb34aaaba71141fa55c0ac668503962 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20R=C3=BCger?= Date: Mon, 10 Feb 2025 17:12:41 +0100 Subject: [PATCH] Use GHA directly to push container --- .github/workflows/push_container.yaml | 44 ++++++++++++++++++++------- Makefile | 34 ++------------------- 2 files changed, 35 insertions(+), 43 deletions(-) diff --git a/.github/workflows/push_container.yaml b/.github/workflows/push_container.yaml index 964284e3..df8fcc12 100644 --- a/.github/workflows/push_container.yaml +++ b/.github/workflows/push_container.yaml @@ -4,6 +4,10 @@ on: tags: - v*.*.* +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + jobs: unit-test: runs-on: ubuntu-latest @@ -28,17 +32,35 @@ jobs: needs: [unit-test] steps: - - name: checkout - uses: actions/checkout@v4 + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 - - name: get version tag - run: echo TAG_NAME=$(echo ${GITHUB_REF} | rev | cut -d"/" -f1 | rev) >> $GITHUB_ENV + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} - - name: docker login - run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - - name: docker build - run: >- - docker buildx create --name builder && - docker buildx use --builder builder && - make dockerx-build version=${TAG_NAME} + - name: Build and push Docker image + uses: docker/build-push-action@v6 + with: + context: . + build-args: | + KONSTRAINT_VER="${{ github.ref_name }}" + platforms: linux/arm/v7,linux/arm64,linux/amd64 + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/Makefile b/Makefile index e04b3e57..a3544495 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,3 @@ -## The repository where the container image will be pushed to. -IMAGE := ghcr.io/plexsystems/konstraint - -PLATFORMS := linux/arm/v7,linux/arm64/v8,linux/amd64 - # ##@ Development # @@ -45,36 +40,11 @@ fmt: ## Ensures consistent formatting on policy tests. .PHONY: docker-build docker-build: ## Builds the docker image. Can optionally pass in a version. ifeq ($(version),) - docker build -t konstraint:latest . -else - docker build -t konstraint:latest -t konstraint:$(version) --build-arg KONSTRAINT_VER=$(version) . -endif - -.PHONY: dockerx-build -dockerx-build: ## Builds the docker image. Can optionally pass in a version. -ifeq ($(version),) - docker buildx build \ - --platform "$(PLATFORMS)" \ - -t konstraint:latest \ - . + docker build -t konstraint:latest . else - docker buildx build \ - --push \ - --platform "$(PLATFORMS)" \ - -t konstraint:latest \ - -t "konstraint:$(version)" \ - --build-arg "KONSTRAINT_VER=$(version)" \ - . + docker build -t konstraint:latest -t konstraint:$(version) --build-arg KONSTRAINT_VER=$(version) . endif -.PHONY: docker-push -docker-push: ## Pushes the docker image to the container registry. - @test $(version) - docker tag konstraint:latest $(IMAGE):$(version) - docker tag konstraint:latest $(IMAGE):latest - docker push $(IMAGE):$(version) - docker push $(IMAGE):latest - .PHONY: release release: ## Builds the binaries for each OS and creates the checksums. @test $(version)