示例#1
0
文件: empire.go 项目: frewsxcv/empire
// 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)
	})
}
示例#2
0
文件: empire.go 项目: mhahn/empire
// 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)
	})
}