Ability to specify the base image of the Docker container

This commit is contained in:
Faissal Elamraoui 2016-12-22 18:29:13 +01:00
parent 81c6de6cb3
commit 699d76bc95
1 changed files with 7 additions and 5 deletions

View File

@ -34,10 +34,7 @@ var cmdDockerize = &Command{
Run: dockerizeApp, Run: dockerizeApp,
} }
const dockerBuildTemplate = `FROM library/golang:latest const dockerBuildTemplate = `FROM {{.BaseImage}}
# Get Beego Web Framework
RUN go get github.com/astaxie/beego
# Godep for vendoring # Godep for vendoring
RUN go get github.com/tools/godep RUN go get github.com/tools/godep
@ -60,17 +57,20 @@ EXPOSE {{.Expose}}
` `
type Dockerfile struct { type Dockerfile struct {
BaseImage string
Appdir string Appdir string
Entrypoint string Entrypoint string
Expose string Expose string
} }
var ( var (
expose string expose string
baseImage string
) )
func init() { func init() {
fs := flag.NewFlagSet("dockerize", flag.ContinueOnError) fs := flag.NewFlagSet("dockerize", flag.ContinueOnError)
fs.StringVar(&baseImage, "image", "library/golang", "Sets the base image of the Docker container.")
fs.StringVar(&expose, "expose", "8080", "Port to expose in the Docker container.") fs.StringVar(&expose, "expose", "8080", "Port to expose in the Docker container.")
cmdDockerize.Flag = *fs cmdDockerize.Flag = *fs
} }
@ -86,8 +86,10 @@ func dockerizeApp(cmd *Command, args []string) int {
appdir := strings.Replace(dir, gopath, "", 1) appdir := strings.Replace(dir, gopath, "", 1)
// TODO: Check if the base image exists in Docker Hub
_, entrypoint := path.Split(appdir) _, entrypoint := path.Split(appdir)
dockerfile := Dockerfile{ dockerfile := Dockerfile{
BaseImage: baseImage,
Appdir: appdir, Appdir: appdir,
Entrypoint: entrypoint, Entrypoint: entrypoint,
Expose: expose, Expose: expose,