示例#1
0
func (c *dockerClient) Build(imageName string, contextDir string, options BuildOptions) error {
	return c.client.BuildImage(
		docker.BuildImageOptions{
			Name:           imageName,
			Dockerfile:     options.Dockerfile,
			SuppressOutput: true,
			OutputStream:   log.Writer(),
			ContextDir:     contextDir,
		},
	)
}
示例#2
0
func (c *dockerClient) Pull(imageName string, options PullOptions) error {
	repository, tag := docker.ParseRepositoryTag(imageName)
	if tag == "" {
		tag = "latest"
	}
	return c.client.PullImage(
		docker.PullImageOptions{
			Repository:   repository,
			Tag:          tag,
			OutputStream: log.Writer(),
		},
		docker.AuthConfiguration{},
	)
}
示例#3
0
func (c *dockerClient) Wait(containerID string, options WaitOptions) error {
	errC := make(chan error)
	go func() {
		errC <- c.client.Logs(
			docker.LogsOptions{
				Container:    containerID,
				OutputStream: log.Writer(),
				ErrorStream:  log.Writer(),
				Stdout:       true,
				Stderr:       true,
				Timestamps:   true,
			},
		)
	}()
	exitCode, err := c.client.WaitContainer(containerID)
	logsErr := <-errC
	if err != nil {
		return err
	}
	if exitCode != 0 {
		return fmt.Errorf("container %s had exit code %d", containerID, exitCode)
	}
	return logsErr
}