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 981f80d
Show file tree
Hide file tree
Showing 2 changed files with 26 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
21 changes: 18 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,13 @@ func buildVersion() string {
if dirty {
revision += "-dirty"
}
if gitTag != "" {
if dirty {

Check warning on line 44 in version.go

View check run for this annotation

Codecov / codecov/patch

version.go#L44

Added line #L44 was not covered by tests
// when commit matched git tag, but there were local changes, append the dev suffix
return gitTag + "/" + day + "-" + revision

Check warning on line 46 in version.go

View check run for this annotation

Codecov / codecov/patch

version.go#L46

Added line #L46 was not covered by tests
}
return gitTag

Check warning on line 48 in version.go

View check run for this annotation

Codecov / codecov/patch

version.go#L48

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

0 comments on commit 981f80d

Please sign in to comment.