From 50e37875fcdf2b6683009fff3b2618f578280a68 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Mon, 21 Nov 2022 16:25:31 +0100 Subject: [PATCH 1/2] Update bake def, Dockerfile and workflow to release image Signed-off-by: CrazyMax --- .github/workflows/ci.yaml | 45 +++++++++++++++++++++++++++++++++------ Dockerfile | 36 ++++++++++++++++++++----------- docker-bake.hcl | 35 +++++++++++++++++++++++------- 3 files changed, 89 insertions(+), 27 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 84ef8b69..43a9ee8f 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,9 +1,19 @@ name: ci +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + on: push: branches: - 'master' + tags: + - 'v*' + pull_request: + +env: + DOCKERHUB_SLUG: docker/buildkit-syft-scanner jobs: build: @@ -12,6 +22,25 @@ jobs: - name: Checkout uses: actions/checkout@v3 + with: + fetch-depth: 0 + - + name: Docker meta + id: meta + uses: docker/metadata-action@v4 + with: + images: | + ${{ env.DOCKERHUB_SLUG }} + tags: | + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + type=ref,event=pr + type=edge + labels: | + org.opencontainers.image.title=BuildKit Syft scanner + org.opencontainers.image.description=SBOM generation for BuildKit images + org.opencontainers.image.vendor=Docker Inc. - name: Set up QEMU uses: docker/setup-qemu-action@v2 @@ -20,16 +49,18 @@ jobs: uses: docker/setup-buildx-action@v2 - name: Login to DockerHub + if: github.event_name != 'pull_request' uses: docker/login-action@v2 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Build and push - uses: docker/build-push-action@v3 + name: Build + uses: docker/bake-action@v2 with: - push: true - tags: jedevc/buildkit-syft-scanner:latest - cache-to: type=inline - cache-from: type=registry,ref=jedevc/buildkit-syft-scanner:latest - platforms: linux/amd64 + files: | + ./docker-bake.hcl + ${{ steps.meta.outputs.bake-file }} + targets: image + # TODO: enable push when hup repo created + #push: ${{ github.event_name != 'pull_request' }} diff --git a/Dockerfile b/Dockerfile index 09bd4862..0b96d3b9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,24 +1,36 @@ #syntax=docker/dockerfile:1 -FROM --platform=$BUILDPLATFORM tonistiigi/xx:1.1.2 AS xx +ARG GO_VERSION="1.19" +ARG ALPINE_VERSION="3.16" +ARG XX_VERSION="1.1.2" -FROM --platform=$BUILDPLATFORM golang:alpine as build-base +FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx + +FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine AS base COPY --link --from=xx / / ENV CGO_ENABLED=0 - -FROM build-base as build -ARG TARGETPLATFORM +RUN apk add --no-cache file git WORKDIR /src -RUN \ - --mount=type=bind,target=. \ - --mount=type=cache,target=/root/.cache < Date: Mon, 21 Nov 2022 16:39:51 +0100 Subject: [PATCH 2/2] Set project version Signed-off-by: CrazyMax --- Dockerfile | 9 ++++++++- cmd/syft-scanner/main.go | 10 +++++++--- docker-bake.hcl | 7 +++++++ internal/target.go | 7 ++----- version/version.go | 7 +++++++ 5 files changed, 31 insertions(+), 9 deletions(-) create mode 100644 version/version.go diff --git a/Dockerfile b/Dockerfile index 0b96d3b9..bf19a6c8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,9 +13,16 @@ RUN apk add --no-cache file git WORKDIR /src FROM base AS version +ARG GIT_REF RUN --mount=target=. <