From ad61d78b57178ff6e271b20227aced3f655f8605 Mon Sep 17 00:00:00 2001 From: Mughees2001 Date: Sun, 9 Feb 2025 02:09:57 -0500 Subject: [PATCH 1/9] fix: centralize Go version management and simplify Dockerfile build --- .github/workflows/build-and-release.yaml | 32 +++++--- .github/workflows/build.yaml | 21 +++-- .github/workflows/tests.yaml | 98 ++++++++++++------------ Dockerfile | 3 +- Makefile | 16 ++-- 5 files changed, 96 insertions(+), 74 deletions(-) diff --git a/.github/workflows/build-and-release.yaml b/.github/workflows/build-and-release.yaml index b343bfe..4fbc439 100644 --- a/.github/workflows/build-and-release.yaml +++ b/.github/workflows/build-and-release.yaml @@ -12,21 +12,32 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Checkout code - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # ratchet:actions/checkout@v4 + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 + + - name: Get Go version from go.mod + id: get_go_version + run: | + # Extract the Go version from the "toolchain" line in go.mod (e.g. "toolchain go1.23.2" becomes "1.23.2") + go_version=$(grep '^toolchain' go.mod | awk '{print $2}' | sed 's/go//') + echo "go_version=$go_version" >> $GITHUB_OUTPUT + - name: Set up Go - uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # ratchet:actions/setup-go@v5 + uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a with: - go-version: '1.23.2' + go-version: ${{ steps.get_go_version.outputs.go_version }} + - name: Install Dependencies run: | sudo apt update sudo apt install -y libbpf-dev sudo apt install -y libseccomp-dev + - name: Build and Test run: | make build-gh + - name: Upload Artifact - uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b # ratchet:actions/upload-artifact@v4 + uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b with: name: harpoon path: bin/harpoon @@ -36,13 +47,13 @@ jobs: runs-on: ubuntu-latest steps: - name: Download Artifact - uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # ratchet:actions/download-artifact@v4 + uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 with: name: harpoon path: ./ - name: Create Release id: create_release - uses: softprops/action-gh-release@e7a8f85e1c67a31e6ed99a94b41bd0b71bbee6b8 # ratchet:softprops/action-gh-release@v2 + uses: softprops/action-gh-release@e7a8f85e1c67a31e6ed99a94b41bd0b71bbee6b8 with: files: | harpoon @@ -56,10 +67,10 @@ jobs: packages: write steps: - name: Checkout code - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # ratchet:actions/checkout@v3 + uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 - name: Log in to Docker Hub - uses: docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc # ratchet:docker/login-action@v2 + uses: docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }} @@ -77,9 +88,8 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Build Docker image + - name: Build Docker image (GHCR) run: IMAGE_NAME="ghcr.io/alegrey91/harpoon" make build-docker - - name: Push Docker image to Docker Hub + - name: Push Docker image to GHCR run: IMAGE_NAME="ghcr.io/alegrey91/harpoon" make push-docker - diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 7b7039f..9a52408 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -10,16 +10,25 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Checkout code - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # ratchet:actions/checkout@v4 + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 + + - name: Get Go version from go.mod + id: get_go_version + run: | + # Extract the Go version from the "toolchain" line (e.g. "toolchain go1.23.2" becomes "1.23.2") + go_version=$(grep '^toolchain' go.mod | awk '{print $2}' | sed 's/go//') + echo "go_version=$go_version" >> $GITHUB_OUTPUT + - name: Set up Go - uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # ratchet:actions/setup-go@v5 + uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a with: - go-version: '1.21.7' + go-version: ${{ steps.get_go_version.outputs.go_version }} + - name: Install BCC Dependencies run: | sudo apt update sudo apt install -y libbpf-dev # Install libbpf dependencies - sudo apt install -y libseccomp-dev # Install Seccomp dependencies + sudo apt install -y libseccomp-dev # Install Seccomp dependencies + - name: Build and Test - run: |- - make build-gh + run: make build-gh diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index fd01d77..19db56b 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -8,15 +8,22 @@ on: jobs: unit-test: - runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # ratchet:actions/checkout@v4 + - name: Checkout code + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 + + - name: Get Go version from go.mod + id: get_go_version + run: | + # Extract the version from the toolchain line (e.g. "toolchain go1.23.2" becomes "1.23.2") + go_version=$(grep '^toolchain' go.mod | awk '{print $2}' | sed 's/go//') + echo "go_version=$go_version" >> $GITHUB_OUTPUT - name: Set up Go - uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # ratchet:actions/setup-go@v5 + uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a with: - go-version: '1.21' + go-version: ${{ steps.get_go_version.outputs.go_version }} - name: Install Dependencies run: | @@ -42,21 +49,27 @@ jobs: -args -test.gocoverdir=/tmp/unit/ - name: Upload cover profiles - uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b # ratchet:actions/upload-artifact@v4 + uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b with: name: unit-test path: /tmp/unit/ integration-test: - runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # ratchet:actions/checkout@v4 + - name: Checkout code + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 + + - name: Get Go version from go.mod + id: get_go_version + run: | + go_version=$(grep '^toolchain' go.mod | awk '{print $2}' | sed 's/go//') + echo "go_version=$go_version" >> $GITHUB_OUTPUT - name: Set up Go - uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # ratchet:actions/setup-go@v5 + uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a with: - go-version: '1.21' + go-version: ${{ steps.get_go_version.outputs.go_version }} - name: Install Dependencies run: | @@ -78,72 +91,55 @@ jobs: - name: Run integration test run: | mkdir -p /tmp/integration - # we have to run integration tests one-by-one - # otherwhise they will run in parallel. - # since harpoon apply network forwards, these could - # interact with each other and make the test fail. + # We run integration tests one-by-one to avoid parallel issues go test \ -exec sudo \ -cover \ -v main_test.go \ -args -test.gocoverdir=/tmp/integration/ + - name: Upload cover profiles - uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b # ratchet:actions/upload-artifact@v4 + uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b with: name: integration-test path: /tmp/integration/ + code-coverage: runs-on: ubuntu-22.04 needs: [unit-test, integration-test] steps: - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # ratchet:actions/checkout@v4 - - uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # ratchet:actions/download-artifact@v4 + - name: Checkout code + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 + + - name: Get Go version from go.mod + id: get_go_version + run: | + go_version=$(grep '^toolchain' go.mod | awk '{print $2}' | sed 's/go//') + echo "go_version=$go_version" >> $GITHUB_OUTPUT + + - name: Download Unit Test Artifact + uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 with: name: unit-test path: /tmp/unit-test - - uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # ratchet:actions/download-artifact@v4 + + - name: Download Integration Test Artifact + uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 with: name: integration-test path: /tmp/integration-test - - name: list files - run: |2 + - name: List files + run: | ls -lah /tmp/unit-test ls -lah /tmp/integration-test + - name: Set up Go - uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # ratchet:actions/setup-go@v5 + uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a with: - go-version: '1.21' + go-version: ${{ steps.get_go_version.outputs.go_version }} - name: Calculate total coverage run: | - go tool \ - covdata \ - textfmt \ - -i=/tmp/unit-test,/tmp/integration-test \ - -o=code-coverage - go tool \ - cover \ - -func code-coverage - - - - - - - - - - - - - - - - - - - - - - + go tool covdata textfmt -i=/tmp/unit-test,/tmp/integration-test -o=code-coverage + go tool cover -func code-coverage diff --git a/Dockerfile b/Dockerfile index 74b6ba2..5e94dd4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,6 @@ # Minimal Base Image -FROM golang:1.23.2 AS builder +ARG GO_VERSION=1.23.2 +FROM golang:${GO_VERSION} AS builder WORKDIR /workspace diff --git a/Makefile b/Makefile index 50cf657..3106c22 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,9 @@ BINARY_DIR=./bin OUTPUT_DIR=./output IMAGE_NAME?=alegrey91/harpoon +GO_VERSION := $(shell grep '^toolchain' go.mod | awk '{print $$2}' | sed 's/go//') + + build-static-libbpfgo: git clone https://github.com/aquasecurity/libbpfgo.git && \ cd libbpfgo/ && \ @@ -68,18 +71,21 @@ endif -o ${BINARY_DIR}/${BINARY_NAME} \ . -build-docker: +build-docker: build ifdef GITHUB_REF_NAME docker build \ --no-cache \ - -t ${IMAGE_NAME}:latest \ - -t ${IMAGE_NAME}:${GITHUB_REF_NAME} \ + --build-arg GO_VERSION=$(GO_VERSION) \ + -t $(IMAGE_NAME):latest \ + -t $(IMAGE_NAME):$(GITHUB_REF_NAME) \ . -endif +else docker build \ --no-cache \ - -t ${IMAGE_NAME}:latest \ + --build-arg GO_VERSION=$(GO_VERSION) \ + -t $(IMAGE_NAME):latest \ . +endif push-docker: ifdef GITHUB_REF_NAME From fde7cfecb24692ebfcb458b432cab523f87e3376 Mon Sep 17 00:00:00 2001 From: Mughees2001 Date: Sun, 9 Feb 2025 02:21:45 -0500 Subject: [PATCH 2/9] fix: removed a line space --- Makefile | 1 - 1 file changed, 1 deletion(-) diff --git a/Makefile b/Makefile index 3106c22..3215256 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,6 @@ BINARY_NAME=harpoon BINARY_DIR=./bin OUTPUT_DIR=./output IMAGE_NAME?=alegrey91/harpoon - GO_VERSION := $(shell grep '^toolchain' go.mod | awk '{print $$2}' | sed 's/go//') From 1281952f6a743aa69e1d1f2f8e611440c8db4d04 Mon Sep 17 00:00:00 2001 From: Mughees2001 Date: Sun, 9 Feb 2025 02:39:40 -0500 Subject: [PATCH 3/9] chore: updated go version inside testcases to match with main branch --- tests/testcases/example-app/Makefile | 7 +++++-- tests/testcases/example-app/go.mod | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/testcases/example-app/Makefile b/tests/testcases/example-app/Makefile index c833813..d0846c1 100644 --- a/tests/testcases/example-app/Makefile +++ b/tests/testcases/example-app/Makefile @@ -1,3 +1,6 @@ +# Optionally extract the Go version from go.mod (if a toolchain line exists) +GO_VERSION := $(shell grep '^toolchain' go.mod | awk '{print $$2}' | sed 's/go//') + BINARY_NAME=example-app BINARY_DIR=bin UNIT_TEST_DIR=/tmp/unit @@ -21,8 +24,8 @@ run: test: unit-test -# here we are compiling the _test package(s) we want to test, -# so we are able to run manually unsing the `strace` utility. +# Here we are compiling the _test package(s) we want to test, +# so we are able to run manually using the `strace` utility. unit-test: rm -rf ${UNIT_TEST_DIR} mkdir ${UNIT_TEST_DIR} diff --git a/tests/testcases/example-app/go.mod b/tests/testcases/example-app/go.mod index d5825f3..5140ffc 100644 --- a/tests/testcases/example-app/go.mod +++ b/tests/testcases/example-app/go.mod @@ -1,6 +1,7 @@ module github.com/alegrey91/seccomp-test-coverage -go 1.20 +go 1.23 +toolchain go1.23.2 require github.com/spf13/cobra v1.7.0 From 859e32ad976d569d752918b5d06c508dbadf0f70 Mon Sep 17 00:00:00 2001 From: Mughees2001 Date: Sun, 9 Feb 2025 03:35:23 -0500 Subject: [PATCH 4/9] fix: Go version will be now picked from go.mod file across repo --- .github/workflows/build-and-release.yaml | 1 - .github/workflows/build.yaml | 1 - .github/workflows/tests.yaml | 1 - 3 files changed, 3 deletions(-) diff --git a/.github/workflows/build-and-release.yaml b/.github/workflows/build-and-release.yaml index 4fbc439..bcfd93a 100644 --- a/.github/workflows/build-and-release.yaml +++ b/.github/workflows/build-and-release.yaml @@ -17,7 +17,6 @@ jobs: - name: Get Go version from go.mod id: get_go_version run: | - # Extract the Go version from the "toolchain" line in go.mod (e.g. "toolchain go1.23.2" becomes "1.23.2") go_version=$(grep '^toolchain' go.mod | awk '{print $2}' | sed 's/go//') echo "go_version=$go_version" >> $GITHUB_OUTPUT diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 9a52408..7548fbe 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -15,7 +15,6 @@ jobs: - name: Get Go version from go.mod id: get_go_version run: | - # Extract the Go version from the "toolchain" line (e.g. "toolchain go1.23.2" becomes "1.23.2") go_version=$(grep '^toolchain' go.mod | awk '{print $2}' | sed 's/go//') echo "go_version=$go_version" >> $GITHUB_OUTPUT diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 19db56b..bbc87f9 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -16,7 +16,6 @@ jobs: - name: Get Go version from go.mod id: get_go_version run: | - # Extract the version from the toolchain line (e.g. "toolchain go1.23.2" becomes "1.23.2") go_version=$(grep '^toolchain' go.mod | awk '{print $2}' | sed 's/go//') echo "go_version=$go_version" >> $GITHUB_OUTPUT From f9038ab766778c673b6fab87593106e9df1e3d9c Mon Sep 17 00:00:00 2001 From: Mughees2001 Date: Sun, 9 Feb 2025 15:04:40 -0500 Subject: [PATCH 5/9] fix: Go version will be now picked from go.mod file across repo --- .github/workflows/build-and-release.yaml | 24 +++---- .github/workflows/build.yaml | 14 ++-- .github/workflows/tests.yaml | 91 +++++++++++++----------- Dockerfile | 2 +- Makefile | 2 +- 5 files changed, 65 insertions(+), 68 deletions(-) diff --git a/.github/workflows/build-and-release.yaml b/.github/workflows/build-and-release.yaml index bcfd93a..3264ad7 100644 --- a/.github/workflows/build-and-release.yaml +++ b/.github/workflows/build-and-release.yaml @@ -12,31 +12,25 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Checkout code - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 - + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # ratchet:actions/checkout@v4 - name: Get Go version from go.mod id: get_go_version run: | go_version=$(grep '^toolchain' go.mod | awk '{print $2}' | sed 's/go//') - echo "go_version=$go_version" >> $GITHUB_OUTPUT - - name: Set up Go - uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a + uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # ratchet:actions/setup-go@v5 with: go-version: ${{ steps.get_go_version.outputs.go_version }} - - name: Install Dependencies run: | sudo apt update sudo apt install -y libbpf-dev sudo apt install -y libseccomp-dev - - name: Build and Test run: | make build-gh - - name: Upload Artifact - uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b + uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b # ratchet:actions/upload-artifact@v4 with: name: harpoon path: bin/harpoon @@ -46,13 +40,13 @@ jobs: runs-on: ubuntu-latest steps: - name: Download Artifact - uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 + uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # ratchet:actions/download-artifact@v4 with: name: harpoon path: ./ - name: Create Release id: create_release - uses: softprops/action-gh-release@e7a8f85e1c67a31e6ed99a94b41bd0b71bbee6b8 + uses: softprops/action-gh-release@e7a8f85e1c67a31e6ed99a94b41bd0b71bbee6b8 # ratchet:softprops/action-gh-release@v2 with: files: | harpoon @@ -66,10 +60,10 @@ jobs: packages: write steps: - name: Checkout code - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 + uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # ratchet:actions/checkout@v3 - name: Log in to Docker Hub - uses: docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc + uses: docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc # ratchet:docker/login-action@v2 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }} @@ -87,8 +81,8 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Build Docker image (GHCR) + - name: Build Docker image run: IMAGE_NAME="ghcr.io/alegrey91/harpoon" make build-docker - - name: Push Docker image to GHCR + - name: Push Docker image to Docker Hub run: IMAGE_NAME="ghcr.io/alegrey91/harpoon" make push-docker diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 7548fbe..c6b5d50 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -10,24 +10,20 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Checkout code - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 - + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # ratchet:actions/checkout@v4 - name: Get Go version from go.mod id: get_go_version run: | go_version=$(grep '^toolchain' go.mod | awk '{print $2}' | sed 's/go//') - echo "go_version=$go_version" >> $GITHUB_OUTPUT - - name: Set up Go - uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a + uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # ratchet:actions/setup-go@v5 with: go-version: ${{ steps.get_go_version.outputs.go_version }} - - name: Install BCC Dependencies run: | sudo apt update sudo apt install -y libbpf-dev # Install libbpf dependencies - sudo apt install -y libseccomp-dev # Install Seccomp dependencies - + sudo apt install -y libseccomp-dev # Install Seccomp dependencies - name: Build and Test - run: make build-gh + run: |- + make build-gh \ No newline at end of file diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index bbc87f9..23d1afc 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -8,19 +8,16 @@ on: jobs: unit-test: + runs-on: ubuntu-22.04 steps: - - name: Checkout code - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 - + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # ratchet:actions/checkout@v4 - name: Get Go version from go.mod id: get_go_version run: | go_version=$(grep '^toolchain' go.mod | awk '{print $2}' | sed 's/go//') - echo "go_version=$go_version" >> $GITHUB_OUTPUT - - name: Set up Go - uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a + uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # ratchet:actions/setup-go@v5 with: go-version: ${{ steps.get_go_version.outputs.go_version }} @@ -48,27 +45,21 @@ jobs: -args -test.gocoverdir=/tmp/unit/ - name: Upload cover profiles - uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b + uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b # ratchet:actions/upload-artifact@v4 with: name: unit-test path: /tmp/unit/ integration-test: + runs-on: ubuntu-22.04 steps: - - name: Checkout code - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 - - - name: Get Go version from go.mod - id: get_go_version - run: | - go_version=$(grep '^toolchain' go.mod | awk '{print $2}' | sed 's/go//') - echo "go_version=$go_version" >> $GITHUB_OUTPUT + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # ratchet:actions/checkout@v4 - name: Set up Go - uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a + uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # ratchet:actions/setup-go@v5 with: - go-version: ${{ steps.get_go_version.outputs.go_version }} + go-version: '1.21' - name: Install Dependencies run: | @@ -90,55 +81,71 @@ jobs: - name: Run integration test run: | mkdir -p /tmp/integration - # We run integration tests one-by-one to avoid parallel issues + # we have to run integration tests one-by-one + # otherwhise they will run in parallel. + # since harpoon apply network forwards, these could + # interact with each other and make the test fail. go test \ -exec sudo \ -cover \ -v main_test.go \ -args -test.gocoverdir=/tmp/integration/ - - name: Upload cover profiles - uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b + uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b # ratchet:actions/upload-artifact@v4 with: name: integration-test path: /tmp/integration/ - code-coverage: runs-on: ubuntu-22.04 needs: [unit-test, integration-test] steps: - - name: Checkout code - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 - - - name: Get Go version from go.mod - id: get_go_version - run: | - go_version=$(grep '^toolchain' go.mod | awk '{print $2}' | sed 's/go//') - echo "go_version=$go_version" >> $GITHUB_OUTPUT - - - name: Download Unit Test Artifact - uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # ratchet:actions/checkout@v4 + - uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # ratchet:actions/download-artifact@v4 with: name: unit-test path: /tmp/unit-test - - - name: Download Integration Test Artifact - uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 + - uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # ratchet:actions/download-artifact@v4 with: name: integration-test path: /tmp/integration-test + - name: list files + run: |2 - - name: List files - run: | ls -lah /tmp/unit-test ls -lah /tmp/integration-test - - name: Set up Go - uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a + uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # ratchet:actions/setup-go@v5 with: - go-version: ${{ steps.get_go_version.outputs.go_version }} + go-version: '1.21' - name: Calculate total coverage run: | - go tool covdata textfmt -i=/tmp/unit-test,/tmp/integration-test -o=code-coverage - go tool cover -func code-coverage + go tool \ + covdata \ + textfmt \ + -i=/tmp/unit-test,/tmp/integration-test \ + -o=code-coverage + go tool \ + cover \ + -func code-coverage + + + + + + + + + + + + + + + + + + + + + diff --git a/Dockerfile b/Dockerfile index 5e94dd4..e31742c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -49,4 +49,4 @@ COPY --from=builder /workspace/bin/harpoon . # --pid=host \ # -v /sys/kernel/debug/:/sys/kernel/debug:rw \ # harpoon:latest -ENTRYPOINT ["/bin/bash"] +ENTRYPOINT ["/bin/bash"] \ No newline at end of file diff --git a/Makefile b/Makefile index 3215256..8e60d09 100644 --- a/Makefile +++ b/Makefile @@ -104,4 +104,4 @@ install: clean: rm -rf ${OUTPUT_DIR} rm -rf ${BINARY_DIR} - rm -rf ./libbpfgo + rm -rf ./libbpfgo \ No newline at end of file From 72c7c4e5c48e9ff3aac8a936a3878fb6c84d2eff Mon Sep 17 00:00:00 2001 From: Mughees2001 Date: Mon, 10 Feb 2025 14:11:46 -0500 Subject: [PATCH 6/9] fix: fixed go versions in test.yaml and fixed Dockerfile --- .github/workflows/tests.yaml | 15 ++++++++++++--- Dockerfile | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 23d1afc..8abff82 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -55,11 +55,15 @@ jobs: runs-on: ubuntu-22.04 steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # ratchet:actions/checkout@v4 - + - name: Get Go version from go.mod + id: get_go_version + run: | + go_version=$(grep '^toolchain' go.mod | awk '{print $2}' | sed 's/go//') + - name: Set up Go uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # ratchet:actions/setup-go@v5 with: - go-version: '1.21' + go-version: ${{ steps.get_go_version.outputs.go_version }} - name: Install Dependencies run: | @@ -113,10 +117,15 @@ jobs: ls -lah /tmp/unit-test ls -lah /tmp/integration-test + - name: Get Go version from go.mod + id: get_go_version + run: | + go_version=$(grep '^toolchain' go.mod | awk '{print $2}' | sed 's/go//') + - name: Set up Go uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # ratchet:actions/setup-go@v5 with: - go-version: '1.21' + go-version: ${{ steps.get_go_version.outputs.go_version }} - name: Calculate total coverage run: | diff --git a/Dockerfile b/Dockerfile index e31742c..5375241 100644 --- a/Dockerfile +++ b/Dockerfile @@ -38,7 +38,7 @@ RUN apt-get update && \ libelf1 && \ rm -rf /var/lib/apt/lists/* -COPY --from=builder /workspace/bin/harpoon . +COPY bin/harpoon . # run it with the following command: # docker run \ From d8c759c4460e7a8550890b481021e7e7c69484eb Mon Sep 17 00:00:00 2001 From: Mughees2001 Date: Tue, 11 Feb 2025 14:14:51 -0500 Subject: [PATCH 7/9] chore: restored the dockerfile --- Dockerfile | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 5375241..733d55c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,5 @@ # Minimal Base Image -ARG GO_VERSION=1.23.2 -FROM golang:${GO_VERSION} AS builder +FROM golang:1.23.2 AS builder WORKDIR /workspace @@ -38,8 +37,7 @@ RUN apt-get update && \ libelf1 && \ rm -rf /var/lib/apt/lists/* -COPY bin/harpoon . - +COPY --from=builder /workspace/bin/harpoon . # run it with the following command: # docker run \ # -it \ From 5f4ccd093128233dabeb7dc12dd59abc0bc92c54 Mon Sep 17 00:00:00 2001 From: Mughees2001 Date: Tue, 11 Feb 2025 14:16:44 -0500 Subject: [PATCH 8/9] chore: restored the dockerfile --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index 733d55c..34f201d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -38,6 +38,7 @@ RUN apt-get update && \ rm -rf /var/lib/apt/lists/* COPY --from=builder /workspace/bin/harpoon . + # run it with the following command: # docker run \ # -it \ From 289566d8849df613a294412d8469a3a8fecad8e2 Mon Sep 17 00:00:00 2001 From: Mughees2001 Date: Tue, 11 Feb 2025 14:47:18 -0500 Subject: [PATCH 9/9] refact: centralize Go version retrieval in Makefile --- .github/workflows/build-and-release.yaml | 2 +- .github/workflows/build.yaml | 4 ++-- .github/workflows/tests.yaml | 8 ++++---- Makefile | 5 ++++- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build-and-release.yaml b/.github/workflows/build-and-release.yaml index 3264ad7..1439235 100644 --- a/.github/workflows/build-and-release.yaml +++ b/.github/workflows/build-and-release.yaml @@ -16,7 +16,7 @@ jobs: - name: Get Go version from go.mod id: get_go_version run: | - go_version=$(grep '^toolchain' go.mod | awk '{print $2}' | sed 's/go//') + go_version=$(make go-version) - name: Set up Go uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # ratchet:actions/setup-go@v5 with: diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index c6b5d50..8bd6919 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -11,10 +11,10 @@ jobs: steps: - name: Checkout code uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # ratchet:actions/checkout@v4 - - name: Get Go version from go.mod + - name: Get Go version from Makefile id: get_go_version run: | - go_version=$(grep '^toolchain' go.mod | awk '{print $2}' | sed 's/go//') + go_version=$(make go-version) - name: Set up Go uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # ratchet:actions/setup-go@v5 with: diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 8abff82..2a5eadb 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -12,10 +12,10 @@ jobs: runs-on: ubuntu-22.04 steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # ratchet:actions/checkout@v4 - - name: Get Go version from go.mod + - name: Get Go version from Make file id: get_go_version run: | - go_version=$(grep '^toolchain' go.mod | awk '{print $2}' | sed 's/go//') + go_version=$(make go-version) - name: Set up Go uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # ratchet:actions/setup-go@v5 with: @@ -58,7 +58,7 @@ jobs: - name: Get Go version from go.mod id: get_go_version run: | - go_version=$(grep '^toolchain' go.mod | awk '{print $2}' | sed 's/go//') + go_version=$(make go-version) - name: Set up Go uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # ratchet:actions/setup-go@v5 @@ -120,7 +120,7 @@ jobs: - name: Get Go version from go.mod id: get_go_version run: | - go_version=$(grep '^toolchain' go.mod | awk '{print $2}' | sed 's/go//') + go_version=$(make go-version) - name: Set up Go uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # ratchet:actions/setup-go@v5 diff --git a/Makefile b/Makefile index 8e60d09..114cf7a 100644 --- a/Makefile +++ b/Makefile @@ -104,4 +104,7 @@ install: clean: rm -rf ${OUTPUT_DIR} rm -rf ${BINARY_DIR} - rm -rf ./libbpfgo \ No newline at end of file + rm -rf ./libbpfgo + +go-version: + @grep '^toolchain' go.mod | awk '{print $$2}' | sed 's/go//'