Skip to content

Commit

Permalink
Merge pull request #71 from 30x/issue-66
Browse files Browse the repository at this point in the history
add new status & Dockerfile API resources
  • Loading branch information
noahdietz authored Oct 27, 2016
2 parents 5dcb773 + 5dbc9c5 commit 06e0703
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pkg/kiln/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"path/filepath"
"strings"
"text/template"
"bytes"

uuid "github.com/nu7hatch/gouuid"
)
Expand Down Expand Up @@ -281,3 +282,16 @@ func (sourceInfo *SourceInfo) CreateDockerFile(dockerInfo *DockerInfo) error {

return nil
}

// GetExampleDockerfile is used to create an example Dockerfile with the given information
func GetExampleDockerfile(dockerInfo *DockerInfo) (buf *bytes.Buffer, err error) {
buf = &bytes.Buffer{}

err = dockerTemplate.Execute(buf, dockerInfo)

if err != nil {
return nil, err
}

return buf, nil
}
28 changes: 28 additions & 0 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,15 @@ func NewServer(imageCreator kiln.ImageCreator, podSpecIo kiln.PodspecIo) *Server
routes.Methods("PUT").Headers("Content-Type", "application/json").Path("/imagespaces/{org}/images/{name}/podspec/{revision}/").HandlerFunc(server.postPodSpec)
routes.Methods("PUT").Headers("Content-Type", "application/json").Path("/imagespaces/{org}/images/{name}/podspec/{revision}").HandlerFunc(server.postPodSpec)

// dockerfile
routes.Methods("GET").Path("/imagespaces/kiln/Dockerfile/").HandlerFunc(server.getDockerfile)
routes.Methods("GET").Path("/imagespaces/kiln/Dockerfile").HandlerFunc(server.getDockerfile)

//health check
routes.Methods("GET").Path("/imagespaces/status/").HandlerFunc(server.status)
routes.Methods("GET").Path("/imagespaces/status").HandlerFunc(server.status)
routes.Methods("GET").Path("/imagespaces/kiln/status/").HandlerFunc(server.status)
routes.Methods("GET").Path("/imagespaces/kiln/status").HandlerFunc(server.status)

//now wrap everything with logging

Expand Down Expand Up @@ -117,6 +123,28 @@ func (server *Server) Start(port int, timeout time.Duration) {

}

// getDockerFile replies with the Dockerfile kiln uses to build images
func (server *Server) getDockerfile(w http.ResponseWriter, r *http.Request) {
dockerInfo := &kiln.DockerInfo{
RepoName: "<imagespace>",
ImageName: "<imageName>",
Revision: "<revision>",
EnvVars: []string{"var1=val1", "var2=val2"},
NodeVersion: "<nodeVersion>",
}

resp, err := kiln.GetExampleDockerfile(dockerInfo)
if err != nil {
message := fmt.Sprintf("Failed making example Dockerfile %s", err)
kiln.LogError.Printf(message)
internalError(message, w)
return
}

w.Header().Set("Content-Type", "text/plain")
w.Write(resp.Bytes())
}

// TODO: Fix how org and other info is parsed
//postApplication and render a response
func (server *Server) postApplication(w http.ResponseWriter, r *http.Request) {
Expand Down

0 comments on commit 06e0703

Please sign in to comment.