Example #1
1
func (f *dockerFetcher) fetch(u *url.URL) (*os.File, error) {
	tmpDir, err := f.getTmpDir()
	if err != nil {
		return nil, err
	}
	defer os.RemoveAll(tmpDir)

	registryURL := strings.TrimPrefix(u.String(), "docker://")
	user, password := f.getCreds(registryURL)
	config := docker2aci.RemoteConfig{
		Username: user,
		Password: password,
		Insecure: f.InsecureFlags.AllowHTTP(),
		CommonConfig: docker2aci.CommonConfig{
			Squash:      true,
			OutputDir:   tmpDir,
			TmpDir:      tmpDir,
			Compression: d2acommon.NoCompression,
		},
	}
	acis, err := docker2aci.ConvertRemoteRepo(registryURL, config)
	if err != nil {
		return nil, errwrap.Wrap(errors.New("error converting docker image to ACI"), err)
	}

	aciFile, err := os.Open(acis[0])
	if err != nil {
		return nil, errwrap.Wrap(errors.New("error opening squashed ACI file"), err)
	}

	return aciFile, nil
}
Example #2
0
func (a *ACBuild) beginFromRemoteDockerImage(start string, insecure bool) (err error) {
	outputDir, err := ioutil.TempDir("", "acbuild")
	if err != nil {
		return err
	}
	defer os.RemoveAll(outputDir)

	tempDir, err := ioutil.TempDir("", "acbuild")
	if err != nil {
		return err
	}
	defer os.RemoveAll(tempDir)

	insecureConf := common.InsecureConfig{
		SkipVerify: insecure,
		AllowHTTP:  insecure,
	}

	config := docker2aci.RemoteConfig{
		CommonConfig: docker2aci.CommonConfig{
			Squash:      true,
			OutputDir:   outputDir,
			TmpDir:      tempDir,
			Compression: common.GzipCompression,
		},
		Username: "",
		Password: "",
		Insecure: insecureConf,
	}
	renderedACIs, err := docker2aci.ConvertRemoteRepo(start, config)
	if err != nil {
		return err
	}
	if len(renderedACIs) > 1 {
		return fmt.Errorf("internal error: docker2aci didn't squash the image")
	}
	if len(renderedACIs) == 0 {
		return fmt.Errorf("internal error: docker2aci didn't produce any images")
	}
	absRenderedACI, err := filepath.Abs(renderedACIs[0])
	if err != nil {
		return err
	}

	return util.ExtractImage(absRenderedACI, a.CurrentACIPath, nil)
}