this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat(controller): push platform manifests

+99
+43
controller/activities/oci.go
··· 1 + package activities 2 + 3 + import ( 4 + "bytes" 5 + "context" 6 + "encoding/json" 7 + "os/exec" 8 + 9 + "go.temporal.io/sdk/activity" 10 + ) 11 + 12 + type PushResult struct { 13 + Reference string `json:"reference"` 14 + MediaType string `json:"mediaType"` 15 + Digest string `json:"digest"` 16 + Size int `json:"size"` 17 + Annotations map[string]string `json:"annotations"` 18 + ArtifactType string `json:"artifactType"` 19 + ReferenceAsTags []string `json:"referenceAsTags"` 20 + } 21 + 22 + func PushManifests(ctx context.Context, path string, image string) (*PushResult, error) { 23 + logger := activity.GetLogger(ctx) 24 + cmd := exec.CommandContext(ctx, "nix", "develop", "--command", "oras", "push", "--format=json", "--plain-http", image, ".") 25 + cmd.Dir = path 26 + 27 + var stdout, stderr bytes.Buffer 28 + cmd.Stdout = &stdout 29 + cmd.Stderr = &stderr 30 + 31 + if err := cmd.Run(); err != nil { 32 + logger.Error("oras push failed", "error", err, "stderr", stderr.String()) 33 + return nil, err 34 + } 35 + 36 + var result PushResult 37 + if err := json.Unmarshal(stdout.Bytes(), &result); err != nil { 38 + logger.Error("failed to parse oras output", "error", err, "output", stdout.String()) 39 + return nil, err 40 + } 41 + 42 + return &result, nil 43 + }
+2
controller/worker/main.go
··· 24 24 w := worker.New(temporalClient, "cloudlab", worker.Options{}) 25 25 26 26 w.RegisterWorkflow(workflows.Infra) 27 + w.RegisterWorkflow(workflows.Platform) 27 28 w.RegisterActivity(activities.Clone) 28 29 w.RegisterActivity(activities.ChangedModules) 29 30 w.RegisterActivity(activities.TerragruntGraph) 30 31 w.RegisterActivity(activities.PruneGraph) 31 32 w.RegisterActivity(activities.TerragruntApply) 33 + w.RegisterActivity(activities.PushManifests) 32 34 33 35 err = w.Run(worker.InterruptCh()) 34 36 if err != nil {
+54
controller/workflows/platform.go
··· 1 + package workflows 2 + 3 + import ( 4 + "time" 5 + 6 + "cloudlab/controller/activities" 7 + 8 + "go.temporal.io/sdk/temporal" 9 + "go.temporal.io/sdk/workflow" 10 + ) 11 + 12 + type PlatformInput struct { 13 + Url string 14 + Revision string 15 + Registry string 16 + Cluster string 17 + } 18 + 19 + func Platform(ctx workflow.Context, input PlatformInput) error { 20 + logger := workflow.GetLogger(ctx) 21 + logger.Info("Platform workflow started", "platform", input) 22 + 23 + var path string 24 + if err := workflow.ExecuteActivity( 25 + workflow.WithActivityOptions(ctx, workflow.ActivityOptions{ 26 + StartToCloseTimeout: 1 * time.Minute, 27 + RetryPolicy: &temporal.RetryPolicy{ 28 + MaximumAttempts: 3, 29 + }, 30 + }), 31 + activities.Clone, 32 + input.Url, 33 + input.Revision, 34 + ).Get(ctx, &path); err != nil { 35 + return err 36 + } 37 + 38 + var pushResult *activities.PushResult 39 + if err := workflow.ExecuteActivity( 40 + workflow.WithActivityOptions(ctx, workflow.ActivityOptions{ 41 + StartToCloseTimeout: 5 * time.Minute, 42 + RetryPolicy: &temporal.RetryPolicy{ 43 + MaximumAttempts: 2, 44 + }, 45 + }), 46 + activities.PushManifests, 47 + path+"/platform/"+input.Cluster, 48 + input.Registry+"/platform:"+input.Cluster, 49 + ).Get(ctx, &pushResult); err != nil { 50 + return err 51 + } 52 + 53 + return nil 54 + }