Skip to content

Commit

Permalink
fix(docker): version match git tag
Browse files Browse the repository at this point in the history
  • Loading branch information
lidel committed Jun 11, 2024
1 parent 6ff0b51 commit 103bf3f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
11 changes: 8 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,26 @@ LABEL org.opencontainers.image.licenses=MIT+APACHE_2.0
ARG TARGETPLATFORM TARGETOS TARGETARCH

ENV GOPATH /go
ENV GOCACHE /root/.cache/go-build
ENV SRC_PATH $GOPATH/src/github.com/ipfs/rainbow
ENV GO111MODULE on
ENV GOPROXY https://proxy.golang.org

COPY go.* $SRC_PATH/
WORKDIR $SRC_PATH
RUN go mod download
RUN --mount=type=cache,target=/go/pkg/mod \
go mod download

COPY . $SRC_PATH
RUN git config --global --add safe.directory /go/src/github.com/ipfs/rainbow

RUN --mount=target=. \
--mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg \
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -o $GOPATH/bin/rainbow
--mount=type=cache,target=/go/pkg/mod \
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH \
go build \
-ldflags "-X main.gitTag=$(git describe --exact-match --tags HEAD 2>/dev/null || true)" \
-o $GOPATH/bin/rainbow

#------------------------------------------------------
FROM debian:bookworm-slim
Expand Down
20 changes: 17 additions & 3 deletions version.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,17 @@ import (
"time"
)

var name = "rainbow"
var version = buildVersion()
var userAgent = name + "/" + version
var (
name = "rainbow"
version string
userAgent string
gitTag string
)

func init() {
version = buildVersion()
userAgent = name + "/" + version
}

func buildVersion() string {
var revision string
Expand All @@ -32,6 +40,12 @@ func buildVersion() string {
if dirty {
revision += "-dirty"
}
if gitTag != "" {
if revision != "" {
gitTag += "/" + day + "-" + revision

Check warning on line 45 in version.go

View check run for this annotation

Codecov / codecov/patch

version.go#L44-L45

Added lines #L44 - L45 were not covered by tests
}
return gitTag

Check warning on line 47 in version.go

View check run for this annotation

Codecov / codecov/patch

version.go#L47

Added line #L47 was not covered by tests
}
if revision != "" {
return day + "-" + revision
}
Expand Down

0 comments on commit 103bf3f

Please sign in to comment.