diff --git a/cmd/wedding/main.go b/cmd/wedding/main.go index f33d7ab9..ca6fb34f 100644 --- a/cmd/wedding/main.go +++ b/cmd/wedding/main.go @@ -96,7 +96,7 @@ func run(c *cli.Context) error { log.Println("set up service") - svc := wedding.NewService(storage, kubernetesClient, namespace) + svc := wedding.NewService(gitHash, gitRef, storage, kubernetesClient, namespace) svcServer := httpServer(svc, c.String("addr")) diff --git a/deployment/Dockerfile b/deployment/Dockerfile index edd06a11..f82ad582 100644 --- a/deployment/Dockerfile +++ b/deployment/Dockerfile @@ -26,6 +26,5 @@ RUN apt-get update && apt-get install -y \ ca-certificates \ && rm -rf /var/lib/apt/lists/* -COPY --from=build-env /etc/mime.types /etc/mime.types COPY --from=build-env /go/bin/wedding /usr/local/bin/wedding ENTRYPOINT [ "wedding", "server" ] diff --git a/pkg/mock.go b/pkg/mock.go index 918c1658..08b85393 100644 --- a/pkg/mock.go +++ b/pkg/mock.go @@ -63,23 +63,28 @@ func ping(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) } -func version(w http.ResponseWriter, r *http.Request) { - w.Write([]byte(fmt.Sprintf(`{ - "Components": [ - { - "Name": "Wedding", - "Details": { - "Scheduler": "kubernetes", - "Builds": "buildkit", - "Pull/Tag/Push": "skopeo" - } - } - ], - "Version": "19.03.8", - "ApiVersion": "%s", - "MinAPIVersion": "1.12" +func versionHandler(gitHash, gitRef string) http.HandlerFunc { + tmpl := `{ + "Components": [ + { + "Name": "Wedding", + "Details": { + "Scheduler": "kubernetes", + "Builds": "buildkit", + "Pull/Tag/Push": "skopeo", + "GitCommit": "%s", + "GitBranch": "%s" + } + } + ], + "Version": "19.03.8", + "ApiVersion": "%s", + "MinAPIVersion": "1.12" } -`, apiVersion))) +` + return func(w http.ResponseWriter, r *http.Request) { + w.Write([]byte(fmt.Sprintf(tmpl, gitHash, gitRef, apiVersion))) + } } func buildPrune(w http.ResponseWriter, r *http.Request) { diff --git a/pkg/service.go b/pkg/service.go index e27475e7..3aa0a87c 100644 --- a/pkg/service.go +++ b/pkg/service.go @@ -30,14 +30,14 @@ type Service struct { } // NewService creates a new service server and initiates the routes. -func NewService(objectStore *ObjectStore, kubernetesClient *kubernetes.Clientset, namespace string) *Service { +func NewService(gitHash, gitRef string, objectStore *ObjectStore, kubernetesClient *kubernetes.Clientset, namespace string) *Service { srv := &Service{ objectStore: objectStore, namespace: namespace, kubernetesClient: kubernetesClient, } - srv.routes() + srv.routes(gitHash, gitRef) return srv } @@ -46,11 +46,11 @@ func (s *Service) ServeHTTP(w http.ResponseWriter, r *http.Request) { s.router.ServeHTTP(w, r) } -func (s *Service) routes() { +func (s *Service) routes(gitHash, gitRef string) { router := mux.NewRouter() router.HandleFunc("/_ping", ping).Methods(http.MethodGet) router.HandleFunc("/session", ignored).Methods(http.MethodPost) - router.HandleFunc("/{apiVersion}/version", version).Methods(http.MethodGet) + router.HandleFunc("/{apiVersion}/version", versionHandler(gitHash, gitRef)).Methods(http.MethodGet) router.HandleFunc("/{apiVersion}/build", s.build).Methods(http.MethodPost) router.HandleFunc("/{apiVersion}/images/{name:.+}/tag", s.tagImage).Methods(http.MethodPost)