Skip to content

Commit

Permalink
Adding commit to page
Browse files Browse the repository at this point in the history
  • Loading branch information
COMTOP1 committed Jan 6, 2025
1 parent 247ad58 commit d1440f6
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 .")
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions server/Dockerfile
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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

Expand Down
4 changes: 3 additions & 1 deletion server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type (
var (
verbose bool
Version = "unknown"
Commit = "unknown"
)

//go:embed public/*
Expand Down Expand Up @@ -82,6 +83,7 @@ func main() {
}

config.Version = Version
config.Commit = Commit

r := &Router{
config: config,
Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion server/templates/_base.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
{{template "content" .}}
<br><br>
{{ $year := thisYear }}
<footer id="footer">Streamer (version: {{ getVersion }}) - created by Liam Burnand 2022{{if ne $year 2022}}-{{ $year }}{{end}}</footer>
<footer id="footer">Streamer (version: {{ getVersion }}, <a href="https://github.com/ystv/streamer/commit/{{ getCommit }}"
target="_blank">GitHub (commit: {{ getCommit }})</a>) - created by Liam Burnand 2022{{if ne $year 2022}}-{{ $year }}{{end}}</footer>
<script>
const toggleSwitch = document.getElementById("theme_checkbox");

Expand Down
7 changes: 6 additions & 1 deletion server/templates/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var tmpls embed.FS

type Templater struct {
Version string
Commit string
}

type Template string
Expand All @@ -39,9 +40,10 @@ func (t Template) String() string {
return string(t)
}

func NewTemplate(version string) *Templater {
func NewTemplate(version, commit string) *Templater {
return &Templater{
Version: version,
Commit: commit,
}
}

Expand Down Expand Up @@ -70,6 +72,9 @@ func (t *Templater) getFuncMaps() template.FuncMap {
"getVersion": func() string {
return t.Version
},
"getCommit": func() string {
return t.Commit
},
}
}

Expand Down
3 changes: 2 additions & 1 deletion server/views/views.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type (
Config struct {
Verbose bool
Version string
Commit string
StreamServer string `envconfig:"STREAM_SERVER"`
TransmissionLight string `envconfig:"TRANSMISSION_LIGHT"`
KeyChecker string `envconfig:"KEY_CHECKER"`
Expand Down Expand Up @@ -188,7 +189,7 @@ func New(conf Config, store *store.Store) *Views {
conf: conf,
cookie: cookie,
store: store,
template: templates.NewTemplate(conf.Version),
template: templates.NewTemplate(conf.Version, conf.Commit),
}
}

Expand Down

0 comments on commit d1440f6

Please sign in to comment.