bootcfg/version: Add version package and HTTP version output

* bootcfg/version package provides the linker's GIT SHA based
version to bootcfg components
* Display the bootcfg version via the HTTP server / path for
convenience and for validating a deployed version easily
* Log requests to the / rooted subtree paths to surface machines
which are making requests containing typos and mistakes that do
not match HTTP API endpoints
This commit is contained in:
Dalton Hubble
2016-04-26 13:40:01 -07:00
parent f654879195
commit 3525abf84f
6 changed files with 27 additions and 6 deletions

View File

@@ -20,7 +20,7 @@ Configuration arguments can be provided as flags or as environment variables.
| data | /var/lib/bootcfg/{profiles,groups,ignition,cloud} |
| assets | /var/lib/bootcfg/assets |
## Check Version
## Version
./bin/bootcfg -version
sudo rkt --insecure-options=image run quay.io/coreos/bootcfg:latest -- -version

View File

@@ -1,12 +1,14 @@
package http
import (
"fmt"
"net/http"
"golang.org/x/net/context"
"github.com/coreos/coreos-baremetal/bootcfg/server"
pb "github.com/coreos/coreos-baremetal/bootcfg/server/serverpb"
"github.com/coreos/coreos-baremetal/bootcfg/version"
)
// requireGET requires requests to be an HTTP GET. Otherwise, it responds with
@@ -31,6 +33,19 @@ func logRequests(next http.Handler) http.Handler {
return http.HandlerFunc(fn)
}
// versionHandler shows the server name and version for root requests.
// Otherwise, a 404 is returned.
func versionHandler() http.Handler {
fn := func(w http.ResponseWriter, req *http.Request) {
if req.URL.Path != "/" {
http.NotFound(w, req)
return
}
fmt.Fprintf(w, "bootcfg version: %s", version.Version)
}
return http.HandlerFunc(fn)
}
// selectGroup selects the Group whose selectors match the query parameters,
// adds the Group to the ctx, and calls the next handler. The next handler
// should handle a missing Group.

View File

@@ -46,6 +46,8 @@ func (s *Server) HTTPHandler() http.Handler {
mux := http.NewServeMux()
srv := server.NewServer(&server.Config{s.store})
// bootcfg version
mux.Handle("/", logRequests(versionHandler()))
// Boot via GRUB
mux.Handle("/grub", logRequests(NewHandler(selectProfile(srv, grubHandler()))))
// Boot via iPXE

View File

@@ -0,0 +1,5 @@
// Package version provides the bootcfg version.
package version
// Version provided by compile time -ldflags.
var Version = "was not built properly"

2
build
View File

@@ -1,6 +1,6 @@
#!/bin/bash -e
LD_FLAGS="-w -X main.version=$(./git-version)"
LD_FLAGS="-w -X github.com/coreos/coreos-baremetal/bootcfg/version.Version=$(./git-version)"
CGO_ENABLED=0 go build -o bin/bootcfg -ldflags "$LD_FLAGS" -a -tags netgo github.com/coreos/coreos-baremetal/cmd/bootcfg
# bootcmd CLI binary

View File

@@ -17,12 +17,11 @@ import (
"github.com/coreos/coreos-baremetal/bootcfg/server"
"github.com/coreos/coreos-baremetal/bootcfg/sign"
"github.com/coreos/coreos-baremetal/bootcfg/storage"
"github.com/coreos/coreos-baremetal/bootcfg/version"
)
var (
// version provided by compile time flag: -ldflags "-X main.version $GIT_SHA"
version = "was not built properly"
log = capnslog.NewPackageLogger("github.com/coreos/coreos-baremetal/cmd/bootcfg", "main")
log = capnslog.NewPackageLogger("github.com/coreos/coreos-baremetal/cmd/bootcfg", "main")
)
func main() {
@@ -56,7 +55,7 @@ func main() {
passphrase := os.Getenv("BOOTCFG_PASSPHRASE")
if flags.version {
fmt.Println(version)
fmt.Println(version.Version)
return
}