Skip to content

Commit d494e39

Browse files
committed
Build docker image in CI for PRs as well
1 parent 64dd3cf commit d494e39

File tree

2 files changed

+35
-14
lines changed

2 files changed

+35
-14
lines changed

.github/workflows/pull_request.yaml

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
name: Pull Request
22
on: [pull_request]
33

4+
env:
5+
REGISTRY: ghcr.io
6+
IMAGE_NAME: ${{ github.repository }}
7+
48
jobs:
59
lint:
610
name: Lint
@@ -74,19 +78,44 @@ jobs:
7478
name: Docker Tests
7579
needs: [lint]
7680
runs-on: ubuntu-latest
77-
81+
7882
steps:
79-
- name: checkout
83+
- name: Checkout repository
8084
uses: actions/checkout@v4
8185

82-
- name: docker build
83-
run: make docker-build
86+
- name: Set up Docker Buildx
87+
uses: docker/setup-buildx-action@v3
88+
with:
89+
driver: docker
90+
91+
- name: Log in to the Container registry
92+
uses: docker/login-action@v3
93+
with:
94+
registry: ${{ env.REGISTRY }}
95+
username: ${{ github.actor }}
96+
password: ${{ secrets.GITHUB_TOKEN }}
97+
98+
- name: Extract metadata (tags, labels) for Docker
99+
id: meta
100+
uses: docker/metadata-action@v5
101+
with:
102+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
103+
104+
- name: Build and push Docker image
105+
uses: docker/build-push-action@v6
106+
with:
107+
context: .
108+
build-args: |
109+
KONSTRAINT_VER="${{ env.DOCKER_METADATA_OUTPUT_VERSION }}"
110+
push: false
111+
tags: ${{ steps.meta.outputs.tags }}
112+
labels: ${{ steps.meta.outputs.labels }}
84113

85114
- name: test create command
86-
run: docker run -v $PWD:/konstraint konstraint create /konstraint/examples
115+
run: docker run -v $PWD:/konstraint ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.DOCKER_METADATA_OUTPUT_VERSION }} create /konstraint/examples
87116

88117
- name: test doc command
89-
run: docker run -v $PWD:/konstraint konstraint doc /konstraint/examples
118+
run: docker run -v $PWD:/konstraint ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.DOCKER_METADATA_OUTPUT_VERSION }} doc /konstraint/examples
90119

91120
policy-checks:
92121
name: Policy Checks

Makefile

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,6 @@ fmt: ## Ensures consistent formatting on policy tests.
3737
##@ Releases
3838
#
3939

40-
.PHONY: docker-build
41-
docker-build: ## Builds the docker image. Can optionally pass in a version.
42-
ifeq ($(version),)
43-
docker build -t konstraint:latest .
44-
else
45-
docker build -t konstraint:latest -t konstraint:$(version) --build-arg KONSTRAINT_VER=$(version) .
46-
endif
47-
4840
.PHONY: release
4941
release: ## Builds the binaries for each OS and creates the checksums.
5042
@test $(version)

0 commit comments

Comments
 (0)