func (aci *Aci) prepareRktRunArguments(command common.BuilderCommand, builderHash string, stage1Hash string) []string { var args []string if logs.IsDebugEnabled() { args = append(args, "--debug") } args = append(args, "--set-env="+common.EnvDgrVersion+"="+BuildVersion) args = append(args, "--set-env="+common.EnvLogLevel+"="+logs.GetLevel().String()) args = append(args, "--set-env="+common.EnvAciPath+"="+aci.path) args = append(args, "--set-env="+common.EnvAciTarget+"="+aci.target) args = append(args, "--set-env="+common.EnvBuilderCommand+"="+string(command)) args = append(args, "--set-env="+common.EnvCatchOnError+"="+strconv.FormatBool(aci.args.CatchOnError)) args = append(args, "--set-env="+common.EnvCatchOnStep+"="+strconv.FormatBool(aci.args.CatchOnStep)) args = append(args, "--net=host") args = append(args, "--insecure-options=image") args = append(args, "--uuid-file-save="+aci.target+pathBuilderUuid) args = append(args, "--interactive") if stage1Hash != "" { args = append(args, "--stage1-hash="+stage1Hash) } else { args = append(args, "--stage1-name="+aci.manifest.Builder.Image.String()) } for _, v := range aci.args.SetEnv.Strings() { args = append(args, "--set-env="+v) } args = append(args, builderHash) return args }
func (b *Builder) runBuildSetup() error { //TODO REMOVE if empty, err := common.IsDirEmpty(b.aciHomePath + PATH_RUNLEVELS + PATH_BUILD_SETUP); empty || err != nil { return nil } logs.WithF(b.fields).Info("Running build setup") for _, e := range manifestApp(b.pod).App.Environment { logs.WithField("name", e.Name).WithField("value", e.Value).Debug("Adding environment var") os.Setenv(e.Name, e.Value) } logs.WithF(b.fields).Warn("Build setup is deprecated and will be removed. it create unreproductible builds and run as root directly on the host. Please use builder dependencies and builder runlevels instead") time.Sleep(5 * time.Second) os.Setenv("BASEDIR", b.aciHomePath) os.Setenv("TARGET", b.stage2Rootfs+"/..") os.Setenv("ROOTFS", b.stage2Rootfs+"/../rootfs") os.Setenv(common.EnvLogLevel, logs.GetLevel().String()) if err := common.ExecCmd(b.stage1Rootfs + PATH_DGR + PATH_BUILDER + "/stage2/build-setup.sh"); err != nil { return errs.WithEF(err, b.fields, "Build setup failed") } return nil }
func (aci *Aci) runTestAci(testerHash string, hashAcis []string) error { os.MkdirAll(aci.target+pathTestsResult, 0777) defer aci.cleanupTest(testerHash, hashAcis) if err := Home.Rkt.Run([]string{"--set-env=" + common.EnvLogLevel + "=" + logs.GetLevel().String(), "--net=host", "--mds-register=false", "--uuid-file-save=" + aci.target + pathTesterUuid, "--volume=" + mountAcname + ",kind=host,source=" + aci.target + pathTestsResult, testerHash, "--exec", "/test", }); err != nil { // rkt+systemd cannot exit with fail status yet, so will not happen return errs.WithEF(err, aci.fields, "Run of test aci failed") } return nil }
func (b *Builder) prepareNspawnArgsAndEnv(commandPath string) ([]string, []string, error) { var args []string env := os.Environ() args = append(args, b.stage1Rootfs+"/dgr/usr/lib/ld-linux-x86-64.so.2") args = append(args, b.stage1Rootfs+"/dgr/usr/bin/systemd-nspawn") if context := os.Getenv(rktcommon.EnvSELinuxContext); context != "" { args = append(args, fmt.Sprintf("-Z%s", context)) } args = append(args, "--register=no") args = append(args, "-q") args = append(args, "--link-journal=auto") env = append(env, "LD_LIBRARY_PATH="+b.stage1Rootfs+"/dgr/usr/lib") if !logs.IsDebugEnabled() { args = append(args, "--quiet") } lvl := "info" switch logs.GetLevel() { case logs.FATAL: lvl = "crit" case logs.PANIC: lvl = "alert" case logs.ERROR: lvl = "err" case logs.WARN: lvl = "warning" case logs.INFO: lvl = "info" case logs.DEBUG | logs.TRACE: lvl = "debug" } args = append(args, "--uuid="+b.pod.UUID.String()) args = append(args, "--machine=dgr"+b.pod.UUID.String()) env = append(env, "SYSTEMD_LOG_LEVEL="+lvl) for _, e := range manifestApp(b.pod).App.Environment { if e.Name != common.EnvBuilderCommand && e.Name != common.EnvAciTarget { args = append(args, "--setenv="+e.Name+"="+e.Value) } } catchError, _ := manifestApp(b.pod).App.Environment.Get(common.EnvCatchOnError) catchStep, _ := manifestApp(b.pod).App.Environment.Get(common.EnvCatchOnStep) args = append(args, "--setenv="+common.EnvCatchOnError+"="+string(catchError)) args = append(args, "--setenv="+common.EnvCatchOnStep+"="+string(catchStep)) version, ok := manifestApp(b.pod).Image.Labels.Get("version") if ok { args = append(args, "--setenv=ACI_VERSION="+version) } args = append(args, "--setenv=ACI_NAME="+manifestApp(b.pod).Name.String()) args = append(args, "--setenv=ACI_EXEC="+"'"+strings.Join(manifestApp(b.pod).App.Exec, "' '")+"'") args = append(args, "--setenv=ROOTFS="+PATH_OPT+PATH_STAGE2+"/"+manifestApp(b.pod).Name.String()+common.PathRootfs) args = append(args, "--capability=all") args = append(args, "--directory="+b.stage1Rootfs) args = append(args, "--bind="+b.aciHomePath+"/:/dgr/aci-home") args = append(args, "--bind="+b.aciTargetPath+"/:/dgr/aci-target") // content, err := ioutil.ReadFile(b.aciTargetPath + common.PathManifestYmlTmpl) if err != nil { return args, env, errs.WithEF(err, b.fields.WithField("file", b.aciTargetPath+common.PathManifestYmlTmpl), "Failed to read manifest template") } aciManifest, err := common.ProcessManifestTemplate(string(content), nil, false) if err != nil { return args, env, errs.WithEF(err, b.fields.WithField("content", string(content)), "Failed to process manifest template") } for _, mount := range aciManifest.Builder.MountPoints { if strings.HasPrefix(mount.From, "~/") { user, err := user.Current() if err != nil { return args, env, errs.WithEF(err, b.fields, "Cannot found current user") } mount.From = user.HomeDir + mount.From[1:] } from := mount.From if from[0] != '/' { from = b.aciHomePath + "/" + from } if _, err := os.Stat(from); err != nil { os.MkdirAll(from, 0755) } args = append(args, "--bind="+from+":"+mount.To) } for _, mount := range aciManifest.Build.MountPoints { if strings.HasPrefix(mount.From, "~/") { user, err := user.Current() if err != nil { return args, env, errs.WithEF(err, b.fields, "Cannot found current user") } mount.From = user.HomeDir + mount.From[1:] } from := mount.From if from[0] != '/' { from = b.aciHomePath + "/" + from } if _, err := os.Stat(from); err != nil { os.MkdirAll(from, 0755) } args = append(args, "--bind="+from+":"+PATH_OPT+PATH_STAGE2+"/"+manifestApp(b.pod).Name.String()+common.PathRootfs+"/"+mount.To) } args = append(args, commandPath) return args, env, nil }