This change orchestrates function builds. Environments (in v2) define a builder image, just like they do a runtime image. The builder image contains a build script that's invoked with source and deployment paths (as env vars). The buildermgr watches for environments with build images defined, and creates build deployments and services. Functions can define source and deployment. Buildermgr watches for functions with source code (and build status == pending) and invokes the environment's builder when appropriate. It captures logs from the build and sets the build status (success/failure) and build lots into the PackageStatus.
81 lines
1.4 KiB
Go
81 lines
1.4 KiB
Go
package client
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"io/ioutil"
|
|
"log"
|
|
"net/http"
|
|
//"time"
|
|
|
|
"github.com/fission/fission"
|
|
"github.com/fission/fission/environments/fetcher"
|
|
//"github.com/fission/fission/router"
|
|
)
|
|
|
|
type (
|
|
Client struct {
|
|
url string
|
|
}
|
|
)
|
|
|
|
func MakeClient(fetcherUrl string) *Client {
|
|
return &Client{
|
|
url: fetcherUrl,
|
|
}
|
|
}
|
|
|
|
func (c *Client) Fetch(fr *fetcher.FetchRequest) error {
|
|
body, err := json.Marshal(fr)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// client := http.Client{
|
|
// Transport: router.MakeRetryingRoundTripper(10, 50*time.Millisecond),
|
|
// }
|
|
|
|
resp, err := http.Post(c.url, "application/json", bytes.NewReader(body))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer resp.Body.Close()
|
|
|
|
if resp.StatusCode != 200 {
|
|
return fission.MakeErrorFromHTTP(resp)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (c *Client) Upload(fr *fetcher.UploadRequest) (*fetcher.UploadResponse, error) {
|
|
body, err := json.Marshal(fr)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
resp, err := http.Post(c.url+"/upload", "application/json", bytes.NewReader(body))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer resp.Body.Close()
|
|
|
|
if resp.StatusCode != 200 {
|
|
return nil, fission.MakeErrorFromHTTP(resp)
|
|
}
|
|
|
|
rBody, err := ioutil.ReadAll(resp.Body)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
log.Printf("Received upload response: %v", string(rBody))
|
|
|
|
uploadReq := fetcher.UploadResponse{}
|
|
err = json.Unmarshal([]byte(rBody), &uploadReq)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &uploadReq, nil
|
|
}
|