Skip to content

Commit

Permalink
Display version from git tag
Browse files Browse the repository at this point in the history
  • Loading branch information
rmil committed Jul 21, 2021
1 parent a449d93 commit 7ba22f0
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pipeline {
sh '''ssh -tt deploy@web << EOF
docker pull $REGISTRY_ENDPOINT/ystv/web-auth:$BUILD_ID
docker rm -f ystv-web-auth || true
docker run -d -p 1335:8080 --env-file /data/webs/web-auth/env --name ystv-web-auth $REGISTRY_ENDPOINT/ystv/web-auth:$BUILD_ID
docker run -d -p 1335:8080 --env-file /data/webs/web-auth/env -e WAUTH_VERSION=$TAG_NAME --name ystv-web-auth $REGISTRY_ENDPOINT/ystv/web-auth:$BUILD_ID
docker image prune -a -f --filter "label=site=auth"
EOF'''
}
Expand Down Expand Up @@ -66,7 +66,7 @@ pipeline {
echo err.getMessage()
}
}
sh 'docker run -d -p 1335:8080 --env-file $APP_ENV --name ystv-web-auth $REGISTRY_ENDPOINT/ystv/web-auth:$BUILD_ID' // Deploying site
sh 'docker run -d -p 1335:8080 --env-file $APP_ENV -e WAUTH_VERSION=$TAG_NAME --name ystv-web-auth $REGISTRY_ENDPOINT/ystv/web-auth:$BUILD_ID' // Deploying site
sh 'docker image prune -a -f --filter "label=site=auth"' // remove old image
}
}
Expand Down
6 changes: 6 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,14 @@ func main() {
log.Fatalf("template files failed: %+v", err)
}

version := os.Getenv("WAUTH_VERSION")
if version == "" {
version = "unknown"
}

// Generate config
conf := views.Config{
Version: version,
DatabaseURL: os.Getenv("WAUTH_DATABASE_URL"),
DomainName: os.Getenv("WAUTH_DOMAIN_NAME"),
LogoutEndpoint: os.Getenv("WAUTH_LOGOUT_ENDPOINT"),
Expand Down
2 changes: 1 addition & 1 deletion views/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (v *Views) InternalFunc(w http.ResponseWriter, r *http.Request) {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
c := getData(session)
c := v.getData(session)
lastLogin := time.Now()
if c.User.LastLogin.Valid {
lastLogin = c.User.LastLogin.Time
Expand Down
4 changes: 2 additions & 2 deletions views/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (v *Views) LoginFunc(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case "GET":
// Data for our HTML template
context := getData(session)
context := v.getData(session)

// Check if there is a callback request
callbackURL, err := url.Parse(r.URL.Query().Get("callback"))
Expand Down Expand Up @@ -95,7 +95,7 @@ func (v *Views) LoginFunc(w http.ResponseWriter, r *http.Request) {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
ctx := getData(session)
ctx := v.getData(session)
ctx.Callback = callback
ctx.Message = "Invalid username or password"
ctx.MsgType = "is-danger"
Expand Down
7 changes: 4 additions & 3 deletions views/views.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
type (
// Config the global web-auth configuration
Config struct {
Version string
DatabaseURL string
DomainName string
LogoutEndpoint string
Expand Down Expand Up @@ -147,7 +148,7 @@ func (v Views) IndexFunc(w http.ResponseWriter, r *http.Request) {
return
}
// Data for our HTML template
context := getData(session)
context := v.getData(session)

// Check if there is a callback request
callbackURL, err := url.Parse(r.URL.Query().Get("callback"))
Expand All @@ -173,14 +174,14 @@ type Context struct {
User types.User
}

func getData(s *sessions.Session) *Context {
func (v Views) getData(s *sessions.Session) *Context {
val := s.Values["user"]
u := types.User{}
u, ok := val.(types.User)
if !ok {
u = types.User{Authenticated: false}
}
c := Context{Version: "0.4.12",
c := Context{Version: v.conf.Version,
Callback: "/internal",
User: u,
}
Expand Down

0 comments on commit 7ba22f0

Please sign in to comment.