Skip to content

Commit

Permalink
fix(build): version info (#13)
Browse files Browse the repository at this point in the history
* fix(build): version info with goreleaser

* fix(build): version info with docker

* fix(build): docker labels
  • Loading branch information
zze0s authored Oct 27, 2024
1 parent 8630574 commit 17d835f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
2 changes: 2 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ builds:
# goarch: arm64
main: ./cmd/distribrr/main.go
binary: distribrr
ldflags:
- -s -w -X github.com/autobrr/distribrr/pkg/version.Version=v{{.Version}} -X github.com/autobrr/distribrr/pkg/version.Commit={{.Commit}} -X github.com/autobrr/distribrr/pkg/version.BuildDate={{.Date}} -X github.com/autobrr/distribrr/pkg/version.BuiltBy=goreleaser'

archives:
- id: distribrr
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile.ci
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ export GOARCH=$TARGETARCH; \
[[ "$GOARCH" == "arm" ]] && [[ "$TARGETVARIANT" == "v6" ]] && export GOARM=6; \
[[ "$GOARCH" == "arm" ]] && [[ "$TARGETVARIANT" == "v7" ]] && export GOARM=7; \
echo $GOARCH $GOOS $GOARM$GOAMD64; \
go build -ldflags "-s -w -X version.Version=${VERSION} -X version.Commit=${REVISION} -X version.BuildDate=${BUILDTIME}" -o /out/bin/distribrr cmd/distribrr/main.go
go build -ldflags "-s -w -X github.com/autobrr/distribrr/pkg/version.Version=${VERSION} -X github.com/autobrr/distribrr/pkg/version.Commit=${REVISION} -X github.com/autobrr/distribrr/pkg/version.BuildDate=${BUILDTIME}" -o /out/bin/distribrr cmd/distribrr/main.go

# build runner
FROM alpine:latest AS runner

LABEL org.opencontainers.image.source = "https://github.com/autobrr/distribrr"
LABEL org.opencontainers.image.base.name = "alpine:latest"
LABEL org.opencontainers.image.source="https://github.com/autobrr/distribrr"
LABEL org.opencontainers.image.base.name="alpine:latest"

ENV HOME="/config" \
XDG_CONFIG_HOME="/config" \
Expand Down
18 changes: 11 additions & 7 deletions pkg/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,24 @@ var (
Version = "dev"
Commit = ""
BuildDate = ""
BuiltBy = ""
Info BuildInfo
)

func init() {
Info = BuildInfo{
Version: Version,
Commit: Commit,
Date: BuildDate,
Version: Version,
Commit: Commit,
Date: BuildDate,
BuildtBy: BuiltBy,
}
}

type BuildInfo struct {
Version string `json:"version"`
Commit string `json:"commit"`
Date string `json:"build_date"`
Version string `json:"version"`
Commit string `json:"commit"`
Date string `json:"build_date"`
BuildtBy string `json:"buildt_by"`
}

func (i BuildInfo) Print(output string) {
Expand All @@ -42,6 +45,7 @@ func (i BuildInfo) Print(output string) {
Version: %s
Commit: %s
Date: %s
`, Version, Commit, BuildDate)
Built by: %s
`, Version, Commit, BuildDate, BuiltBy)
}
}

0 comments on commit 17d835f

Please sign in to comment.