From 59b326e68941607c0e9bd798f392b2b35c5d6ad1 Mon Sep 17 00:00:00 2001 From: Will Jordan Date: Tue, 4 Feb 2025 10:40:23 -0800 Subject: [PATCH] log postgres-flex version on startup Updates a `main.version` variable with the `VERSION` build arg and logs it at startup. --- cmd/start/main.go | 3 +++ pg15/Dockerfile | 4 +++- pg15/Dockerfile-timescaledb | 4 +++- pg16/Dockerfile | 4 +++- pg16/Dockerfile-timescaledb | 4 +++- 5 files changed, 15 insertions(+), 4 deletions(-) diff --git a/cmd/start/main.go b/cmd/start/main.go index b3cb3fbf..f503857c 100644 --- a/cmd/start/main.go +++ b/cmd/start/main.go @@ -13,7 +13,10 @@ import ( "github.com/fly-apps/postgres-flex/internal/supervisor" ) +var version = "(devel)" + func main() { + log.Printf("Starting postgres-flex %s.", version) log.SetFlags(0) requiredPasswords := []string{"SU_PASSWORD", "OPERATOR_PASSWORD", "REPL_PASSWORD"} diff --git a/pg15/Dockerfile b/pg15/Dockerfile index 9611a1e5..46deb905 100644 --- a/pg15/Dockerfile +++ b/pg15/Dockerfile @@ -4,6 +4,8 @@ ARG VERSION=custom FROM golang:1.23 +ARG VERSION + WORKDIR /go/src/github.com/fly-apps/fly-postgres COPY . . @@ -14,7 +16,7 @@ RUN CGO_ENABLED=0 GOOS=linux go build -v -o /fly/bin/start_monitor ./cmd/monitor RUN CGO_ENABLED=0 GOOS=linux go build -v -o /fly/bin/start_admin_server ./cmd/admin_server RUN CGO_ENABLED=0 GOOS=linux go build -v -o /fly/bin/flexctl ./cmd/flexctl -RUN CGO_ENABLED=0 GOOS=linux go build -v -o /fly/bin/start ./cmd/start +RUN CGO_ENABLED=0 GOOS=linux go build -v -o /fly/bin/start -ldflags="-X main.version=${VERSION}" ./cmd/start COPY ./bin/* /fly/bin/ diff --git a/pg15/Dockerfile-timescaledb b/pg15/Dockerfile-timescaledb index 78c69425..45603122 100644 --- a/pg15/Dockerfile-timescaledb +++ b/pg15/Dockerfile-timescaledb @@ -4,6 +4,8 @@ ARG VERSION=custom FROM golang:1.23 +ARG VERSION + WORKDIR /go/src/github.com/fly-apps/fly-postgres COPY . . @@ -14,7 +16,7 @@ RUN CGO_ENABLED=0 GOOS=linux go build -v -o /fly/bin/start_monitor ./cmd/monitor RUN CGO_ENABLED=0 GOOS=linux go build -v -o /fly/bin/start_admin_server ./cmd/admin_server RUN CGO_ENABLED=0 GOOS=linux go build -v -o /fly/bin/flexctl ./cmd/flexctl -RUN CGO_ENABLED=0 GOOS=linux go build -v -o /fly/bin/start ./cmd/start +RUN CGO_ENABLED=0 GOOS=linux go build -v -o /fly/bin/start -ldflags="-X main.version=${VERSION}" ./cmd/start COPY ./bin/* /fly/bin/ diff --git a/pg16/Dockerfile b/pg16/Dockerfile index 0ec89145..2b873063 100644 --- a/pg16/Dockerfile +++ b/pg16/Dockerfile @@ -4,6 +4,8 @@ ARG VERSION=custom FROM golang:1.23 AS builder +ARG VERSION + WORKDIR /go/src/github.com/fly-apps/fly-postgres COPY . . @@ -13,7 +15,7 @@ RUN CGO_ENABLED=0 GOOS=linux \ go build -v -o /fly/bin/pg_unregister ./cmd/pg_unregister && \ go build -v -o /fly/bin/start_monitor ./cmd/monitor && \ go build -v -o /fly/bin/start_admin_server ./cmd/admin_server && \ - go build -v -o /fly/bin/start ./cmd/start && \ + go build -v -o /fly/bin/start -ldflags="-X main.version=${VERSION}" ./cmd/start && \ go build -v -o /fly/bin/flexctl ./cmd/flexctl diff --git a/pg16/Dockerfile-timescaledb b/pg16/Dockerfile-timescaledb index cdb92ebb..30908c88 100644 --- a/pg16/Dockerfile-timescaledb +++ b/pg16/Dockerfile-timescaledb @@ -4,6 +4,8 @@ ARG VERSION=custom FROM golang:1.23 AS builder +ARG VERSION + WORKDIR /go/src/github.com/fly-apps/fly-postgres COPY . . @@ -13,7 +15,7 @@ RUN CGO_ENABLED=0 GOOS=linux \ go build -v -o /fly/bin/pg_unregister ./cmd/pg_unregister && \ go build -v -o /fly/bin/start_monitor ./cmd/monitor && \ go build -v -o /fly/bin/start_admin_server ./cmd/admin_server && \ - go build -v -o /fly/bin/start ./cmd/start && \ + go build -v -o /fly/bin/start -ldflags="-X main.version=${VERSION}" ./cmd/start && \ go build -v -o /fly/bin/flexctl ./cmd/flexctl