Exemple #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
}
Exemple #2
0
// Install run compile instructions with a Docker container.
func Install(client docker.Docker, stream docker.LogStream, configuration *configuration.Configuration) error {

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

	if configuration.Install.Disable {
		fmt.Println("install module is disabled")
		return nil
	}

	env := GetEnv(configuration)

	volumes, err := GetVolumes(configuration)

	if err != nil {
		return err
	}

	output := configuration.Install.Output
	image := configuration.Install.Image
	command := configuration.Install.Command
	links := configuration.Install.Links

	option := docker.RunOptions{
		Image:   image,
		Command: command,
		Env:     env,
		Volumes: volumes,
		Links:   links,
	}

	exit, err := client.Run(option, stream)

	if err != nil {
		return err
	}

	if exit != 0 {
		return fmt.Errorf("cannot run install: exit status %d", exit)
	}

	if !pathExist(output) {
		return fmt.Errorf("file not found: %s", output)
	}

	return nil
}
Exemple #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
}