Ejemplo n.º 1
0
// Configure will analyze the given remote identifier and define the required parameters for
// Compose and Publish modules.
func (c *Configuration) Configure(remote string) error {

	r, err := parser.Parse(remote)
	if err != nil {
		return err
	}

	c.Compose.Name = r.Name()
	c.Publish.Hostname = r.Registry()
	return nil
}
Ejemplo n.º 2
0
// See Docker interface
func (d docker) Run(option RunOptions, stream LogStream) (int, error) {

	r, err := parser.Parse(option.Image)
	if err != nil {
		return 0, err
	}

	err = d.client.PullImage(pullImageOptions(r.Remote(), stream), pullAuthConfiguration(option))
	if err != nil {
		return 0, err
	}

	e, err := d.client.CreateContainer(createContainerOptions(option))

	if err != nil {
		return 0, err
	}

	id := e.ID

	if err = d.client.StartContainer(id, nil); err != nil {
		return 0, err
	}

	err = d.Logs(id, stream)

	if err != nil {
		fmt.Fprint(stream.Err, err)
	}

	exit, err := d.client.WaitContainer(id)

	if err != nil {
		return 0, err
	}

	if err = d.client.RemoveContainer(removeContainerOptions(id)); err != nil {
		return 0, err
	}

	return exit, nil

}
Ejemplo n.º 3
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
}