Beispiel #1
0
func create(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
	defer r.Body.Close()
	var opts schema.BuildCreateOpts
	err := json.NewDecoder(r.Body).Decode(&opts)
	if err != nil {
		log.Fatal(err)
		ren.JSON(w, http.StatusInternalServerError, map[string]string{"status": "internal server error"})
		return
	}

	build := schema.NewBuild(&opts)
	err = reg.Set(build)
	if err != nil {
		log.Fatal(err)
		ren.JSON(w, http.StatusInternalServerError, map[string]string{"status": "internal server error"})
		return
	}
	ren.JSON(w, http.StatusAccepted, build)

	go func() {
		if err := checkoutGitRepository(build, DefaultSourceBaseDir); err != nil {
			return
		}

		if err := dockerBuild(build); err != nil {
			return
		}

		go dockerPush(build)
		go pushCache(build)
	}()
}
Beispiel #2
0
func TestCheckoutGitRepository(t *testing.T) {
	opts := schema.BuildCreateOpts{
		SourceRepo: "wantedly/risu",
		ImageName:  "quay.io/wantedly/risu:test",
	}
	build := schema.NewBuild(&opts)
	err := checkoutGitRepository(build, "/tmp/risu/src/github.com/")
	if err != nil {
		t.Error(err)
	}
	_, err = os.Stat("/tmp/risu/src/github.com/wantedly/risu/.git")
	if err != nil {
		t.Errorf("Fail to clone git repository\nerror: %v", err)
	}

	// Check for second try to test existing repository case
	err = checkoutGitRepository(build, "/tmp/risu/src/github.com/")
	if err != nil {
		t.Error(err)
	}
	_, err = os.Stat("/tmp/risu/src/github.com/wantedly/risu/.git")
	if err != nil {
		t.Errorf("Fail to fetch&checkout git repository\nerror: %v", err)
	}
}
Beispiel #3
0
func (r *EtcdRegistry) Create(opts schema.BuildCreateOpts) (schema.Build, error) {
	build := schema.NewBuild(&opts)
	j, err := marshal(build)
	if err != nil {
		return build, err
	}

	key := path.Join(r.keyPrefix, build.ID.String())
	_, err = r.etcd.Create(key, string(j), DefaultExpireSeconds)
	if err != nil {
		return build, err
	}

	return build, nil
}
Beispiel #4
0
func (r *LocalFsRegistry) Create(opts schema.BuildCreateOpts) (schema.Build, error) {
	build := schema.NewBuild(&opts)
	b, err := json.Marshal(build)
	if err != nil {
		return build, err
	}

	file, err := os.Create(r.dir + build.ID.String() + ".json")
	if err != nil {
		return build, err
	}

	defer file.Close()

	buildData := []byte(string(b))

	_, err = file.Write(buildData)
	if err != nil {
		return build, err
	}
	return build, nil
}