From c10ea9606e580cb6ce55c99589429522eda5a2ca Mon Sep 17 00:00:00 2001 From: CrazyMax <1951866+crazy-max@users.noreply.github.com> Date: Sun, 3 Nov 2024 18:47:51 +0100 Subject: [PATCH] ci: add bench Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com> --- .github/workflows/ci.yml | 26 ++++++++++++++++++++++++++ Dockerfile | 18 ++++++++++++++++++ docker-bake.hcl | 26 ++++++++++++++++++++++++++ 3 files changed, 70 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e2d075d7..097c8568 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -92,6 +92,32 @@ jobs: flags: unit,${{ matrix.mode }},go-${{ matrix.go }} token: ${{ secrets.CODECOV_TOKEN }} + bench: + runs-on: ubuntu-latest + strategy: + matrix: + go: + - "1.23" + - "1.22" + - "1.21" + mode: + - "root" + - "noroot" + env: + GO_VERSION: ${{ matrix.go }} + steps: + - + name: Checkout + uses: actions/checkout@v4 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - + name: Test + uses: docker/bake-action@v5 + with: + targets: bench-${{ matrix.mode }} + test-os: runs-on: ${{ matrix.os }} strategy: diff --git a/Dockerfile b/Dockerfile index 3a76d341..fc094128 100644 --- a/Dockerfile +++ b/Dockerfile @@ -35,4 +35,22 @@ COPY --from=test /tmp/coverage.txt /coverage-root.txt FROM scratch AS test-noroot-coverage COPY --from=test-noroot /tmp/coverage.txt /coverage-noroot.txt +FROM base AS bench +ARG BENCH_FILE_SIZE +RUN --mount=target=. \ + --mount=target=/go/pkg/mod,type=cache \ + --mount=target=/root/.cache,type=cache \ + CGO_ENABLED=0 xx-go test -benchmem -bench=. -run=^$ ./... && \ + cd bench && CGO_ENABLED=0 xx-go test -benchmem -bench=. -run=^$ ./... + +FROM base AS bench-noroot +RUN mkdir /go/pkg && chmod 0777 /go/pkg +USER 1000:1000 +ARG BENCH_FILE_SIZE +RUN --mount=target=. \ + --mount=target=/go/pkg/mod,type=cache \ + --mount=target=/tmp/.cache,type=cache \ + CGO_ENABLED=0 GOCACHE=/tmp/gocache xx-go test -bench=. -benchmem -run=^$ ./... && \ + cd bench && CGO_ENABLED=0 GOCACHE=/tmp/gocache xx-go test -bench=. -benchmem -run=^$ ./... + FROM build diff --git a/docker-bake.hcl b/docker-bake.hcl index a18986bc..351e2209 100644 --- a/docker-bake.hcl +++ b/docker-bake.hcl @@ -6,6 +6,10 @@ variable "DESTDIR" { default = "./bin" } +variable "BENCH_FILE_SIZE" { + default = null +} + group "default" { targets = ["build"] } @@ -32,6 +36,28 @@ target "test-noroot" { output = ["${DESTDIR}/coverage"] } +group "bench" { + targets = ["test-root", "test-noroot"] +} + +target "bench-root" { + inherits = ["build"] + target = "bench" + output = ["type=cacheonly"] + args = { + BENCH_FILE_SIZE = BENCH_FILE_SIZE + } +} + +target "bench-noroot" { + inherits = ["build"] + target = "bench-noroot" + output = ["type=cacheonly"] + args = { + BENCH_FILE_SIZE = BENCH_FILE_SIZE + } +} + target "lint" { dockerfile = "./hack/dockerfiles/lint.Dockerfile" output = ["type=cacheonly"]