Skip to content

Commit 8fa08a7

Browse files
committed
ci: publish Docker images to GHCR on release
Extend the existing docker workflow to push images to GitHub Container Registry (ghcr.io/libbpf/bpftool) when a new tag is pushed or when changes are merged to main. - Add trigger for version tags (v*.*.*) - Add GHCR login and push steps - Add multi-arch build support (linux/amd64, linux/arm64) - Add build caching using GitHub Actions cache - Add automatic latest tag management with semantic version comparison - Split workflow into separate jobs for testing (PR) and publishing (release) Link: #232 Signed-off-by: Gyutae Bae <gyutae.bae@navercorp.com>
1 parent ad5d76e commit 8fa08a7

File tree

1 file changed

+63
-7
lines changed

1 file changed

+63
-7
lines changed

.github/workflows/docker.yaml

Lines changed: 63 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,21 @@ on:
1111
push:
1212
branches:
1313
- main
14+
tags:
15+
- 'v[0-9]+.[0-9]+.[0-9]+'
1416

1517
concurrency:
1618
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.event.after }}
1719
cancel-in-progress: true
1820

21+
env:
22+
REGISTRY: ghcr.io
23+
IMAGE_NAME: ${{ github.repository }}
24+
1925
jobs:
20-
dockerimage:
21-
name: Docker image
26+
test:
27+
name: Test Docker image
28+
if: github.event_name == 'pull_request'
2229
runs-on: ubuntu-latest
2330
steps:
2431
- name: Checkout repository
@@ -29,16 +36,65 @@ jobs:
2936
- name: Build bpftool container image
3037
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
3138
with:
32-
push: false
33-
tags: bpftool:latest
39+
context: .
40+
load: true
41+
tags: bpftool:test
3442

3543
- name: Test bpftool container image
3644
run: |
37-
docker run --rm --privileged --pid=host bpftool version
38-
docker run --rm --privileged --pid=host bpftool prog
39-
docker run --rm --privileged --pid=host bpftool map
45+
docker run --rm --privileged --pid=host bpftool:test version
46+
docker run --rm --privileged --pid=host bpftool:test prog
47+
docker run --rm --privileged --pid=host bpftool:test map
4048
4149
- name: Lint Docker image
4250
uses: hadolint/hadolint-action@2332a7b74a6de0dda2e2221d575162eba76ba5e5 # v3.3.0
4351
with:
4452
dockerfile: Dockerfile
53+
54+
build-and-push:
55+
name: Build and push Docker image
56+
if: github.event_name != 'pull_request'
57+
runs-on: ubuntu-latest
58+
permissions:
59+
contents: read
60+
packages: write
61+
steps:
62+
- name: Checkout repository
63+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
64+
with:
65+
submodules: recursive
66+
67+
- name: Set up QEMU
68+
uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3.7.0
69+
70+
- name: Set up Docker Buildx
71+
uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2 # v3.10.0
72+
73+
- name: Log in to the Container registry
74+
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
75+
with:
76+
registry: ${{ env.REGISTRY }}
77+
username: ${{ github.actor }}
78+
password: ${{ secrets.GITHUB_TOKEN }}
79+
80+
- name: Extract metadata (tags, labels) for Docker
81+
id: meta
82+
uses: docker/metadata-action@902fa8ec7d6ecbf8d84d538b9b233a880e428804 # v5.7.0
83+
with:
84+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
85+
flavor: |
86+
latest=auto
87+
tags: |
88+
type=ref,event=branch
89+
type=semver,pattern={{version}}
90+
91+
- name: Build and push bpftool container image
92+
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
93+
with:
94+
context: .
95+
platforms: linux/amd64,linux/arm64
96+
push: true
97+
tags: ${{ steps.meta.outputs.tags }}
98+
labels: ${{ steps.meta.outputs.labels }}
99+
cache-from: type=gha
100+
cache-to: type=gha,mode=max

0 commit comments

Comments
 (0)