Skip to content
This repository has been archived by the owner on Oct 25, 2022. It is now read-only.

Commit

Permalink
Optional use prefix "gofn/" the image name
Browse files Browse the repository at this point in the history
ref #47
  • Loading branch information
Avelino committed Feb 23, 2017
1 parent 25e895c commit 239182c
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions provision/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,19 @@ type VolumeOptions struct {

// BuildOptions are options used in the image build
type BuildOptions struct {
ContextDir string
Dockerfile string
ImageName string
RemoteURI string
Iaas iaas.Iaas
ContextDir string
Dockerfile string
DoNotUsePrefixImageName bool
ImageName string
RemoteURI string
Iaas iaas.Iaas
}

func (opts BuildOptions) GetImageName() string {
if opts.DoNotUsePrefixImageName {
return opts.ImageName
}
return "gofn/" + opts.ImageName
}

// FnClient instantiate a docker client
Expand Down Expand Up @@ -78,7 +86,7 @@ func FnImageBuild(client *docker.Client, opts *BuildOptions) (Name string, Stdou
opts.Dockerfile = "Dockerfile"
}
stdout := new(bytes.Buffer)
Name = "gofn/" + opts.ImageName
Name = opts.GetImageName()
err = client.BuildImage(docker.BuildImageOptions{
Name: Name,
Dockerfile: opts.Dockerfile,
Expand All @@ -97,18 +105,14 @@ func FnImageBuild(client *docker.Client, opts *BuildOptions) (Name string, Stdou
// FnFindImage returns image data by name
func FnFindImage(client *docker.Client, imageName string) (image docker.APIImages, err error) {
var imgs []docker.APIImages
name := "gofn/" + imageName

imgs, err = client.ListImages(docker.ListImagesOptions{Filter: name})
imgs, err = client.ListImages(docker.ListImagesOptions{Filter: imageName})
if err != nil {
return
}

if len(imgs) == 0 {
err = ErrImageNotFound
return
}

image = imgs[0]
return
}
Expand Down

0 comments on commit 239182c

Please sign in to comment.