Skip to content

Commit 4c78044

Browse files
committed
major:
- chore: bugfixing - feat: added gvisor runtime - fix: misc
1 parent 6b52e51 commit 4c78044

9 files changed

Lines changed: 1317 additions & 18 deletions

File tree

examples/gvisor/main.go

Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"log"
7+
"time"
8+
9+
"github.com/rizome-dev/arc/pkg/messagequeue"
10+
"github.com/rizome-dev/arc/pkg/orchestrator"
11+
"github.com/rizome-dev/arc/pkg/runtime"
12+
"github.com/rizome-dev/arc/pkg/state"
13+
"github.com/rizome-dev/arc/pkg/types"
14+
)
15+
16+
func main() {
17+
ctx := context.Background()
18+
19+
// Try to create gVisor runtime, fall back to Docker if not available
20+
var runtimeInstance runtime.Runtime
21+
var runtimeName string
22+
23+
gvisorRuntime, err := runtime.NewGVisorRuntime(runtime.Config{
24+
Type: "gvisor",
25+
Labels: map[string]string{
26+
"managed-by": "arc",
27+
"runtime": "gvisor",
28+
},
29+
})
30+
if err != nil {
31+
fmt.Printf("gVisor runtime not available (%v), falling back to Docker...\n", err)
32+
33+
// Fall back to Docker runtime
34+
dockerRuntime, dockerErr := runtime.NewDockerRuntime(runtime.Config{
35+
Type: "docker",
36+
Labels: map[string]string{
37+
"managed-by": "arc",
38+
"runtime": "docker",
39+
},
40+
})
41+
if dockerErr != nil {
42+
log.Fatalf("Failed to create Docker runtime: %v", dockerErr)
43+
}
44+
runtimeInstance = dockerRuntime
45+
runtimeName = "Docker"
46+
} else {
47+
runtimeInstance = gvisorRuntime
48+
runtimeName = "gVisor"
49+
}
50+
51+
// Create message queue
52+
mq, err := messagequeue.NewAMQMessageQueue(messagequeue.Config{
53+
StorePath: "./arc-amq-data",
54+
WorkerPoolSize: 10,
55+
MessageTimeout: 300, // 5 minutes
56+
})
57+
if err != nil {
58+
log.Fatalf("Failed to create message queue: %v", err)
59+
}
60+
defer mq.Close()
61+
62+
// Create state manager
63+
stateManager := state.NewMemoryStore()
64+
if err := stateManager.Initialize(ctx); err != nil {
65+
log.Fatalf("Failed to initialize state manager: %v", err)
66+
}
67+
defer stateManager.Close(ctx)
68+
69+
// Create orchestrator
70+
arc, err := orchestrator.New(orchestrator.Config{
71+
Runtime: runtimeInstance,
72+
MessageQueue: mq,
73+
StateManager: stateManager,
74+
})
75+
if err != nil {
76+
log.Fatalf("Failed to create orchestrator: %v", err)
77+
}
78+
79+
// Start orchestrator
80+
if err := arc.Start(); err != nil {
81+
log.Fatalf("Failed to start orchestrator: %v", err)
82+
}
83+
defer arc.Stop()
84+
85+
// Get runtime info if gVisor
86+
if gvisorRT, ok := runtimeInstance.(*runtime.GVisorRuntime); ok && runtimeName == "gVisor" {
87+
info, err := gvisorRT.GetRuntimeInfo(ctx)
88+
if err == nil {
89+
fmt.Printf("%s Runtime Info:\n", runtimeName)
90+
for k, v := range info {
91+
fmt.Printf(" %s: %v\n", k, v)
92+
}
93+
fmt.Println()
94+
}
95+
}
96+
97+
// Create a sample workflow with sandboxed containers
98+
workflow := &types.Workflow{
99+
Name: "secure-data-processing",
100+
Description: "A secure data processing workflow using gVisor sandboxing",
101+
Tasks: []types.Task{
102+
{
103+
Name: "fetch-data",
104+
AgentConfig: types.AgentConfig{
105+
Command: []string{"alpine"},
106+
Args: []string{"sh", "-c", "echo 'Fetching data in gVisor sandbox...'; sleep 5; echo 'Data fetched securely!'"},
107+
Environment: map[string]string{
108+
"TASK_TYPE": "fetch",
109+
"RUNTIME": "gvisor",
110+
},
111+
MessageQueue: types.MessageQueueConfig{
112+
Topics: []string{"secure-pipeline"},
113+
},
114+
Resources: types.ResourceRequirements{
115+
CPU: "500m",
116+
Memory: "256Mi",
117+
},
118+
},
119+
},
120+
{
121+
Name: "process-data",
122+
Dependencies: []string{}, // Will be set after task IDs are generated
123+
AgentConfig: types.AgentConfig{
124+
Command: []string{"alpine"},
125+
Args: []string{"sh", "-c", "echo 'Processing data in isolated environment...'; sleep 10; echo 'Data processed with isolation!'"},
126+
Environment: map[string]string{
127+
"TASK_TYPE": "process",
128+
"RUNTIME": "gvisor",
129+
},
130+
MessageQueue: types.MessageQueueConfig{
131+
Topics: []string{"secure-pipeline"},
132+
},
133+
Resources: types.ResourceRequirements{
134+
CPU: "1000m",
135+
Memory: "512Mi",
136+
},
137+
},
138+
},
139+
{
140+
Name: "store-results",
141+
Dependencies: []string{}, // Will be set after task IDs are generated
142+
AgentConfig: types.AgentConfig{
143+
Command: []string{"alpine"},
144+
Args: []string{"sh", "-c", "echo 'Storing results securely...'; sleep 3; echo 'Results stored in sandbox!'"},
145+
Environment: map[string]string{
146+
"TASK_TYPE": "store",
147+
"RUNTIME": "gvisor",
148+
},
149+
MessageQueue: types.MessageQueueConfig{
150+
Topics: []string{"secure-pipeline"},
151+
},
152+
Resources: types.ResourceRequirements{
153+
CPU: "250m",
154+
Memory: "128Mi",
155+
},
156+
},
157+
},
158+
},
159+
}
160+
161+
// Create workflow
162+
if err := arc.CreateWorkflow(ctx, workflow); err != nil {
163+
log.Fatalf("Failed to create workflow: %v", err)
164+
}
165+
166+
// Set dependencies after workflow creation (tasks now have IDs)
167+
workflow.Tasks[1].Dependencies = []string{workflow.Tasks[0].ID}
168+
workflow.Tasks[2].Dependencies = []string{workflow.Tasks[1].ID}
169+
170+
fmt.Printf("Created workflow: %s (ID: %s)\n", workflow.Name, workflow.ID)
171+
fmt.Printf("Using %s runtime for container execution\n", runtimeName)
172+
if runtimeName == "gVisor" {
173+
fmt.Println("Enhanced security and isolation enabled")
174+
}
175+
fmt.Println()
176+
177+
// Start workflow execution
178+
fmt.Printf("Starting workflow execution with %s runtime...\n", runtimeName)
179+
if err := arc.StartWorkflow(ctx, workflow.ID); err != nil {
180+
log.Fatalf("Failed to start workflow: %v", err)
181+
}
182+
183+
// Monitor workflow progress
184+
ticker := time.NewTicker(2 * time.Second)
185+
defer ticker.Stop()
186+
187+
for {
188+
select {
189+
case <-ticker.C:
190+
wf, err := arc.GetWorkflow(ctx, workflow.ID)
191+
if err != nil {
192+
log.Printf("Failed to get workflow status: %v", err)
193+
continue
194+
}
195+
196+
fmt.Printf("\nWorkflow Status: %s\n", wf.Status)
197+
for _, task := range wf.Tasks {
198+
fmt.Printf(" Task '%s' [%s]: %s\n", task.Name, runtimeName, task.Status)
199+
}
200+
201+
// Check if workflow is complete
202+
if wf.Status == types.WorkflowStatusCompleted {
203+
fmt.Printf("\nWorkflow completed successfully with %s runtime!\n", runtimeName)
204+
if runtimeName == "gVisor" {
205+
fmt.Println("All tasks ran in secure sandboxed environments.")
206+
}
207+
return
208+
} else if wf.Status == types.WorkflowStatusFailed {
209+
fmt.Printf("\nWorkflow failed: %s\n", wf.Error)
210+
return
211+
}
212+
case <-time.After(2 * time.Minute):
213+
fmt.Println("\nTimeout waiting for workflow to complete")
214+
return
215+
}
216+
}
217+
}

go.mod

Lines changed: 70 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,74 @@ module github.com/rizome-dev/arc
33
go 1.23.4
44

55
require (
6-
github.com/docker/docker v24.0.7+incompatible
7-
github.com/rizome-dev/amq v0.1.0
8-
k8s.io/api v0.29.0
9-
k8s.io/apimachinery v0.29.0
10-
k8s.io/client-go v0.29.0
6+
github.com/docker/docker v27.5.0+incompatible
7+
github.com/rizome-dev/amq v0.1.0
8+
k8s.io/api v0.29.0
9+
k8s.io/apimachinery v0.29.0
10+
k8s.io/client-go v0.29.0
11+
)
12+
13+
require (
14+
github.com/Microsoft/go-winio v0.4.14 // indirect
15+
github.com/cespare/xxhash/v2 v2.3.0 // indirect
16+
github.com/containerd/log v0.1.0 // indirect
17+
github.com/davecgh/go-spew v1.1.1 // indirect
18+
github.com/dgraph-io/badger/v4 v4.8.0 // indirect
19+
github.com/dgraph-io/ristretto/v2 v2.2.0 // indirect
20+
github.com/distribution/reference v0.6.0 // indirect
21+
github.com/docker/go-connections v0.5.0 // indirect
22+
github.com/docker/go-units v0.5.0 // indirect
23+
github.com/dustin/go-humanize v1.0.1 // indirect
24+
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
25+
github.com/felixge/httpsnoop v1.0.4 // indirect
26+
github.com/go-logr/logr v1.4.3 // indirect
27+
github.com/go-logr/stdr v1.2.2 // indirect
28+
github.com/go-openapi/jsonpointer v0.19.6 // indirect
29+
github.com/go-openapi/jsonreference v0.20.2 // indirect
30+
github.com/go-openapi/swag v0.22.3 // indirect
31+
github.com/gogo/protobuf v1.3.2 // indirect
32+
github.com/golang/protobuf v1.5.3 // indirect
33+
github.com/google/flatbuffers v25.2.10+incompatible // indirect
34+
github.com/google/gnostic-models v0.6.8 // indirect
35+
github.com/google/gofuzz v1.2.0 // indirect
36+
github.com/google/uuid v1.6.0 // indirect
37+
github.com/imdario/mergo v0.3.6 // indirect
38+
github.com/josharian/intern v1.0.0 // indirect
39+
github.com/json-iterator/go v1.1.12 // indirect
40+
github.com/klauspost/compress v1.18.0 // indirect
41+
github.com/mailru/easyjson v0.7.7 // indirect
42+
github.com/moby/docker-image-spec v1.3.1 // indirect
43+
github.com/moby/term v0.5.2 // indirect
44+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
45+
github.com/modern-go/reflect2 v1.0.2 // indirect
46+
github.com/morikuni/aec v1.0.0 // indirect
47+
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
48+
github.com/opencontainers/go-digest v1.0.0 // indirect
49+
github.com/opencontainers/image-spec v1.1.1 // indirect
50+
github.com/pkg/errors v0.9.1 // indirect
51+
github.com/spf13/pflag v1.0.6 // indirect
52+
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
53+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.62.0 // indirect
54+
go.opentelemetry.io/otel v1.37.0 // indirect
55+
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.37.0 // indirect
56+
go.opentelemetry.io/otel/metric v1.37.0 // indirect
57+
go.opentelemetry.io/otel/trace v1.37.0 // indirect
58+
golang.org/x/net v0.41.0 // indirect
59+
golang.org/x/oauth2 v0.10.0 // indirect
60+
golang.org/x/sys v0.34.0 // indirect
61+
golang.org/x/term v0.32.0 // indirect
62+
golang.org/x/text v0.26.0 // indirect
63+
golang.org/x/time v0.3.0 // indirect
64+
google.golang.org/appengine v1.6.7 // indirect
65+
google.golang.org/protobuf v1.36.6 // indirect
66+
gopkg.in/inf.v0 v0.9.1 // indirect
67+
gopkg.in/yaml.v2 v2.4.0 // indirect
68+
gopkg.in/yaml.v3 v3.0.1 // indirect
69+
gotest.tools/v3 v3.5.2 // indirect
70+
k8s.io/klog/v2 v2.110.1 // indirect
71+
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect
72+
k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect
73+
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
74+
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
75+
sigs.k8s.io/yaml v1.3.0 // indirect
1176
)

0 commit comments

Comments
 (0)