Skip to content

Commit

Permalink
print gitRef & gitHash for docker version
Browse files Browse the repository at this point in the history
  • Loading branch information
damoon committed Nov 16, 2020
1 parent 56b65fb commit 8381a41
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 22 deletions.
2 changes: 1 addition & 1 deletion cmd/wedding/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))

Expand Down
1 change: 0 additions & 1 deletion deployment/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
37 changes: 21 additions & 16 deletions pkg/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions pkg/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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)
Expand Down

0 comments on commit 8381a41

Please sign in to comment.