Esempio n. 1
0
func (a *ACBuild) beginFromLocalImage(start string) error {
	finfo, err := os.Stat(start)
	if err != nil {
		return err
	}
	if finfo.IsDir() {
		return fmt.Errorf("provided starting ACI is a directory: %s", start)
	}
	err = util.ExtractImage(start, a.CurrentACIPath, nil)
	if err != nil {
		return err
	}

	for _, file := range []struct {
		FileName string
		FilePath string
	}{
		{"manifest file", path.Join(a.CurrentACIPath, aci.ManifestFile)},
		{"rootfs directory", path.Join(a.CurrentACIPath, aci.RootfsDir)},
	} {
		_, err = os.Stat(file.FilePath)
		switch {
		case os.IsNotExist(err):
			fmt.Fprintf(os.Stderr, "%s is missing, assuming build is beginning with a tar of a rootfs\n", file.FileName)
			return a.startedFromTar()
		case err != nil:
			return err
		}
	}
	return nil
}
Esempio n. 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)
}
Esempio n. 3
0
// FetchAndRender will fetch the given image and all of its dependencies if
// they have not been fetched yet, and will then render them on to the
// filesystem if they have not been rendered yet.
func (r Registry) FetchAndRender(imagename types.ACIdentifier, labels types.Labels, size uint) error {
	err := r.Fetch(imagename, labels, size, true)
	if err != nil {
		return err
	}

	filesToRender, err := acirenderer.GetRenderedACI(imagename,
		labels, r)
	if err != nil {
		return err
	}

filesloop:
	for _, fs := range filesToRender {
		_, err := os.Stat(path.Join(r.DepStoreExpandedPath, fs.Key, "rendered"))
		switch {
		case os.IsNotExist(err):
			break
		case err != nil:
			return err
		default:
			// This ACI has already been rendered
			continue filesloop
		}

		err = util.ExtractImage(path.Join(r.DepStoreTarPath, fs.Key),
			path.Join(r.DepStoreExpandedPath, fs.Key), fs.FileMap)
		if err != nil {
			return err
		}

		rfile, err := os.Create(
			path.Join(r.DepStoreExpandedPath, fs.Key, "rendered"))
		if err != nil {
			return err
		}
		rfile.Close()
	}
	return nil
}
Esempio n. 4
0
func (a *ACBuild) beginFromRemoteImage(start string, insecure bool) error {
	app, err := discovery.NewAppFromString(start)
	if err != nil {
		return err
	}
	labels, err := types.LabelsFromMap(app.Labels)
	if err != nil {
		return err
	}

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

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

	reg := registry.Registry{
		DepStoreTarPath:      tmpDepStoreTarPath,
		DepStoreExpandedPath: tmpDepStoreExpandedPath,
		Insecure:             insecure,
		Debug:                a.Debug,
	}

	err = reg.Fetch(app.Name, labels, 0, false)
	if err != nil {
		if urlerr, ok := err.(*url.Error); ok {
			if operr, ok := urlerr.Err.(*net.OpError); ok {
				if dnserr, ok := operr.Err.(*net.DNSError); ok {
					if dnserr.Err == "no such host" {
						return fmt.Errorf("unknown host when fetching image, check your connection and local file paths must start with '/' or '.'")
					}
				}
			}
		}
		return err
	}

	files, err := ioutil.ReadDir(tmpDepStoreTarPath)
	if err != nil {
		return err
	}

	if len(files) != 1 {
		var filelist string
		for _, file := range files {
			if filelist == "" {
				filelist = file.Name()
			} else {
				filelist = filelist + ", " + file.Name()
			}
		}
		panic("unexpected number of files in store after download: " + filelist)
	}

	return util.ExtractImage(path.Join(tmpDepStoreTarPath, files[0].Name()), a.CurrentACIPath, nil)
}