diff --git a/pkg/kiln/io.go b/pkg/kiln/io.go index e880d900..732f4a90 100644 --- a/pkg/kiln/io.go +++ b/pkg/kiln/io.go @@ -9,6 +9,7 @@ import ( "path/filepath" "strings" "text/template" + "bytes" uuid "github.com/nu7hatch/gouuid" ) @@ -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 +} diff --git a/pkg/server/server.go b/pkg/server/server.go index 261692ea..cdabdd21 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -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 @@ -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: "", + ImageName: "", + Revision: "", + EnvVars: []string{"var1=val1", "var2=val2"}, + 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) {