Skip to content

Commit

Permalink
Adding commit version to login
Browse files Browse the repository at this point in the history
  • Loading branch information
COMTOP1 committed Jan 6, 2025
1 parent 2787cfb commit abefaee
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ LABEL stage="builder"
WORKDIR /src/

ARG WAUTH_VERSION_ARG
ARG WAUTH_COMMIT_ARG

# Stores our dependencies
COPY go.mod .
Expand All @@ -19,6 +20,8 @@ COPY . .

# Set build variables
RUN echo -n "-X 'main.Version=$WAUTH_VERSION_ARG" > ./ldflags && \
tr -d \\n < ./ldflags > ./temp && mv ./temp ./ldflags && \
echo -n "' -X 'main.Commit=$WAUTH_COMMIT_ARG" >> ./ldflags && \
tr -d \\n < ./ldflags > ./temp && mv ./temp ./ldflags && \
echo -n "'" >> ./ldflags

Expand Down
3 changes: 2 additions & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ pipeline {
stage('Build image') {
steps {
script {
GIT_COMMIT_HASH = sh (script: "git log -n 1 --pretty=format:'%H' | head -c 7", returnStdout: true)
docker.withRegistry('https://' + registryEndpoint, 'docker-registry') {
image = docker.build(imageName, "--build-arg WAUTH_VERSION_ARG=${env.BRANCH_NAME}-${env.BUILD_ID} --no-cache .")
image = docker.build(imageName, "--build-arg WAUTH_VERSION_ARG=${env.BRANCH_NAME}-${env.BUILD_ID} --build-arg WAUTH_COMMIT_ARG=${GIT_COMMIT_HASH} --no-cache .")
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ import (
//go:generate ./node_modules/.bin/mjml -r ./templates/mjml/forgotEmail.mjml -o ./templates/forgotEmail.tmpl
//go:generate ./node_modules/.bin/mjml -r ./templates/mjml/resetEmail.mjml -o ./templates/resetEmail.tmpl

var Version = "unknown"
var (
Version = "unknown"
Commit = "unknown"
)

func main() {
var local, global bool
Expand Down Expand Up @@ -77,6 +80,7 @@ func main() {
// Generate config
conf := &views.Config{
Version: Version,
Commit: Commit,
Debug: debug,
Address: address,
DatabaseURL: dbConnectionString,
Expand Down
4 changes: 3 additions & 1 deletion templates/login.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@
<p class="has-text-grey">
<a href="/signup">Sign Up</a> &nbsp;·&nbsp;
<a href="/forgot">Forgot Password</a>{{if ne (len .Version) 0}} &nbsp;·&nbsp;
<a href="https://github.com/ystv/web-auth"> Version: {{.Version}} </a>{{end}}
<a href="https://github.com/ystv/web-auth/"
target="_blank">Version: {{.Version}}</a> &nbsp;·&nbsp; <a href="https://github.com/ystv/web-auth/commit/{{.Commit}}"
target="_blank">Commit: {{.Commit}}</a>{{end}}
</p>
</div>
</div>
Expand Down
3 changes: 3 additions & 0 deletions views/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type (
User user.User
// Version is the version that is running
Version string
Commit string
Assumed bool
actualUser user.User
}
Expand Down Expand Up @@ -63,6 +64,7 @@ func (v *Views) getSessionData(eC echo.Context) *Context {
MsgType: i.MesType,
Callback: "/internal",
Version: v.conf.Version,
Commit: v.conf.Commit,
}

return c
Expand Down Expand Up @@ -98,6 +100,7 @@ func (v *Views) getSessionData(eC echo.Context) *Context {
Callback: "/internal",
User: u,
Version: v.conf.Version,
Commit: v.conf.Commit,
Assumed: assumed,
actualUser: actual,
}
Expand Down
1 change: 1 addition & 0 deletions views/views.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type (
// Config the global web-auth configuration
Config struct {
Version string
Commit string
Debug bool
Address string
DatabaseURL string
Expand Down

0 comments on commit abefaee

Please sign in to comment.