Skip to content

Commit dada614

Browse files
committed
ci: push docker image when publishing new release
Signed-off-by: Alessio Greggi <[email protected]>
1 parent 3ef90ff commit dada614

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

.github/workflows/build-and-release.yaml

+26-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
name: Build and Release
2+
23
on:
34
release:
45
types: [published]
6+
57
permissions:
68
contents: write
9+
710
jobs:
811
build:
912
runs-on: ubuntu-latest
@@ -14,11 +17,11 @@ jobs:
1417
uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # ratchet:actions/setup-go@v5
1518
with:
1619
go-version: '1.21.7'
17-
- name: Install BCC Dependencies
20+
- name: Install Dependencies
1821
run: |
1922
sudo apt update
20-
sudo apt install -y libbpf-dev # Install libbpf dependency
21-
sudo apt install -y libseccomp-dev # Install Seccomp dependencies
23+
sudo apt install -y libbpf-dev
24+
sudo apt install -y libseccomp-dev
2225
- name: Build and Test
2326
run: |
2427
make build-gh
@@ -27,6 +30,7 @@ jobs:
2730
with:
2831
name: harpoon
2932
path: bin/harpoon
33+
3034
release:
3135
needs: build
3236
runs-on: ubuntu-latest
@@ -44,3 +48,22 @@ jobs:
4448
harpoon
4549
env:
4650
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
51+
52+
build-and-push-docker:
53+
needs: build
54+
runs-on: ubuntu-latest
55+
steps:
56+
- name: Checkout code
57+
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # ratchet:actions/checkout@v3
58+
59+
- name: Log in to Docker Hub
60+
uses: docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc # ratchet:docker/login-action@v2
61+
with:
62+
username: ${{ secrets.DOCKERHUB_USERNAME }}
63+
password: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }}
64+
65+
- name: Build Docker image
66+
run: make build-docker
67+
68+
- name: Push Docker image to Docker Hub
69+
run: make push-docker

Makefile

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
BINARY_NAME=harpoon
22
BINARY_DIR=./bin
33
OUTPUT_DIR=./output
4+
IMAGE_NAME=alegrey91/harpoon
45

56
build-static-libbpfgo:
67
git clone https://github.com/aquasecurity/libbpfgo.git && \
@@ -68,7 +69,23 @@ endif
6869
.
6970

7071
build-docker:
71-
docker build --no-cache -t harpoon:latest .
72+
ifdef GITHUB_REF_NAME
73+
docker build \
74+
--no-cache \
75+
-t ${IMAGE_NAME}:latest \
76+
-t ${IMAGE_NAME}:${GITHUB_REF_NAME} \
77+
.
78+
endif
79+
docker build \
80+
--no-cache \
81+
-t ${IMAGE_NAME}:latest \
82+
.
83+
84+
push-docker:
85+
ifdef GITHUB_REF_NAME
86+
docker push ${IMAGE_NAME}:${GITHUB_REF_NAME}
87+
docker push ${IMAGE_NAME}:latest
88+
endif
7289

7390
create-bin-dir:
7491
mkdir -p ${BINARY_DIR}

0 commit comments

Comments
 (0)