Skip to content

Commit be809dc

Browse files
committed
Use GHA directly to push container
1 parent 3f954e3 commit be809dc

File tree

2 files changed

+33
-49
lines changed

2 files changed

+33
-49
lines changed

.github/workflows/push_container.yaml

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ on:
44
tags:
55
- v*.*.*
66

7+
env:
8+
REGISTRY: ghcr.io
9+
IMAGE_NAME: ${{ github.repository }}
10+
711
jobs:
812
unit-test:
913
runs-on: ubuntu-latest
@@ -28,17 +32,35 @@ jobs:
2832
needs: [unit-test]
2933

3034
steps:
31-
- name: checkout
32-
uses: actions/checkout@v4
35+
- name: Checkout repository
36+
uses: actions/checkout@v4
3337

34-
- name: get version tag
35-
run: echo TAG_NAME=$(echo ${GITHUB_REF} | rev | cut -d"/" -f1 | rev) >> $GITHUB_ENV
38+
- name: Set up QEMU
39+
uses: docker/setup-qemu-action@v3
40+
41+
- name: Set up Docker Buildx
42+
uses: docker/setup-buildx-action@v3
43+
44+
- name: Log in to the Container registry
45+
uses: docker/login-action@v3
46+
with:
47+
registry: ${{ env.REGISTRY }}
48+
username: ${{ github.actor }}
49+
password: ${{ secrets.GITHUB_TOKEN }}
3650

37-
- name: docker login
38-
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
51+
- name: Extract metadata (tags, labels) for Docker
52+
id: meta
53+
uses: docker/metadata-action@v5
54+
with:
55+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
3956

40-
- name: docker build
41-
run: >-
42-
docker buildx create --name builder &&
43-
docker buildx use --builder builder &&
44-
make dockerx-build version=${TAG_NAME}
57+
- name: Build and push Docker image
58+
uses: docker/build-push-action@v6
59+
with:
60+
context: .
61+
build-args: |
62+
KONSTRAINT_VER="${{ github.ref_name }}"
63+
platforms: linux/arm/v7,linux/arm64,linux/amd64
64+
push: true
65+
tags: ${{ steps.meta.outputs.tags }}
66+
labels: ${{ steps.meta.outputs.labels }}

Makefile

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
## The repository where the container image will be pushed to.
2-
IMAGE := ghcr.io/plexsystems/konstraint
3-
4-
PLATFORMS := linux/arm/v7,linux/arm64/v8,linux/amd64
5-
61
#
72
##@ Development
83
#
@@ -42,39 +37,6 @@ fmt: ## Ensures consistent formatting on policy tests.
4237
##@ Releases
4338
#
4439

45-
.PHONY: docker-build
46-
docker-build: ## Builds the docker image. Can optionally pass in a version.
47-
ifeq ($(version),)
48-
docker build -t konstraint:latest .
49-
else
50-
docker build -t konstraint:latest -t konstraint:$(version) --build-arg KONSTRAINT_VER=$(version) .
51-
endif
52-
53-
.PHONY: dockerx-build
54-
dockerx-build: ## Builds the docker image. Can optionally pass in a version.
55-
ifeq ($(version),)
56-
docker buildx build \
57-
--platform "$(PLATFORMS)" \
58-
-t konstraint:latest \
59-
.
60-
else
61-
docker buildx build \
62-
--push \
63-
--platform "$(PLATFORMS)" \
64-
-t konstraint:latest \
65-
-t "konstraint:$(version)" \
66-
--build-arg "KONSTRAINT_VER=$(version)" \
67-
.
68-
endif
69-
70-
.PHONY: docker-push
71-
docker-push: ## Pushes the docker image to the container registry.
72-
@test $(version)
73-
docker tag konstraint:latest $(IMAGE):$(version)
74-
docker tag konstraint:latest $(IMAGE):latest
75-
docker push $(IMAGE):$(version)
76-
docker push $(IMAGE):latest
77-
7840
.PHONY: release
7941
release: ## Builds the binaries for each OS and creates the checksums.
8042
@test $(version)

0 commit comments

Comments
 (0)