Exemplo n.º 1
0
func (r *dockerResolver) Resolve(ctx context.Context, img image.Image, out chan Event) (image.Image, error) {
	pr, pw := io.Pipe()
	errCh := make(chan error, 1)
	go func() {
		defer pw.Close()
		errCh <- r.pullImage(ctx, img, pw)
	}()

	dec := json.NewDecoder(pr)
	for {
		var e DockerEvent
		if err := dec.Decode(&e); err == io.EOF {
			break
		} else if err != nil {
			return img, err
		}
		out <- &e
	}

	// Wait for pullImage to finish
	if err := <-errCh; err != nil {
		return img, err
	}

	i, err := r.client.InspectImage(img.String())
	if err != nil {
		return img, err
	}

	return image.Image{
		Repository: img.Repository,
		Tag:        i.ID,
	}, nil
}
Exemplo n.º 2
0
// createContainer creates a new docker container for the given docker image.
func (e *fileExtractor) createContainer(ctx context.Context, img image.Image) (*docker.Container, error) {
	return e.client.CreateContainer(ctx, docker.CreateContainerOptions{
		Config: &docker.Config{
			Image: img.String(),
		},
	})
}
Exemplo n.º 3
0
func (e *cmdExtractor) Extract(ctx context.Context, img image.Image, _ io.Writer) ([]byte, error) {
	i, err := e.client.InspectImage(img.String())
	if err != nil {
		return nil, err
	}

	return procfile.Marshal(procfile.ExtendedProcfile{
		"web": procfile.Process{
			Command: i.Config.Cmd,
		},
	})
}
Exemplo n.º 4
0
func (e *CMDExtractor) Extract(img image.Image) (Procfile, error) {
	pm := make(Procfile)

	i, err := e.client.InspectImage(img.String())
	if err != nil {
		return pm, err
	}

	pm["web"] = strings.Join(i.Config.Cmd, " ")

	return pm, nil
}
Exemplo n.º 5
0
func (r *dockerResolver) Resolve(ctx context.Context, img image.Image, out io.Writer) (image.Image, error) {
	if err := r.pullImage(ctx, img, out); err != nil {
		return img, err
	}

	i, err := r.client.InspectImage(img.String())
	if err != nil {
		return img, err
	}

	return image.Image{
		Repository: img.Repository,
		Tag:        i.ID,
	}, nil
}