func (aci *Aci) copyAttributes() { files, err := utils.AttributeFiles(aci.path + PATH_ATTRIBUTES) if err != nil { logs.WithEF(err, aci.fields).Fatal("Cannot read attribute files") } for _, file := range files { targetPath := aci.rootfs + PATH_CNT + PATH_ATTRIBUTES + "/" + aci.manifest.NameAndVersion.ShortName() err = os.MkdirAll(targetPath, 0755) if err != nil { logs.WithEF(err, aci.fields.WithField("path", targetPath)).Fatal("Cannot create target attribute directory") } if err := utils.CopyFile(file, targetPath+"/"+filepath.Base(file)); err != nil { logs.WithEF(err, aci.fields.WithField("file", file)).Fatal("Cannot copy attribute file") } } }
func (cnt *Img) prepareTestAci() (*Img, error) { files, err := ioutil.ReadDir(cnt.path + PATH_TESTS) if err != nil { return nil, err } utils.CopyDir(cnt.path+PATH_TESTS+PATH_FILES, cnt.target+PATH_TESTS+PATH_FILES) utils.CopyDir(cnt.path+PATH_TESTS+PATH_ATTRIBUTES, cnt.target+PATH_TESTS+PATH_ATTRIBUTES) utils.CopyDir(cnt.path+PATH_TESTS+PATH_CONFD, cnt.target+PATH_TESTS+PATH_CONFD) utils.CopyDir(cnt.path+PATH_TESTS+PATH_RUNLEVELS, cnt.target+PATH_TESTS+PATH_RUNLEVELS) os.MkdirAll(cnt.target+PATH_TESTS+PATH_FILES+PATH_TESTS, 0777) for _, f := range files { if !f.IsDir() { if err := utils.CopyFile(cnt.path+PATH_TESTS+"/"+f.Name(), cnt.target+PATH_TESTS+PATH_FILES+PATH_TESTS+"/"+f.Name()); err != nil { panic(err) } } } ExecScript := strings.Replace(TEST_INIT_SCRIPT, "%%COMMAND%%", "'"+strings.Join(cnt.manifest.Aci.App.Exec, "' '")+"'", 1) ExecScript = strings.Replace(ExecScript, "%%CWD%%", "'"+cnt.manifest.Aci.App.WorkingDirectory+"'", 2) ioutil.WriteFile(cnt.target+PATH_TESTS+PATH_FILES+"/init.sh", []byte(ExecScript), 0777) fullname, err := spec.NewACFullName(cnt.manifest.NameAndVersion.Name() + "_test:" + cnt.manifest.NameAndVersion.Version()) if err != nil { panic(err) } resultMountName, _ := types.NewACName("result") testAci, err := NewAciWithManifest(cnt.target+PATH_TESTS, cnt.args, spec.AciManifest{ Aci: spec.AciDefinition{ App: &spec.CntApp{ Exec: []string{"/init.sh"}, MountPoints: []types.MountPoint{{Path: PATH_RESULT, Name: *resultMountName}}, }, Dependencies: []spec.ACFullname{BATS_ACI, cnt.manifest.NameAndVersion}, }, NameAndVersion: *fullname, }, nil) if err != nil { panic("Cannot build test aci" + err.Error()) } return testAci, nil }
func (cnt *Img) writeCntManifest() { utils.CopyFile(cnt.path+PATH_CNT_MANIFEST, cnt.target+PATH_CNT_MANIFEST) }