Skip to content
This repository was archived by the owner on Apr 2, 2024. It is now read-only.

Commit 066695e

Browse files
Blagoj Atanasovskiatanasovskib
authored andcommitted
Log a version and latest commit hash on startup
Commit hash is set on build.
1 parent a53c5a3 commit 066695e

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed

Dockerfile

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
# Build stage
22
FROM golang:1.14.1-alpine AS builder
3-
COPY ./pkg timescale-prometheus-connector/pkg
4-
COPY ./cmd timescale-prometheus-connector/cmd
5-
COPY ./go.mod timescale-prometheus-connector/go.mod
6-
COPY ./go.sum timescale-prometheus-connector/go.sum
3+
COPY ./.git timescale-prometheus/.git
4+
COPY ./pkg timescale-prometheus/pkg
5+
COPY ./cmd timescale-prometheus/cmd
6+
COPY ./go.mod timescale-prometheus/go.mod
7+
COPY ./go.sum timescale-prometheus/go.sum
78
RUN apk update && apk add --no-cache git \
8-
&& cd timescale-prometheus-connector \
9+
&& cd timescale-prometheus \
910
&& go mod download \
10-
&& CGO_ENABLED=0 go build -a --ldflags '-w' -o /go/timescale-prometheus ./cmd/timescale-prometheus
11+
&& GIT_COMMIT=$(git rev-list -1 HEAD) \
12+
&& CGO_ENABLED=0 go build -a --ldflags '-w' --ldflags "-X main.CommitHash=$GIT_COMMIT" -o /go/timescale-prometheus ./cmd/timescale-prometheus
1113

1214
# Final image
1315
FROM busybox

cmd/timescale-prometheus/main.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,17 +142,19 @@ func main() {
142142
cfg := parseFlags()
143143
err := log.Init(cfg.logLevel)
144144
if err != nil {
145+
fmt.Println("Version: ", Version, "Commit Hash: ", CommitHash)
145146
fmt.Println("Fatal error: cannot start logger", err)
146147
os.Exit(1)
147148
}
149+
log.Info("msg", "Version:"+Version+"; Commit Hash: "+CommitHash)
148150
log.Info("config", util.MaskPassword(fmt.Sprintf("%+v", cfg)))
149-
150151
http.Handle(cfg.telemetryPath, promhttp.Handler())
151152

152153
elector, err = initElector(cfg)
153154

154155
if err != nil {
155-
log.Error("msg", "Aborting startup because of elector init error: %s", util.MaskPassword(err.Error()))
156+
errStr := fmt.Sprintf("Aborting startup because of elector init error: %s", util.MaskPassword(err.Error()))
157+
log.Error("msg", errStr)
156158
os.Exit(1)
157159
}
158160

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package main
2+
3+
var (
4+
Version = "0.1.0-dev"
5+
CommitHash = ""
6+
)

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ services:
1212
- 9090:9090/tcp
1313
volumes:
1414
- ./sample-docker-prometheus.yml:/etc/prometheus/prometheus.yml:ro
15-
prometheus_postgresql_adapter:
15+
timescale-prometheus-connector:
1616
build:
1717
context: .
1818
depends_on:

0 commit comments

Comments
 (0)