Skip to content

Commit 6b77d76

Browse files
committed
✨ Display version and commit at start
1 parent 3729a7f commit 6b77d76

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

.gitlab-ci.yml

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
--frontend=dockerfile.v0 \
2323
--local context=. \
2424
--local dockerfile=. \
25+
--opt build-arg:VERSION=$1 \
26+
--opt build-arg:COMMIT=$CI_COMMIT_SHA \
2527
--output type=image,name=$CI_REGISTRY_IMAGE:$1,push=true
2628
}
2729

Dockerfile

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ RUN go mod download
1717
# Copy the source code into the container
1818
COPY . .
1919

20+
ARG VERSION=dev
21+
2022
# Build the Go application
21-
RUN go build -o automirror .
23+
RUN go build --ldflags "-X 'main.Version=$VERSION' -X 'main.Commit=$COMMIT'" -o automirror .
2224

2325
# Use a minimal base image to run the app
2426
FROM alpine:3.21

main.go

+5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ import (
2222
"gopkg.in/yaml.v3"
2323
)
2424

25+
var Version string
26+
var Commit string
27+
2528
type MirrorDefaults struct {
2629
Except []string `json:"except,omitempty"`
2730
Only []string `json:"only,omitempty"`
@@ -589,6 +592,8 @@ func main() {
589592
return
590593
}
591594

595+
ll.Info("Starting automirror v%s (%s)", Version, Commit)
596+
592597
err := loadEnv()
593598
if err != nil {
594599
fmt.Println("Error loading environment variables:", err)

0 commit comments

Comments
 (0)