diff --git a/.github/workflows/binary_branch.yaml b/.github/workflows/binary_branch.yaml index b6f0a3a..8fe48c8 100644 --- a/.github/workflows/binary_branch.yaml +++ b/.github/workflows/binary_branch.yaml @@ -29,7 +29,13 @@ jobs: - name: test run: go test ./... -v - name: build - run: go build -o ${{ matrix.artifact_name }} cmd/flowctl/main.go + run: | + go build -o ${{ matrix.artifact_name }} -ldflags "\ + -X github.com/wide-vsix/linux-flow-exporter/pkg/util.gitSHA=$(git rev-parse HEAD) \ + -X github.com/wide-vsix/linux-flow-exporter/pkg/util.gitBranch=$(git symbolic-ref HEAD | sed -e 's#refs/heads/##g') \ + -X github.com/wide-vsix/linux-flow-exporter/pkg/util.gitTag=none \ + -X github.com/wide-vsix/linux-flow-exporter/pkg/util.buildDate=$(date '+%Y/%m/%d-%H:%M:%S-%Z') \ + " cmd/flowctl/main.go - name: upload uses: svenstaro/upload-release-action@v2 with: diff --git a/.github/workflows/binary_release.yaml b/.github/workflows/binary_release.yaml index 2e36ba8..7466034 100644 --- a/.github/workflows/binary_release.yaml +++ b/.github/workflows/binary_release.yaml @@ -29,7 +29,14 @@ jobs: - name: test run: go test ./... -v - name: build - run: go build -o ${{ matrix.artifact_name }} cmd/flowctl/main.go + run: | + go build -o ${{ matrix.artifact_name }} -ldflags "\ + -X github.com/wide-vsix/linux-flow-exporter/pkg/util.gitSHA=$(git rev-parse HEAD) \ + -X github.com/wide-vsix/linux-flow-exporter/pkg/util.gitBranch=none \ + -X github.com/wide-vsix/linux-flow-exporter/pkg/util.gitTag=$(git describe --tags --abbrev=0) \ + -X github.com/wide-vsix/linux-flow-exporter/pkg/util.buildDate=$(date '+%Y/%m/%d-%H:%M:%S-%Z') \ + " cmd/flowctl/main.go + - name: upload uses: svenstaro/upload-release-action@v2 with: diff --git a/.github/workflows/image_branch.yaml b/.github/workflows/image_branch.yaml index 2219d69..5bde98a 100644 --- a/.github/workflows/image_branch.yaml +++ b/.github/workflows/image_branch.yaml @@ -22,8 +22,13 @@ jobs: - name: push with branch name id: run_docker_push_with_branch_name - run: > - docker build -t ghcr.io/wide-vsix/linux-flow-exporter:branch-main . - && docker push ghcr.io/wide-vsix/linux-flow-exporter:branch-main + run: | + docker build \ + --build-arg GIT_SHA=$(git rev-parse HEAD) \ + --build-arg GIT_BRANCH=$(git symbolic-ref HEAD | sed -e 's#refs/heads/##g') \ + --build-arg GIT_TAG=none \ + --build-arg BUILD_DATE=$(date '+%Y/%m/%d-%H:%M:%S-%Z') \ + --tag ghcr.io/wide-vsix/linux-flow-exporter:branch-main . + docker push ghcr.io/wide-vsix/linux-flow-exporter:branch-main env: BUILDKIT: 1 diff --git a/.github/workflows/image_release.yaml b/.github/workflows/image_release.yaml index 4de77f5..c3daf48 100644 --- a/.github/workflows/image_release.yaml +++ b/.github/workflows/image_release.yaml @@ -23,7 +23,12 @@ jobs: id: run_docker_push_with_branch_name run: | VERSION=$(echo ${{ github.ref }} | sed -e "s#refs/tags/##g") - docker build -t ghcr.io/wide-vsix/linux-flow-exporter:$VERSION . + docker build \ + --build-arg GIT_SHA=$(git rev-parse HEAD) \ + --build-arg GIT_BRANCH=nona \ + --build-arg GIT_TAG=$VERSION \ + --build-arg BUILD_DATE=$(date '+%Y/%m/%d-%H:%M:%S-%Z') \ + --tag ghcr.io/wide-vsix/linux-flow-exporter:$VERSION . docker push ghcr.io/wide-vsix/linux-flow-exporter:$VERSION env: BUILDKIT: 1 diff --git a/Dockerfile b/Dockerfile index ac5e5ed..123bf9e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,9 +20,18 @@ RUN cd iproute2-${IPROUTE2_VERSION} && ./configure --libbpf_force=on --libbpf_di # STAGE(flowctl-dist) FROM golang:1.17 as flowctl-dist +ARG GIT_SHA=unknown +ARG GIT_BRANCH=unknown +ARG GIT_TAG=unknown +ARG BUILD_DATE=unknown WORKDIR /opt COPY ./ ./ -RUN CGO_ENABLED=0 go build -o ./bin/flowctl ./cmd/flowctl/main.go +RUN CGO_ENABLED=0 go build -o ./bin/flowctl -ldflags "\ + -X github.com/wide-vsix/linux-flow-exporter/pkg/util.gitSHA=$GIT_SHA \ + -X github.com/wide-vsix/linux-flow-exporter/pkg/util.gitBranch=$GIT_BRANCH \ + -X github.com/wide-vsix/linux-flow-exporter/pkg/util.gitTag=none \ + -X github.com/wide-vsix/linux-flow-exporter/pkg/util.buildDate=$BUILD_DATE \ + " ./cmd/flowctl/main.go # STAGE(rootfs) FROM ${UBUNTU_IMAGE} as rootfs