Exemplo n.º 1
0
// PullAndExtract returns a ProcfileExtractor that will pull the image using the
// docker client, then attempt to extract the Procfile from the WORKDIR, or
// fallback to the CMD directive in the Procfile.
func PullAndExtract(c *dockerutil.Client) ProcfileExtractor {
	e := procfile.MultiExtractor(
		procfile.NewFileExtractor(c.Client),
		procfile.NewCMDExtractor(c.Client),
	)

	return ProcfileExtractor(func(ctx context.Context, img image.Image, w io.Writer) (procfile.Procfile, error) {
		repo := img.Repository
		if img.Registry != "" {
			repo = fmt.Sprintf("%s/%s", img.Registry, img.Repository)
		}

		if err := c.PullImage(ctx, docker.PullImageOptions{
			Registry:      img.Registry,
			Repository:    repo,
			Tag:           img.Tag,
			OutputStream:  w,
			RawJSONStream: true,
		}); err != nil {
			return nil, err
		}

		return e.Extract(img)
	})
}
Exemplo n.º 2
0
// PullAndExtract returns a ProcfileExtractor that will pull the image using the
// docker client, then attempt to extract the the Procfile, or fallback to the
// CMD directive in the Dockerfile.
func PullAndExtract(c *dockerutil.Client) ProcfileExtractor {
	e := multiExtractor(
		newFileExtractor(c),
		newCMDExtractor(c),
	)

	return ProcfileExtractorFunc(func(ctx context.Context, img image.Image, w io.Writer) ([]byte, error) {
		if err := c.PullImage(ctx, docker.PullImageOptions{
			Registry:      img.Registry,
			Repository:    img.Repository,
			Tag:           img.Tag,
			OutputStream:  w,
			RawJSONStream: true,
		}); err != nil {
			return nil, err
		}

		return e.Extract(ctx, img, w)
	})
}