Beispiel #1
0
// ImageFromTemplate returns an ImageBuilder that will execute a template to
// determine what docker image should be deployed. Note that this doesn't not
// actually perform any "build".
func ImageFromTemplate(t *template.Template) ImageBuilder {
	return ImageBuilderFunc(func(ctx context.Context, _ io.Writer, event events.Deployment) (image.Image, error) {
		buf := new(bytes.Buffer)
		if err := t.Execute(buf, event); err != nil {
			return image.Image{}, err
		}

		return image.Decode(buf.String())
	})
}
Beispiel #2
0
func (c *ConveyorImageBuilder) BuildImage(ctx context.Context, w io.Writer, event events.Deployment) (image.Image, error) {
	a, err := c.client.Build(w, conveyor.BuildCreateOpts{
		Repository: event.Repository.FullName,
		Sha:        &event.Deployment.Sha,
	})
	if err != nil {
		return image.Image{}, err
	}

	return image.Decode(a.Image)
}
Beispiel #3
0
// Image returns an image.Image for the given deployment.
func Image(t string, d events.Deployment) (image.Image, error) {
	if t == "" {
		t = DefaultTemplate
	}

	tmpl, err := template.New("image").Parse(t)
	if err != nil {
		return image.Image{}, err
	}

	buf := new(bytes.Buffer)
	if err := tmpl.Execute(buf, d); err != nil {
		return image.Image{}, err
	}

	return image.Decode(buf.String())
}