refactor!: separate runtime releases from panel source
This commit is contained in:
@@ -189,24 +189,15 @@ func (c *Client) Logs(ctx context.Context, id string) (string, error) {
|
||||
return output.String(), nil
|
||||
}
|
||||
|
||||
func (c *Client) Build(ctx context.Context, tar io.Reader, version, tag string, onLog func(string)) (string, error) {
|
||||
return c.build(ctx, tar, version, tag, nil, onLog)
|
||||
}
|
||||
|
||||
func (c *Client) BuildRelease(ctx context.Context, tar io.Reader, version, tag, releaseID, repository, commit string, onLog func(string)) (string, error) {
|
||||
return c.build(ctx, tar, version, tag, map[string]string{"dsh-mgr.release": releaseID, "dsh-mgr.source": repository, "dsh-mgr.commit": commit}, onLog)
|
||||
}
|
||||
|
||||
func (c *Client) build(ctx context.Context, tar io.Reader, version, tag string, labels map[string]string, onLog func(string)) (string, error) {
|
||||
labels := map[string]string{"dsh-mgr.release": releaseID, "dsh-mgr.source": repository, "dsh-mgr.commit": commit}
|
||||
args, err := json.Marshal(map[string]string{"DSH_VERSION": version})
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
query := url.Values{"t": {tag}, "buildargs": {string(args)}, "rm": {"1"}}
|
||||
if labels != nil {
|
||||
data, _ := json.Marshal(labels)
|
||||
query.Set("labels", string(data))
|
||||
}
|
||||
data, _ := json.Marshal(labels)
|
||||
query.Set("labels", string(data))
|
||||
resp, err := c.Stream(ctx, http.MethodPost, "/build?"+query.Encode(), tar, "application/x-tar")
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
||||
@@ -201,7 +201,7 @@ func TestBuild(t *testing.T) {
|
||||
}
|
||||
})
|
||||
var logs []string
|
||||
id, err := client.Build(context.Background(), strings.NewReader("caller tar bytes"), "1.2.3", "test:1", func(s string) { logs = append(logs, s) })
|
||||
id, err := client.BuildRelease(context.Background(), strings.NewReader("caller tar bytes"), "1.2.3", "test:1", "release", "repository", "commit", func(s string) { logs = append(logs, s) })
|
||||
if err != nil || id != "sha256:image" || len(logs) != 1 || logs[0] != "step 1\n" {
|
||||
t.Fatalf("id=%q logs=%v err=%v", id, logs, err)
|
||||
}
|
||||
@@ -219,7 +219,7 @@ func TestBuildErrors(t *testing.T) {
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
client := testClient(t, func(w http.ResponseWriter, r *http.Request) { io.WriteString(w, tc.data) })
|
||||
id, err := client.Build(context.Background(), nil, "1", "test", nil)
|
||||
id, err := client.BuildRelease(context.Background(), nil, "1", "test", "release", "repository", "commit", nil)
|
||||
if err == nil || !strings.Contains(err.Error(), tc.want) || id != "" {
|
||||
t.Fatalf("id=%q err=%v", id, err)
|
||||
}
|
||||
@@ -235,7 +235,7 @@ func TestBuildCancellation(t *testing.T) {
|
||||
})
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
||||
defer cancel()
|
||||
_, err := client.Build(ctx, nil, "1", "test", func(string) { cancel() })
|
||||
_, err := client.BuildRelease(ctx, nil, "1", "test", "release", "repository", "commit", func(string) { cancel() })
|
||||
if !errors.Is(err, context.Canceled) {
|
||||
t.Fatalf("err=%v", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user