Example #1
0
// Compose create a new image.
func Compose(client docker.Docker, stream docker.LogStream, configuration *configuration.Configuration) error {

	if err := configuration.Validate(); err != nil {
		return err
	}

	name := configuration.Compose.Name
	noCache := configuration.Compose.NoCache
	pull := configuration.Compose.Pull
	directory, err := os.Getwd()

	if err != nil {
		return err
	}

	id := client.ImageID(name)

	option := docker.BuildOptions{
		Name:      name,
		Directory: directory,
		Pull:      pull,
		NoCache:   noCache,
	}

	err = client.Build(option, stream)

	if newid := client.ImageID(name); newid != id && id != "" {
		// Remove previous image since id doesn't match.
		if err2 := client.RemoveImage(id); err == nil {
			err = err2
		}
	}

	return err
}
Example #2
0
// Publish push the docker image into the docker registy.
func Publish(client docker.Docker, stream docker.LogStream, configuration *configuration.Configuration) error {

	if err := configuration.Validate(); err != nil {
		return err
	}

	reference, err := parser.Parse(remote(configuration))

	if err != nil {
		return err
	}

	tagOpts := docker.TagOptions{
		Name:       reference.Name(),
		Repository: reference.Repository(),
		Tag:        reference.Tag(),
	}

	pushOpts := docker.PushOptions{
		Name:       reference.Name(),
		Repository: reference.Repository(),
		Registry:   reference.Registry(),
		Tag:        reference.Tag(),
	}

	if err = client.Tag(tagOpts); err != nil {
		return err
	}

	err = client.Push(pushOpts, stream)

	// Remove registry tag
	if err2 := client.RemoveImage(reference.Remote()); err2 != nil && err == nil {
		err = err2
	}

	return err
}