Skip to content

Commit

Permalink
*: improve build workflow (zilliztech#555)
Browse files Browse the repository at this point in the history
Signed-off-by: huanghaoyuanhhy <[email protected]>
  • Loading branch information
huanghaoyuanhhy authored Feb 25, 2025
1 parent 2eb37e7 commit 2abf8c7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ jobs:
run: |
echo "VERSION=$(git describe --tags --always)" >> $GITHUB_OUTPUT
echo "COMMIT=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
echo "DATE=$(date +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
- name: Build and push
uses: docker/build-push-action@v6
Expand All @@ -79,4 +78,3 @@ jobs:
build-args: |
VERSION=${{ steps.build_info.outputs.VERSION }}
COMMIT=${{ steps.build_info.outputs.COMMIT }}
DATE=${{ steps.build_info.outputs.DATE }}
10 changes: 5 additions & 5 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ builds:
- arm64
ldflags:
- -w -s
- -X main.version={{ .Version }}
- -X main.commit={{ .Commit }}
- -X main.date={{ .Date }}
- -X github.com/zilliztech/milvus-backup/version.Version={{ .Version }}
- -X github.com/zilliztech/milvus-backup/version.Commit={{ .Commit }}
- -X github.com/zilliztech/milvus-backup/version.Date={{ .Date }}

archives:
- format: tar.gz
- formats: ['tar.gz']
# this name template makes the OS and Arch compatible with the results of uname.
name_template: >-
{{ .ProjectName }}_
Expand All @@ -33,7 +33,7 @@ archives:
checksum:
name_template: "checksums.txt"
snapshot:
name_template: "{{ incpatch .Version }}-next"
version_template: "{{ incpatch .Version }}-next"

brews:
- name: milvus-backup
Expand Down
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ ENV CGO_ENABLED=0

ARG VERSION=0.0.1
ARG COMMIT=unknown
ARG DATE=unknown

WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download

COPY . .
RUN go build -ldflags="-X 'main.version=$VERSION' -X 'main.commit=$COMMIT' -X 'main.date=$DATE'" -o /app/milvus-backup
RUN make build

FROM alpine:3.17

Expand Down
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Variables
BINARY_NAME=milvus-backup
PKG := github.com/zilliztech/milvus-backup
VERSION=$(shell git describe --tags --always)
COMMIT=$(shell git rev-parse --short HEAD)
BUILD_VERSION=$(if $(VERSION),$(VERSION),$(shell git describe --tags --always))
BUILD_COMMIT=$(if $(COMMIT),$(COMMIT),$(shell git rev-parse --short HEAD))
DATE=$(shell date -u '+%Y-%m-%dT%H:%M:%SZ')

LDFLAGS += -X "$(PKG)/version.Version=$(VERSION)"
LDFLAGS += -X "$(PKG)/version.Commit=$(COMMIT)"
LDFLAGS += -X "$(PKG)/version.Version=$(BUILD_VERSION)"
LDFLAGS += -X "$(PKG)/version.Commit=$(BUILD_COMMIT)"
LDFLAGS += -X "$(PKG)/version.Date=$(DATE)"

# Default target
Expand All @@ -19,8 +19,8 @@ test:
# Build the binary
build:
@echo "Building Backup binary..."
@echo "Version: $(VERSION)"
@echo "Commit: $(COMMIT)"
@echo "Version: $(BUILD_VERSION)"
@echo "Commit: $(BUILD_COMMIT)"
@echo "Date: $(DATE)"
@GO111MODULE=on CGO_ENABLED=0 go build -ldflags '$(LDFLAGS)' -o $(BINARY_NAME)

Expand Down

0 comments on commit 2abf8c7

Please sign in to comment.