Skip to content

Commit

Permalink
Merge pull request #18 from wide-vsix/actions
Browse files Browse the repository at this point in the history
Support version metadata in the binary
  • Loading branch information
slankdev authored Oct 25, 2022
2 parents 580aa3b + 3a3d305 commit d851c69
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 7 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/binary_branch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 8 additions & 1 deletion .github/workflows/binary_release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 8 additions & 3 deletions .github/workflows/image_branch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 6 additions & 1 deletion .github/workflows/image_release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 10 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d851c69

Please sign in to comment.