Пример #1
0
func (b *Build) ExecuteRemote(repo string, cache bool, manifest string, ch chan error) {
	started := time.Now()

	b.Status = "building"
	err := b.Save()

	if err != nil {
		helpers.TrackError("build", err, map[string]interface{}{"type": "remote", "at": "b.Save"})
		b.buildError(err, ch)
		return
	}

	args, err := b.buildArgs(cache, manifest)

	if err != nil {
		helpers.TrackError("build", err, map[string]interface{}{"type": "remote", "at": "b.buildArgs"})
		b.buildError(err, ch)
		return
	}

	args = append(args, b.App, repo)

	err = b.execute(args, nil, ch)

	if err != nil {
		helpers.TrackError("build", err, map[string]interface{}{"type": "remote", "at": "b.execute"})
		b.buildError(err, ch)
		return
	}

	NotifySuccess("build:create", map[string]string{"id": b.Id, "app": b.App})
	fmt.Printf("ns=kernel cn=build at=ExecuteRemote state=success step=build.execute app=%q build=%q\n", b.App, b.Id)
	helpers.TrackSuccess("build", map[string]interface{}{"type": "remote", "elapsed": time.Now().Sub(started).Nanoseconds() / 1000000})
}
Пример #2
0
func (srcBuild *Build) CopyTo(destApp App) (*Build, error) {
	started := time.Now()

	srcApp, err := GetApp(srcBuild.App)

	if err != nil {
		return nil, err
	}

	// generate a new build ID
	destBuild := NewBuild(destApp.Name)

	// copy src build properties
	destBuild.Manifest = srcBuild.Manifest

	// set copy properties
	destBuild.Description = fmt.Sprintf("Copy of %s %s", srcBuild.App, srcBuild.Id)
	destBuild.Status = "copying"

	err = destBuild.Save()

	if err != nil {
		destBuild.copyError(err)
		return nil, err
	}

	// pull, tag, push images
	manifest, err := LoadManifest(destBuild.Manifest, &destApp)

	if err != nil {
		destBuild.copyError(err)
		return nil, err
	}

	for _, entry := range manifest {
		var srcImg, destImg string

		srcImg = entry.RegistryImage(srcApp, srcBuild.Id)
		destImg = entry.RegistryImage(&destApp, destBuild.Id)

		destBuild.Logs += fmt.Sprintf("RUNNING: docker pull %s\n", srcImg)

		out, err := exec.Command("docker", "pull", srcImg).CombinedOutput()

		if err != nil {
			destBuild.copyError(err)
			return nil, err
		}

		destBuild.Logs += string(out)

		destBuild.Logs += fmt.Sprintf("RUNNING: docker tag -f %s %s\n", srcImg, destImg)

		out, err = exec.Command("docker", "tag", "-f", srcImg, destImg).CombinedOutput()

		if err != nil {
			destBuild.copyError(err)
			return nil, err
		}

		destBuild.Logs += string(out)

		destBuild.Logs += fmt.Sprintf("RUNNING: docker push %s\n", destImg)

		out, err = exec.Command("docker", "push", destImg).CombinedOutput()

		if err != nil {
			destBuild.copyError(err)
			return nil, err
		}

		destBuild.Logs += string(out)

	}

	// make release for new build
	release, err := destApp.ForkRelease()

	if err != nil {
		destBuild.copyError(err)
		return nil, err
	}

	release.Build = destBuild.Id
	release.Manifest = destBuild.Manifest

	err = release.Save()

	if err != nil {
		destBuild.copyError(err)
		return nil, err
	}

	// finalize new build
	destBuild.Ended = time.Now()
	destBuild.Release = release.Id
	destBuild.Status = "complete"

	err = destBuild.Save()

	if err != nil {
		destBuild.copyError(err)
		return nil, err
	}

	NotifySuccess("build:copy", map[string]string{"id": destBuild.Id, "app": destBuild.App})
	helpers.TrackSuccess("build-copy", map[string]interface{}{"elapsed": time.Now().Sub(started).Nanoseconds() / 1000000})

	return &destBuild, nil
}
Пример #3
0
func (b *Build) ExecuteIndex(index Index, cache bool, manifest string, ch chan error) {
	started := time.Now()

	b.Status = "building"
	err := b.Save()

	if err != nil {
		helpers.TrackError("build", err, map[string]interface{}{"type": "remote", "at": "b.Save"})
		b.buildError(err, ch)
		return
	}

	args, err := b.buildArgs(cache, manifest)

	if err != nil {
		helpers.TrackError("build", err, map[string]interface{}{"type": "index", "at": "b.buildArgs"})
		b.buildError(err, ch)
		return
	}

	dir, err := ioutil.TempDir("", "source")

	if err != nil {
		helpers.TrackError("build", err, map[string]interface{}{"type": "index", "at": "ioutil.TempDir"})
		b.buildError(err, ch)
		return
	}

	err = os.Chmod(dir, 0755)

	if err != nil {
		helpers.TrackError("build", err, map[string]interface{}{"type": "index", "at": "os.Chmod"})
		b.buildError(err, ch)
		return
	}

	err = index.Download(dir)

	if err != nil {
		helpers.TrackError("build", err, map[string]interface{}{"type": "index", "at": "index.Download"})
		b.buildError(err, ch)
		return
	}

	tgz, err := createTarball(dir)

	if err != nil {
		helpers.TrackError("build", err, map[string]interface{}{"type": "index", "at": "createTarball"})
		b.buildError(err, ch)
		return
	}

	args = append(args, b.App, "-")

	err = b.execute(args, bytes.NewReader(tgz), ch)

	if err != nil {
		helpers.TrackError("build", err, map[string]interface{}{"type": "index", "at": "b.execute"})
		b.buildError(err, ch)
		return
	}

	NotifySuccess("build:create", map[string]string{"id": b.Id, "app": b.App})
	fmt.Printf("ns=kernel cn=build at=ExecuteIndex state=success step=build.execute app=%q build=%q\n", b.App, b.Id)
	helpers.TrackSuccess("build", map[string]interface{}{"type": "index", "elapsed": time.Now().Sub(started).Nanoseconds() / 1000000})
}