diff --git a/.github/workflows/docker-image.yaml b/.github/workflows/docker-image.yaml index 0039e149..bb07057c 100644 --- a/.github/workflows/docker-image.yaml +++ b/.github/workflows/docker-image.yaml @@ -1,10 +1,17 @@ name: docker-image on: - push: - branches: [main] workflow_call: - + inputs: + release: + required: true + type: string + commit: + required: true + type: string + build_date: + required: true + type: string jobs: docker-image: runs-on: ubuntu-22.04 @@ -47,3 +54,7 @@ jobs: push: true tags: ${{ steps.meta_falcoctl.outputs.tags }} file: ./build/Dockerfile + build-args: | + RELEASE=${{ inputs.release }} + COMMIT=${{ inputs.commit }} + BUILD_DATE=${{ inputs.build_date }} diff --git a/.github/workflows/integration.yaml b/.github/workflows/integration.yaml index 118a343b..80b54d65 100644 --- a/.github/workflows/integration.yaml +++ b/.github/workflows/integration.yaml @@ -53,6 +53,31 @@ jobs: path: ./falcoctl-${{ matrix.goos }}-${{ matrix.goarch }}.tar.gz retention-days: 1 + docker-configure: + if: ${{ github.event_name == 'push' }} + runs-on: ubuntu-22.04 + outputs: + release: ${{ steps.vars.outputs.release }} + commit: ${{ steps.vars.outputs.commit }} + build_date: ${{ steps.vars.outputs.build_date }} + steps: + - name: Set version fields + id: vars + run: | + echo "release=${{ github.sha }}" >> $GITHUB_OUTPUT + echo "commit=${{ github.sha }}" >> $GITHUB_OUTPUT + echo "build_date=$(date -u '+%Y-%m-%d_%H:%M:%S')" >> $GITHUB_OUTPUT + + docker-image: + if: ${{ github.event_name == 'push' }} + needs: docker-configure + uses: ./.github/workflows/docker-image.yaml + secrets: inherit + with: + release: ${{ needs.docker-configure.outputs.release }} + commit: ${{ needs.docker-configure.outputs.commit }} + build_date: ${{ needs.docker-configure.outputs.build_date }} + test: needs: build runs-on: ubuntu-latest diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index f7e37b9d..e833f6ab 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -34,6 +34,26 @@ jobs: args: release --rm-dist env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + docker-configure: + runs-on: ubuntu-22.04 + outputs: + release: ${{ steps.vars.outputs.release }} + commit: ${{ steps.vars.outputs.commit }} + build_date: ${{ steps.vars.outputs.build_date }} + steps: + - name: Set version fields + id: vars + run: | + echo "release=$(echo $GITHUB_REF | cut -d / -f 3 | sed 's/^v//')" >> $GITHUB_OUTPUT + echo "commit=${{ github.sha }}" >> $GITHUB_OUTPUT + echo "build_date=$(date -u '+%Y-%m-%d_%H:%M:%S')" >> $GITHUB_OUTPUT + docker-image: + needs: docker-configure uses: ./.github/workflows/docker-image.yaml secrets: inherit + with: + release: ${{ needs.docker-configure.outputs.release }} + commit: ${{ needs.docker-configure.outputs.commit }} + build_date: ${{ needs.docker-configure.outputs.build_date }} diff --git a/.goreleaser.yml b/.goreleaser.yml index 90bf2b60..529b8b25 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -18,9 +18,9 @@ builds: goarch: 386 ldflags: | - -X github.com/falcosecurity/falcoctl/pkg/version.buildDate={{ .Date }} - -X github.com/falcosecurity/falcoctl/pkg/version.gitCommit={{ .Commit }} - -X github.com/falcosecurity/falcoctl/pkg/version.semVersion={{ if .IsSnapshot }}{{ .Commit }}{{ else }}{{ .Version }}{{ end }} + -X github.com/falcosecurity/falcoctl/cmd/version.buildDate={{ .Date }} + -X github.com/falcosecurity/falcoctl/cmd/version.gitCommit={{ .Commit }} + -X github.com/falcosecurity/falcoctl/cmd/version.semVersion={{ if .IsSnapshot }}{{ .Commit }}{{ else }}{{ .Version }}{{ end }} -s -w main: . diff --git a/Makefile b/Makefile index 063597f7..52664a87 100644 --- a/Makefile +++ b/Makefile @@ -10,8 +10,8 @@ GO ?= go DOCKER ?= docker # version settings -RELEASE?=$(shell git rev-parse --short HEAD) -COMMIT?=$(shell git rev-parse --short HEAD) +RELEASE?=$(shell git rev-parse HEAD) +COMMIT?=$(shell git rev-parse HEAD) BUILD_DATE?=$(shell date -u '+%Y-%m-%d_%H:%M:%S') PROJECT?=github.com/falcosecurity/falcoctl @@ -21,9 +21,9 @@ TEST_FLAGS ?= -v -cover# -race .PHONY: falcoctl falcoctl: $(GO) build -ldflags \ - "-X ${PROJECT}/pkg/version.semVersion=${RELEASE} \ - -X ${PROJECT}/pkg/version.gitCommit=${COMMIT} \ - -X ${PROJECT}/pkg/version.buildDate=${BUILD_DATE}" \ + "-X '${PROJECT}/cmd/version.semVersion=${RELEASE}' \ + -X '${PROJECT}/cmd/version.gitCommit=${COMMIT}' \ + -X '${PROJECT}/cmd/version.buildDate=${BUILD_DATE}'" \ -o falcoctl . .PHONY: test @@ -71,4 +71,4 @@ lint: golangci-lint $(GOLANGCILINT) run --new-from-rev main docker: - $(DOCKER) build -f ./build/Dockerfile . + $(DOCKER) build -f ./build/Dockerfile . --build-arg RELEASE=${RELEASE} --build-arg COMMIT=${COMMIT} --build-arg BUILD_DATE=${BUILD_DATE} diff --git a/build/Dockerfile b/build/Dockerfile index b615bfe8..da47e6e7 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -1,15 +1,33 @@ FROM golang:1.19 as builder WORKDIR /tmp/builder +ARG RELEASE +ARG COMMIT +ARG BUILD_DATE +ARG PROJECT=github.com/falcosecurity/falcoctl +RUN test -n "$RELEASE" || ( echo "The RELEASE argument is unset. Aborting" && false ) +RUN test -n "$COMMIT" || ( echo "The COMMIT argument is unset. Aborting" && false ) +RUN test -n "$BUILD_DATE" || ( echo "The BUILD_DATE argument is unset. Aborting" && false ) COPY go.mod ./go.mod COPY go.sum ./go.sum RUN go mod download COPY . ./ -RUN CGO_ENABLED=0 GOOS=$(go env GOOS) GOARCH=$(go env GOARCH) go build -ldflags="-s -w" ./ +RUN CGO_ENABLED=0 \ + GOOS=$(go env GOOS) \ + GOARCH=$(go env GOARCH) \ + go build -ldflags \ + "-s \ + -w \ + -X '${PROJECT}/cmd/version.semVersion=${RELEASE}' \ + -X '${PROJECT}/cmd/version.gitCommit=${COMMIT}' \ + -X '${PROJECT}/cmd/version.buildDate=${BUILD_DATE}'" \ + ./ + +RUN echo ${RELEASE} FROM alpine:3.16.3