Skip to content

Commit

Permalink
ci: push docker image when publishing new release
Browse files Browse the repository at this point in the history
Signed-off-by: Alessio Greggi <[email protected]>
  • Loading branch information
alegrey91 committed Jan 19, 2025
1 parent 3ef90ff commit dada614
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
29 changes: 26 additions & 3 deletions .github/workflows/build-and-release.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
name: Build and Release

on:
release:
types: [published]

permissions:
contents: write

jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -14,11 +17,11 @@ jobs:
uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # ratchet:actions/setup-go@v5
with:
go-version: '1.21.7'
- name: Install BCC Dependencies
- name: Install Dependencies
run: |
sudo apt update
sudo apt install -y libbpf-dev # Install libbpf dependency
sudo apt install -y libseccomp-dev # Install Seccomp dependencies
sudo apt install -y libbpf-dev
sudo apt install -y libseccomp-dev
- name: Build and Test
run: |
make build-gh
Expand All @@ -27,6 +30,7 @@ jobs:
with:
name: harpoon
path: bin/harpoon

release:
needs: build
runs-on: ubuntu-latest
Expand All @@ -44,3 +48,22 @@ jobs:
harpoon
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

build-and-push-docker:
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # ratchet:actions/checkout@v3

- name: Log in to Docker Hub
uses: docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc # ratchet:docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }}

- name: Build Docker image
run: make build-docker

- name: Push Docker image to Docker Hub
run: make push-docker
19 changes: 18 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
BINARY_NAME=harpoon
BINARY_DIR=./bin
OUTPUT_DIR=./output
IMAGE_NAME=alegrey91/harpoon

build-static-libbpfgo:
git clone https://github.com/aquasecurity/libbpfgo.git && \
Expand Down Expand Up @@ -68,7 +69,23 @@ endif
.

build-docker:
docker build --no-cache -t harpoon:latest .
ifdef GITHUB_REF_NAME
docker build \
--no-cache \
-t ${IMAGE_NAME}:latest \
-t ${IMAGE_NAME}:${GITHUB_REF_NAME} \
.
endif
docker build \
--no-cache \
-t ${IMAGE_NAME}:latest \
.

push-docker:
ifdef GITHUB_REF_NAME
docker push ${IMAGE_NAME}:${GITHUB_REF_NAME}
docker push ${IMAGE_NAME}:latest
endif

create-bin-dir:
mkdir -p ${BINARY_DIR}
Expand Down

0 comments on commit dada614

Please sign in to comment.