mirror of https://github.com/harness/drone.git
[SCM-117]: Passing version info while building image (#297)
parent
29e12e3e2f
commit
0d922b5354
10
Makefile
10
Makefile
|
@ -11,6 +11,8 @@ endif
|
|||
tools = $(addprefix $(GOBIN)/, golangci-lint goimports govulncheck protoc-gen-go protoc-gen-go-grpc gci)
|
||||
deps = $(addprefix $(GOBIN)/, wire dbmate mockgen)
|
||||
|
||||
LDFLAGS = "-X github.com/harness/gitness/version.GitCommit=${GIT_COMMIT} -X github.com/harness/gitness/version.major=${GITNESS_VERSION_MAJOR} -X github.com/harness/gitness/version.minor=${GITNESS_VERSION_MINOR} -X github.com/harness/gitness/version.patch=${GITNESS_VERSION_PATCH}"
|
||||
|
||||
ifneq (,$(wildcard ./.local.env))
|
||||
include ./.local.env
|
||||
export
|
||||
|
@ -47,19 +49,19 @@ generate: $(mocks) wire mocks/mock_client.go proto
|
|||
|
||||
build: generate ## Build the all-in-one gitness binary
|
||||
@echo "Building Gitness Server"
|
||||
go build -ldflags="-X github.com/harness/gitness/version.GitCommit=${GIT_COMMIT} -X github.com/harness/gitness/version.Version.Major=${GITNESS_VERSION}" -o ./gitness ./cmd/gitness
|
||||
go build -ldflags=${LDFLAGS} -o ./gitness ./cmd/gitness
|
||||
|
||||
harness-build: generate ## Build the all-in-one gitness binary for harness embedded mode
|
||||
@echo "Building Gitness Server for Harness"
|
||||
go build -tags=harness -ldflags="-X github.com/harness/gitness/version.GitCommit=${GIT_COMMIT} -X github.com/harness/gitness/version.Version.Major=${GITNESS_VERSION}" -o ./gitness ./cmd/gitness
|
||||
go build -tags=harness -ldflags=${LDFLAGS} -o ./gitness ./cmd/gitness
|
||||
|
||||
build-gitrpc: generate ## Build the gitrpc binary
|
||||
@echo "Building GitRPC Server"
|
||||
go build -ldflags="-X github.com/harness/gitness/version.GitCommit=${GIT_COMMIT} -X github.com/harness/gitness/version.Version.Major=${GITNESS_VERSION}" -o ./gitrpcserver ./cmd/gitrpcserver
|
||||
go build -ldflags=${LDFLAGS} -o ./gitrpcserver ./cmd/gitrpcserver
|
||||
|
||||
build-githook: generate ## Build the githook binary
|
||||
@echo "Building GitHook Binary"
|
||||
go build -ldflags="-X github.com/harness/gitness/version.GitCommit=${GIT_COMMIT} -X github.com/harness/gitness/version.Version.Major=${GITNESS_VERSION}" -o ./githook ./cmd/githook
|
||||
go build -ldflags=${LDFLAGS} -o ./githook ./cmd/githook
|
||||
|
||||
test: generate ## Run the go tests
|
||||
@echo "Running tests"
|
||||
|
|
|
@ -22,7 +22,9 @@ ENV CGO_ENABLED=1 \
|
|||
|
||||
# build
|
||||
ARG GIT_COMMIT
|
||||
ARG GITNESS_VERSION
|
||||
ARG GITNESS_VERSION_MAJOR
|
||||
ARG GITNESS_VERSION_MINOR
|
||||
ARG GITNESS_VERSION_PATCH
|
||||
RUN make harness-build
|
||||
|
||||
### Pull CA Certs
|
||||
|
|
|
@ -22,7 +22,9 @@ ENV CGO_ENABLED=0 \
|
|||
|
||||
# build
|
||||
ARG GIT_COMMIT
|
||||
ARG GITNESS_VERSION
|
||||
ARG GITNESS_VERSION_MAJOR
|
||||
ARG GITNESS_VERSION_MINOR
|
||||
ARG GITNESS_VERSION_PATCH
|
||||
RUN make build-gitrpc
|
||||
RUN make build-githook
|
||||
|
||||
|
|
|
@ -5,30 +5,48 @@
|
|||
// Package version provides the version number.
|
||||
package version
|
||||
|
||||
import "github.com/coreos/go-semver/semver"
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/coreos/go-semver/semver"
|
||||
)
|
||||
|
||||
var (
|
||||
// GitRepository is the git repository that was compiled.
|
||||
GitRepository string
|
||||
// GitCommit is the git commit that was compiled.
|
||||
GitCommit string
|
||||
// Major is for an API incompatible changes.
|
||||
Major int64 = 1
|
||||
// Minor is for functionality in a backwards-compatible manner.
|
||||
Minor int64
|
||||
// Patch is for backwards-compatible bug fixes.
|
||||
Patch int64
|
||||
)
|
||||
|
||||
var (
|
||||
// major is for an API incompatible changes.
|
||||
major string
|
||||
// minor is for functionality in a backwards-compatible manner.
|
||||
minor string
|
||||
// patch is for backwards-compatible bug fixes.
|
||||
patch string
|
||||
// Pre indicates prerelease.
|
||||
Pre = ""
|
||||
// Dev indicates development branch. Releases will be empty string.
|
||||
Dev string
|
||||
|
||||
// Version is the specification version that the package types support.
|
||||
Version = semver.Version{
|
||||
Major: parseVersionNumber(major),
|
||||
Minor: parseVersionNumber(minor),
|
||||
Patch: parseVersionNumber(patch),
|
||||
PreRelease: semver.PreRelease(Pre),
|
||||
Metadata: Dev,
|
||||
}
|
||||
)
|
||||
|
||||
// Version is the specification version that the package types support.
|
||||
var Version = semver.Version{
|
||||
Major: Major,
|
||||
Minor: Minor,
|
||||
Patch: Patch,
|
||||
PreRelease: semver.PreRelease(Pre),
|
||||
Metadata: Dev,
|
||||
func parseVersionNumber(versionNum string) int64 {
|
||||
if versionNum == "" {
|
||||
return 0
|
||||
}
|
||||
i, err := strconv.ParseInt(versionNum, 10, 64)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue