From dada614c84fc5dcf477f8548a8f709264aa5aa5c Mon Sep 17 00:00:00 2001 From: Alessio Greggi Date: Mon, 20 Jan 2025 00:45:11 +0100 Subject: [PATCH] ci: push docker image when publishing new release Signed-off-by: Alessio Greggi --- .github/workflows/build-and-release.yaml | 29 +++++++++++++++++++++--- Makefile | 19 +++++++++++++++- 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build-and-release.yaml b/.github/workflows/build-and-release.yaml index eaf6aac..6b8df57 100644 --- a/.github/workflows/build-and-release.yaml +++ b/.github/workflows/build-and-release.yaml @@ -1,9 +1,12 @@ name: Build and Release + on: release: types: [published] + permissions: contents: write + jobs: build: runs-on: ubuntu-latest @@ -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 @@ -27,6 +30,7 @@ jobs: with: name: harpoon path: bin/harpoon + release: needs: build runs-on: ubuntu-latest @@ -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 diff --git a/Makefile b/Makefile index 3a3c6ab..7a24c10 100644 --- a/Makefile +++ b/Makefile @@ -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 && \ @@ -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}