Skip to content

Commit

Permalink
Use GHA directly to push container
Browse files Browse the repository at this point in the history
  • Loading branch information
mrueg committed Feb 10, 2025
1 parent 3f954e3 commit ee70bc9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 43 deletions.
44 changes: 33 additions & 11 deletions .github/workflows/push_container.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ on:
tags:
- v*.*.*

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
unit-test:
runs-on: ubuntu-latest
Expand All @@ -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 }}
34 changes: 2 additions & 32 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
#
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit ee70bc9

Please sign in to comment.