Ejemplo n.º 1
0
func (aci *Aci) upload(name *common.ACFullname) error {
	if Home.Config.Push.Type == "maven" && name.DomainName() == "aci.blbl.cr" { // TODO this definitely need to be removed
		logs.WithF(aci.fields).Info("Uploading aci")
		if err := common.ExecCmd("curl", "-f", "-i",
			"-F", "r=releases",
			"-F", "hasPom=false",
			"-F", "e=aci",
			"-F", "g=com.blablacar.aci.linux.amd64",
			"-F", "p=aci",
			"-F", "v="+name.Version(),
			"-F", "a="+strings.Split(string(name.Name()), "/")[1],
			"-F", "file=@"+aci.target+pathImageGzAci,
			"-u", Home.Config.Push.Username+":"+Home.Config.Push.Password,
			Home.Config.Push.Url+"/service/local/artifact/maven/content"); err != nil {
			return errs.WithEF(err, aci.fields, "Failed to push aci")
		}
	} else {
		systemConf := Home.Config.Rkt.SystemConfig
		if systemConf == "" {
			systemConf = "/usr/lib/rkt"
		}
		localConf := Home.Config.Rkt.LocalConfig
		if localConf == "" {
			localConf = "/etc/rkt"
		}

		conf, err := config.GetConfigFrom(systemConf, localConf)
		if err != nil {
			return errs.WithEF(err, aci.fields, "Failed to get rkt configuration")
		}

		upload := Uploader{
			Acipath: aci.target + pathImageGzAci,
			Ascpath: aci.target + pathImageGzAciAsc,
			Uri:     aci.manifest.NameAndVersion.String(),
			Debug:   false,
			SetHTTPHeaders: func(r *http.Request) {
				if r.URL == nil {
					return
				}
				headerer, ok := conf.AuthPerHost[r.URL.Host]
				if !ok {
					logs.WithFields(aci.fields).WithField("domain", r.URL.Host).
						Warn("No auth credential found in rkt configuration for this domain")
					return
				}
				header := headerer.Header()
				for k, v := range header {
					r.Header[k] = append(r.Header[k], v...)
				}
			},
		}
		err = upload.Upload()
		if err != nil {
			return errs.WithEF(err, aci.fields, "Failed to upload aci")
		}

	}
	return nil
}
Ejemplo n.º 2
0
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
}
Ejemplo n.º 3
0
Archivo: env.go Proyecto: blablacar/ggn
func (e Env) runFleetCmdInternal(getOutput bool, args []string) (string, string, error) {
	logs.WithF(e.fields).WithField("command", strings.Join(args, " ")).Debug("Running command on fleet")
	if e.config.Fleet.Endpoint == "" {
		return "", "", errors.New("Cannot find fleet.endpoint env config to call fleetctl")
	}

	envs := map[string]string{}
	envs[FLEETCTL_ENDPOINT] = e.config.Fleet.Endpoint
	if e.config.Fleet.Username != "" {
		envs[FLEETCTL_SSH_USERNAME] = e.config.Fleet.Username
	}
	envs[FLEETCTL_STRICT_HOST_KEY_CHECKING] = fmt.Sprintf("%t", e.config.Fleet.Strict_host_key_checking)
	envs[FLEETCTL_SUDO] = fmt.Sprintf("%t", e.config.Fleet.Sudo)

	args = append([]string{"fleetctl"}, args...)
	for key, val := range envs {
		args = append([]string{key + "='" + val + "'"}, args...)
	}

	var stdout string
	var stderr string
	var err error
	if getOutput {
		stdout, stderr, err = common.ExecCmdGetStdoutAndStderr("bash", "-c", strings.Join(args, " "))
	} else {
		err = common.ExecCmd("bash", "-c", strings.Join(args, " "))
	}
	return stdout, stderr, err
}
Ejemplo n.º 4
0
Archivo: main.go Proyecto: puckel/dgr
func giveBackUserRights(path string) {
	uid := "0"
	gid := "0"
	if os.Getenv("SUDO_UID") != "" {
		uid = os.Getenv("SUDO_UID")
		gid = os.Getenv("SUDO_GID")
	}
	common.ExecCmd("chown", "-R", uid+":"+gid, path)
}
Ejemplo n.º 5
0
Archivo: aci.go Proyecto: puckel/dgr
func (aci *Aci) zipAci() error {
	if _, err := os.Stat(aci.target + pathImageGzAci); err == nil {
		return nil
	}
	if stdout, stderr, err := common.ExecCmdGetStdoutAndStderr("gzip", "-k", aci.target+pathImageAci); err != nil {
		return errs.WithEF(err, aci.fields.WithField("path", aci.target+pathImageAci).WithField("stdout", stdout).WithField("stderr", stderr), "Failed to zip aci")
	}
	if err := common.ExecCmd("mv", aci.target+pathImageAci+".gz", aci.target+pathImageGzAci); err != nil {
		return errs.WithEF(err, aci.fields.WithField("from", aci.target+pathImageAci+".gz").
			WithField("to", aci.target+pathImageGzAci), "Failed to rename zip aci")
	}
	return nil
}
Ejemplo n.º 6
0
func (aci *Aci) Sign() error {
	logs.WithF(aci.fields).Debug("Signing")

	if err := aci.EnsureZip(); err != nil {
		return errs.WithEF(err, aci.fields, "Failed to prepare image for signature")
	}

	err := common.ExecCmd("gpg", "--armor", "--output", aci.target+pathImageGzAciAsc, "--detach-sig", aci.target+pathImageGzAci)
	if err != nil {
		return errs.WithEF(err, aci.fields, "Failed to sign image")
	}
	return nil
}
Ejemplo n.º 7
0
func (u *Unit) DisplayDiff() error {
	local, remote, err := u.serviceLocalAndRemoteContent()
	if err != nil {
		return err
	}

	localPath := "/tmp/" + u.Name + "__local"
	remotePath := "/tmp/" + u.Name + "__remote"

	ioutil.WriteFile(localPath, []byte(local), 0644)
	defer os.Remove(localPath)
	ioutil.WriteFile(remotePath, []byte(remote), 0644)
	defer os.Remove(remotePath)
	return common.ExecCmd("git", "diff", "--word-diff", remotePath, localPath)
}
Ejemplo n.º 8
0
func (aci *Aci) Push() error {
	defer aci.giveBackUserRightsToTarget()
	if Home.Config.Push.Type == "" {
		return errs.WithF(aci.fields, "Cannot push, push is not configured in dgr global configuration file")
	}

	if err := aci.EnsureBuilt(); err != nil {
		return err
	}

	if aci.args.Test {
		aci.args.Test = false
		if err := aci.Test(); err != nil {
			return err
		}
	}

	logs.WithF(aci.fields).Info("Gzipping aci before upload")

	im, err := common.ExtractManifestFromAci(aci.target + pathImageAci)
	if err != nil {
		return errs.WithEF(err, aci.fields.WithField("file", pathImageAci), "Failed to extract manifest from aci file")
	}
	val, ok := im.Labels.Get("version")
	if !ok {
		return errs.WithEF(err, aci.fields.WithField("file", pathImageAci), "Failed to get version from aci manifest")
	}

	if err := aci.zipAci(); err != nil {
		return errs.WithEF(err, aci.fields, "Failed to zip aci")
	}

	logs.WithF(aci.fields).Info("Uploading aci")
	if err := common.ExecCmd("curl", "-f", "-i",
		"-F", "r=releases",
		"-F", "hasPom=false",
		"-F", "e=aci",
		"-F", "g=com.blablacar.aci.linux.amd64",
		"-F", "p=aci",
		"-F", "v="+val,
		"-F", "a="+strings.Split(string(im.Name), "/")[1],
		"-F", "file=@"+aci.target+pathImageGzAci,
		"-u", Home.Config.Push.Username+":"+Home.Config.Push.Password,
		Home.Config.Push.Url+"/service/local/artifact/maven/content"); err != nil {
		return errs.WithEF(err, aci.fields, "Failed to push aci")
	}
	return nil
}
Ejemplo n.º 9
0
func (aci *Aci) signFile(file string) error {
	sign, err := Home.Config.GetSignKeyring(aci.manifest.NameAndVersion.DomainName())
	if err != nil {
		return errs.WithEF(err, aci.fields, "Failed to sign image. Cannot found keyring")
	}
	if sign.Disabled {
		logs.WithF(aci.fields).WithField("domain", aci.manifest.NameAndVersion.DomainName()).Warn("Sign disabled for this aci's domain")
		return nil
	}

	if err := common.ExecCmd("gpg", "--yes", "--no-default-keyring", "--armor",
		"--keyring", sign.Keyring, "--output", file+suffixAsc, "--detach-sig", file); err != nil {
		return errs.WithEF(err, aci.fields, "Failed to sign image")
	}
	return nil
}
Ejemplo n.º 10
0
func (p *Pod) Push() error {
	logs.WithF(p.fields).Info("Pushing")

	if err := p.CleanAndBuild(); err != nil {
		return err
	}

	for _, e := range p.manifest.Pod.Apps {
		tmpl, err := p.toAciManifestTemplate(e)
		if err != nil {
			return err
		}

		aci, err := NewAciWithManifest(p.path+"/"+e.Name, p.args, tmpl, p.checkWg)
		if err != nil {
			return errs.WithEF(err, p.fields.WithField("name", e.Name), "Cannot prepare aci")
		}
		aci.podName = &p.manifest.Name
		if err := aci.Push(); err != nil {
			return err
		}
	}

	if err := common.ExecCmd("curl", "-i",
		"-F", "r=releases",
		"-F", "hasPom=false",
		"-F", "e=pod",
		"-F", "g=com.blablacar.aci.linux.amd64",
		"-F", "p=pod",
		"-F", "v="+p.manifest.Name.Version(),
		"-F", "a="+p.manifest.Name.ShortName(),
		"-F", "file=@"+p.target+"/pod-manifest.json",
		"-u", Home.Config.Push.Username+":"+Home.Config.Push.Password,
		Home.Config.Push.Url+"/service/local/artifact/maven/content"); err != nil {

		return errs.WithEF(err, p.fields, "Failed to push pod")
	}

	return nil
}
Ejemplo n.º 11
0
Archivo: env.go Proyecto: blablacar/ggn
func (e Env) runHook(path string, info HookInfo) {
	logs.WithFields(e.fields).WithField("path", path).WithField("info", info).Debug("Running hook")
	files, err := ioutil.ReadDir(e.path + PATH_HOOKS + path)
	if err != nil {
		logs.WithEF(err, e.fields).Debug("Cannot read hook directory")
		return
	}

	envs := map[string]string{}
	envs["ENV"] = e.name
	envs["COMMAND"] = info.Command
	if info.Unit != nil {
		envs["UNIT"] = info.Unit.GetName()
	}
	if info.Service != nil {
		envs["SERVICE"] = info.Service.GetName()
	}
	envs["WHO"] = ggn.GetUserAndHost()
	envs["ACTION"] = info.Action
	envs["ATTRIBUTES"] = info.Attributes
	envs["GGN_HOME_PATH"] = ggn.Home.Path

	for _, f := range files {
		if !f.IsDir() {
			hookFields := data.WithField("name", f.Name())

			args := []string{e.path + PATH_HOOKS + path + "/" + f.Name()}
			for key, val := range envs {
				args = append([]string{key + "='" + strings.Replace(val, "'", "'\"'\"'", -1) + "'"}, args...)
			}

			logs.WithFields(hookFields).Debug("Running Hook")
			if err := common.ExecCmd("bash", "-c", strings.Join(args, " ")); err != nil {
				logs.WithFields(hookFields).Fatal("Hook status is failed")
			}
		}
	}
}
Ejemplo n.º 12
0
func (p *Pod) Push() error {
	logs.WithF(p.fields).Info("Pushing")

	if err := p.CleanAndBuild(); err != nil {
		return err
	}

	for _, e := range p.manifest.Pod.Apps {
		aci, err := p.toPodAci(e)
		if err != nil {
			return err
		}

		if err := aci.Push(); err != nil {
			return err
		}
	}

	if Home.Config.Push.Type == "maven" && p.manifest.Name.DomainName() == "aci.blbl.cr" {
		// TODO this definitely need to be removed
		if err := common.ExecCmd("curl", "-i",
			"-F", "r=releases",
			"-F", "hasPom=false",
			"-F", "e=pod",
			"-F", "g=com.blablacar.aci.linux.amd64",
			"-F", "p=pod",
			"-F", "v="+p.manifest.Name.Version(),
			"-F", "a="+p.manifest.Name.ShortName(),
			"-F", "file=@"+p.target+"/pod-manifest.json",
			"-u", Home.Config.Push.Username+":"+Home.Config.Push.Password,
			Home.Config.Push.Url+"/service/local/artifact/maven/content"); err != nil {

			return errs.WithEF(err, p.fields, "Failed to push pod")
		}
	}

	return nil
}