fix: bake GIT_COMMIT via buildinfo in cmd and Dockerfile

Made-with: Cursor
This commit is contained in:
Leopere 2026-04-01 11:43:40 -04:00
parent 650482c189
commit f5b4bbe27e
Signed by: colin
SSH Key Fingerprint: SHA256:nRPCQTeMFLdGytxRQmPVK9VXY3/ePKQ5lGRyJhT5DY8
3 changed files with 9 additions and 5 deletions

View File

@ -9,9 +9,11 @@ RUN go mod download
COPY . . COPY . .
# Build both binaries as static. ARG GIT_COMMIT=unknown
RUN CGO_ENABLED=0 go build -ldflags="-s -w" -o /tunnel-server ./cmd/server/
RUN CGO_ENABLED=0 go build -ldflags="-s -w" -o /tunnel-client ./cmd/client/ # Build both binaries as static; Commit matches ship.sh / local -ldflags.
RUN CGO_ENABLED=0 go build -ldflags="-s -w -X github.com/nixc/reverse-ssh-traefik/internal/buildinfo.Commit=${GIT_COMMIT}" -o /tunnel-server ./cmd/server/
RUN CGO_ENABLED=0 go build -ldflags="-s -w -X github.com/nixc/reverse-ssh-traefik/internal/buildinfo.Commit=${GIT_COMMIT}" -o /tunnel-client ./cmd/client/
# --- Server image --- # --- Server image ---
FROM alpine:3.21 AS server FROM alpine:3.21 AS server

View File

@ -6,6 +6,7 @@ import (
"strconv" "strconv"
"time" "time"
"github.com/nixc/reverse-ssh-traefik/internal/buildinfo"
"github.com/nixc/reverse-ssh-traefik/internal/client" "github.com/nixc/reverse-ssh-traefik/internal/client"
) )
@ -26,7 +27,7 @@ func envOr(key, fallback string) string {
func main() { func main() {
log.SetFlags(log.LstdFlags | log.Lshortfile) log.SetFlags(log.LstdFlags | log.Lshortfile)
log.Println("tunnel-client starting") log.Printf("tunnel-client starting commit=%s", buildinfo.Commit)
serverAddr := envRequired("TUNNEL_SERVER") serverAddr := envRequired("TUNNEL_SERVER")
domain := envRequired("TUNNEL_DOMAIN") domain := envRequired("TUNNEL_DOMAIN")

View File

@ -7,6 +7,7 @@ import (
"strconv" "strconv"
"syscall" "syscall"
"github.com/nixc/reverse-ssh-traefik/internal/buildinfo"
"github.com/nixc/reverse-ssh-traefik/internal/server" "github.com/nixc/reverse-ssh-traefik/internal/server"
) )
@ -40,7 +41,7 @@ func envInt(key string, fallback int) int {
func main() { func main() {
log.SetFlags(log.LstdFlags | log.Lshortfile) log.SetFlags(log.LstdFlags | log.Lshortfile)
log.Println("tunnel-server starting") log.Printf("tunnel-server starting commit=%s", buildinfo.Commit)
// SSH server config (for accepting tunnel clients). // SSH server config (for accepting tunnel clients).
sshPort := envOr("SSH_PORT", "2222") sshPort := envOr("SSH_PORT", "2222")