Example #1
0
func BuildCreate(rw http.ResponseWriter, r *http.Request) {
	log := buildsLogger("create").Start()

	build := models.NewBuild(mux.Vars(r)["app"])

	err := r.ParseMultipartForm(50 * 1024 * 1024)

	logEvent(log, build, "ParseMultipartForm", err)

	if err != nil {
		helpers.Error(log, err)
		RenderError(rw, err)
		return
	}

	err = build.Save()

	logEvent(log, build, "Save", err)

	if err != nil {
		helpers.Error(log, err)
		RenderError(rw, err)
		return
	}

	source, _, err := r.FormFile("source")

	logEvent(log, build, "FormFile", err)

	if err != nil && err != http.ErrMissingFile {
		helpers.Error(log, err)
		RenderError(rw, err)
		return
	}

	resources, err := models.ListResources(os.Getenv("RACK"))

	logEvent(log, build, "ListResources", err)

	if err != nil {
		helpers.Error(log, err)
		RenderError(rw, err)
		return
	}

	err = models.S3PutFile(resources["RegistryBucket"].Id, fmt.Sprintf("builds/%s.tgz", build.Id), source, false)

	logEvent(log, build, "S3Put", err)

	if err != nil {
		helpers.Error(log, err)
		RenderError(rw, err)
		return
	}

	ch := make(chan error)

	if source != nil {
		go build.ExecuteLocal(source, ch)

		err = <-ch

		logEvent(log, build, "ExecuteLocal", err)

		if err != nil {
			RenderError(rw, err)
		} else {
			RenderText(rw, build.Id)
		}

		return
	}

	if err == http.ErrMissingFile {
		if repo := r.FormValue("repo"); repo != "" {
			go build.ExecuteRemote(repo, ch)

			err = <-ch

			logEvent(log, build, "ExecuteRemote", err)

			if err != nil {
				RenderError(rw, err)
			} else {
				RenderText(rw, build.Id)
			}

			return
		}
	}

	err = fmt.Errorf("no source or repo")
	helpers.Error(log, err)
	RenderError(rw, err)
}
Example #2
0
func ReleaseCreate(rw http.ResponseWriter, r *http.Request) {
	log := releasesLogger("create").Start()

	vars := mux.Vars(r)
	name := vars["app"]

	manifest := GetForm(r, "manifest")
	tag := GetForm(r, "tag")

	app, err := models.GetApp(name)

	if err != nil {
		helpers.Error(log, err)
		RenderError(rw, err)
		return
	}

	release, err := app.ForkRelease()

	if err != nil {
		helpers.Error(log, err)
		RenderError(rw, err)
		return
	}

	build := models.NewBuild(app.Name)
	build.Id = tag
	build.Release = release.Id
	build.Status = "complete"

	release.Build = build.Id
	release.Manifest = manifest

	err = build.Save()

	if err != nil {
		helpers.Error(log, err)
		RenderError(rw, err)
		return
	}

	err = release.Save()

	if err != nil {
		helpers.Error(log, err)
		RenderError(rw, err)
		return
	}

	err = release.Promote()

	if err != nil {
		helpers.Error(log, err)
		RenderError(rw, err)
		return
	}

	log.Success("step=release.create app=%q", app.Name)

	RenderText(rw, "ok")
}
Example #3
0
func BuildCreate(rw http.ResponseWriter, r *http.Request) {
	log := buildsLogger("create").Start()

	err := r.ParseMultipartForm(50 * 1024 * 1024)

	if err != nil {
		helpers.Error(log, err)
		RenderError(rw, err)
		return
	}

	app := mux.Vars(r)["app"]

	build := models.NewBuild(app)

	err = build.Save()

	if err != nil {
		helpers.Error(log, err)
		RenderError(rw, err)
		return
	}

	log.Success("step=build.save app=%q", build.App)

	source, _, err := r.FormFile("source")

	if err != nil && err != http.ErrMissingFile {
		helpers.Error(log, err)
		RenderError(rw, err)
		return
	}

	ch := make(chan error)

	if source != nil {
		go build.ExecuteLocal(source, ch)

		if err = <-ch; err != nil {
			RenderError(rw, err)
		} else {
			RenderText(rw, build.Id)
		}

		return
	}

	if err == http.ErrMissingFile {
		if repo := r.FormValue("repo"); repo != "" {
			go build.ExecuteRemote(repo, ch)

			if err = <-ch; err != nil {
				RenderError(rw, err)
			} else {
				RenderText(rw, build.Id)
			}

			return
		}
	}

	err = fmt.Errorf("no source or repo")
	helpers.Error(log, err)
	RenderError(rw, err)
}