From d1440f6f3adadba188c2c4cdd927e9c67044a506 Mon Sep 17 00:00:00 2001 From: Liam Burnand Date: Mon, 6 Jan 2025 08:27:34 +0000 Subject: [PATCH] Adding commit to page --- Jenkinsfile | 3 ++- server/Dockerfile | 4 ++++ server/main.go | 4 +++- server/templates/_base.tmpl | 3 ++- server/templates/templates.go | 7 ++++++- server/views/views.go | 3 ++- 6 files changed, 19 insertions(+), 5 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 83ae68f..2e834e6 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -24,8 +24,9 @@ pipeline { steps { script { dir("server") { + GIT_COMMIT_HASH = sh (script: "git log -n 1 --pretty=format:'%H'", returnStdout: true) docker.withRegistry('https://' + registryEndpoint, 'docker-registry') { - serverImage = docker.build(serverImageName, "--build-arg STREAMER_VERSION_ARG=${env.BRANCH_NAME}-${env.BUILD_ID} --no-cache .") + serverImage = docker.build(serverImageName, "--build-arg STREAMER_VERSION_ARG=${env.BRANCH_NAME}-${env.BUILD_ID} --build-arg STREAMER_COMMIT_ARG=${GIT_COMMIT_HASH} --no-cache .") } } } diff --git a/server/Dockerfile b/server/Dockerfile index b876649..a39f809 100644 --- a/server/Dockerfile +++ b/server/Dockerfile @@ -1,8 +1,10 @@ FROM golang:1.23.4-alpine3.21 AS build LABEL stage="builder" +LABEL author="Liam Burnand" ARG STREAMER_VERSION_ARG +ARG STREAMER_COMMIT_ARG VOLUME /db @@ -16,6 +18,8 @@ RUN apk update && apk add git make protoc && apk add protoc-gen-go --repository # Set build variables RUN echo -n "-X 'main.Version=$STREAMER_VERSION_ARG" > ./ldflags && \ + tr -d \\n < ./ldflags > ./temp && mv ./temp ./ldflags && \ + echo -n "' -X 'main.Commit=$STREAMER_COMMIT_ARG" >> ./ldflags && \ tr -d \\n < ./ldflags > ./temp && mv ./temp ./ldflags && \ echo -n "'" >> ./ldflags diff --git a/server/main.go b/server/main.go index 0314344..bda0e03 100644 --- a/server/main.go +++ b/server/main.go @@ -28,6 +28,7 @@ type ( var ( verbose bool Version = "unknown" + Commit = "unknown" ) //go:embed public/* @@ -82,6 +83,7 @@ func main() { } config.Version = Version + config.Commit = Commit r := &Router{ config: config, @@ -98,7 +100,7 @@ func main() { r.views.BeginWatchdog() - log.Printf("streamer server version: %s", Version) + log.Printf("streamer server version: %s, commit: %s", Version, Commit) r.router.Logger.Error(r.router.Start(r.config.ServerAddress)) log.Fatalf("failed to start router on address %s", r.config.ServerAddress) diff --git a/server/templates/_base.tmpl b/server/templates/_base.tmpl index cbacfd6..be6ef87 100644 --- a/server/templates/_base.tmpl +++ b/server/templates/_base.tmpl @@ -31,7 +31,8 @@ {{template "content" .}}

{{ $year := thisYear }} - +