Skip to content
This repository was archived by the owner on Jan 2, 2026. It is now read-only.

Commit 9e63fe9

Browse files
committed
feat: introduce the new initd
1 parent 8a84719 commit 9e63fe9

File tree

30 files changed

+1924
-141
lines changed

30 files changed

+1924
-141
lines changed

.goreleaser.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,19 @@ builds:
1717
- linux
1818
goarch:
1919
- amd64
20+
- id: jailer
21+
env: [CGO_ENABLED=0]
22+
main: ./cmd/jailer/jailer.go
23+
binary: jailer
24+
goos:
25+
- linux
26+
goarch:
27+
- amd64
28+
- id: initd
29+
env: [CGO_ENABLED=0]
30+
main: ./cmd/initd/initd.go
31+
binary: initd
32+
goos:
33+
- linux
34+
goarch:
35+
- amd64

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ run-api:
55
air
66
build-ravel:
77
CGO_ENABLED=0 go build -o bin/ravel cmd/ravel/ravel.go
8-
8+
build-initd:
9+
CGO_ENABLED=0 go build -o bin/initd cmd/initd/initd.go
910
build-jailer:
1011
CGO_ENABLED=0 go build -o bin/jailer cmd/jailer/jailer.go
1112

api/initd/initd.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package initd
2+
3+
type FSEntry struct {
4+
Name string `json:"name"`
5+
Path string `json:"path"`
6+
IsDir bool `json:"is_dir"`
7+
Size int64 `json:"size"`
8+
ModTime int64 `json:"mod_time"`
9+
}
10+
11+
type MkdirOptions struct {
12+
Dir string `json:"dir"`
13+
}
14+
15+
type Status struct {
16+
Ok bool `json:"ok"`
17+
}
18+
19+
type WatchFSEvent struct {
20+
Path string `json:"path"`
21+
Create bool `json:"create"`
22+
Write bool `json:"write"`
23+
Remove bool `json:"remove"`
24+
Rename bool `json:"rename"`
25+
}

client/daemon.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func (a *DaemonClient) InstanceExec(ctx context.Context, id string, cmd []string
6666
TimeoutMs: int(timeout.Milliseconds()),
6767
}
6868
var result api.ExecResult
69-
err := a.client.Post(ctx, "/instances/"+id+"/exec", result, httpclient.WithJSONBody(&opt))
69+
err := a.client.Post(ctx, "/instances/"+id+"/exec", &result, httpclient.WithJSONBody(&opt))
7070
if err != nil {
7171
return nil, err
7272
}

cmd/initd/initd.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package main
2+
3+
import (
4+
"log/slog"
5+
6+
"github.com/valyentdev/ravel/initd/api"
7+
"github.com/valyentdev/ravel/initd/environment"
8+
)
9+
10+
func main() {
11+
env := &environment.Env{}
12+
13+
if err := env.Init(); err != nil {
14+
panic(err)
15+
}
16+
17+
go env.Run()
18+
19+
if err := api.ServeInitdAPI(env); err != nil {
20+
slog.Error("[ravel-initd] Failed to start API server: %v", "err", err)
21+
}
22+
}

cmd/ravel/commands/instance/exec.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"os"
7+
"strings"
78
"time"
89

910
"github.com/spf13/cobra"
@@ -18,7 +19,7 @@ func newInstanceExec() *cobra.Command {
1819
var execOptions execOptions
1920

2021
cmd := &cobra.Command{
21-
Use: "exec [instance-id] -- [command...]",
22+
Use: "exec instance-id command [...args] | --",
2223
Short: "Execute a command on a instance",
2324
Long: `Execute a command on a instance.`,
2425
RunE: func(cmd *cobra.Command, args []string) error {
@@ -36,7 +37,7 @@ func runInstanceExec(cmd *cobra.Command, args []string, timeout time.Duration) e
3637
return fmt.Errorf("please specify a instance id, then the command")
3738
}
3839

39-
var cmdLine []string
40+
var toExec string
4041

4142
if args[1] == "--" {
4243
println("reading from stdin")
@@ -54,12 +55,16 @@ func runInstanceExec(cmd *cobra.Command, args []string, timeout time.Duration) e
5455
str = str[:len(str)-1]
5556
}
5657

57-
cmdLine = []string{
58-
"/bin/sh",
59-
"-c",
60-
str,
61-
}
58+
toExec = str
59+
60+
} else {
61+
toExec = strings.Join(args[1:], " ")
62+
}
6263

64+
cmdLine := []string{
65+
"/bin/sh",
66+
"-c",
67+
toExec,
6368
}
6469

6570
instanceId := args[0]

go.mod

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ require (
1212
github.com/containerd/errdefs v0.1.0
1313
github.com/coreos/go-iptables v0.7.0
1414
github.com/danielgtaylor/huma/v2 v2.26.0
15+
github.com/fsnotify/fsnotify v1.7.0
1516
github.com/gammazero/deque v0.2.1
1617
github.com/google/go-containerregistry v0.20.2
1718
github.com/jackc/pgx/v5 v5.6.0
@@ -25,10 +26,8 @@ require (
2526
github.com/stretchr/testify v1.9.0
2627
github.com/u-root/u-root v0.14.0
2728
github.com/valyentdev/corroclient v0.1.0
28-
github.com/valyentdev/ravel-init v0.1.0
2929
go.etcd.io/bbolt v1.3.11
3030
google.golang.org/grpc v1.67.1
31-
google.golang.org/protobuf v1.35.2
3231
sigs.k8s.io/yaml v1.4.0
3332

3433
)
@@ -59,7 +58,6 @@ require (
5958
github.com/docker/docker-credential-helpers v0.7.0 // indirect
6059
github.com/dustin/go-humanize v1.0.1 // indirect
6160
github.com/felixge/httpsnoop v1.0.4 // indirect
62-
github.com/fsnotify/fsnotify v1.7.0 // indirect
6361
github.com/go-logr/logr v1.4.1 // indirect
6462
github.com/go-logr/stdr v1.2.2 // indirect
6563
github.com/godbus/dbus/v5 v5.1.0 // indirect
@@ -111,6 +109,7 @@ require (
111109
golang.org/x/mod v0.22.0 // indirect
112110
golang.org/x/tools v0.27.0 // indirect
113111
google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 // indirect
112+
google.golang.org/protobuf v1.35.2 // indirect
114113
gopkg.in/yaml.v3 v3.0.1 // indirect
115114
k8s.io/klog/v2 v2.120.1 // indirect
116115
tags.cncf.io/container-device-interface v0.6.2 // indirect
@@ -120,7 +119,6 @@ require (
120119
require (
121120
github.com/mdlayher/vsock v1.2.1
122121
github.com/opencontainers/go-digest v1.0.0 // indirect
123-
github.com/opencontainers/runc v1.1.15 // indirect
124122
github.com/pkg/errors v0.9.1 // indirect
125123
github.com/sirupsen/logrus v1.9.3
126124
github.com/valyentdev/ravel/api v0.0.0-00010101000000-000000000000

go.sum

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,6 @@ github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8
224224
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
225225
github.com/opencontainers/image-spec v1.1.0 h1:8SG7/vwALn54lVB/0yZ/MMwhFrPYtpEHQb2IpWsCzug=
226226
github.com/opencontainers/image-spec v1.1.0/go.mod h1:W4s4sFTMaBeK1BQLXbG4AdM2szdn85PY75RI83NrTrM=
227-
github.com/opencontainers/runc v1.1.15 h1:QMmSU2q1YUg3iOJX11phnaDi2A5/zhx4BR6h+XZ1DMA=
228-
github.com/opencontainers/runc v1.1.15/go.mod h1:E4C2z+7BxR7GHXp0hAY53mek+x49X1LjPNeMTfRGvOA=
229227
github.com/opencontainers/runtime-spec v1.0.3-0.20220825212826-86290f6a00fb/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0=
230228
github.com/opencontainers/runtime-spec v1.2.0 h1:z97+pHb3uELt/yiAWD691HNHQIF07bE7dzrbT927iTk=
231229
github.com/opencontainers/runtime-spec v1.2.0/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0=
@@ -288,8 +286,6 @@ github.com/urfave/cli v1.19.1/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijb
288286
github.com/urfave/cli v1.22.12/go.mod h1:sSBEIC79qR6OvcmsD4U3KABeOTxDqQtdDnaFuUN30b8=
289287
github.com/valyentdev/corroclient v0.1.0 h1:Q9o1wkDkZjmisi0F8kNsXl2ixL6+IxZF7C4szzld7tY=
290288
github.com/valyentdev/corroclient v0.1.0/go.mod h1:q7jt7jJvWdk/qlRqBdNB/eA88m47vv/y/fDzbHttsvM=
291-
github.com/valyentdev/ravel-init v0.1.0 h1:qxtU0rNS9nNgDVvoKYa82zz0vJ+IN60mrVzbCfPXyns=
292-
github.com/valyentdev/ravel-init v0.1.0/go.mod h1:kCJWNPnxXQjtGBzwQup7BgLe78jLrVdqol9tZpJ2Z5s=
293289
github.com/vbatts/tar-split v0.11.3 h1:hLFqsOLQ1SsppQNTMpkpPXClLDfC2A3Zgy9OUU+RVck=
294290
github.com/vbatts/tar-split v0.11.3/go.mod h1:9QlHN18E+fEH7RdG+QAJJcuya3rqT7eXSTY7wGrAokY=
295291
github.com/vishvananda/netlink v1.3.0 h1:X7l42GfcV4S6E4vHTsw48qbrV+9PVojNfIhZcwQdrZk=

initd/api/internal.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package api
2+
3+
import (
4+
"context"
5+
6+
"github.com/danielgtaylor/huma/v2"
7+
"github.com/valyentdev/ravel/initd"
8+
"github.com/valyentdev/ravel/initd/environment"
9+
)
10+
11+
type InternalEndpoint struct {
12+
env *environment.Env
13+
}
14+
15+
func (e *InternalEndpoint) registerRoutes(api huma.API) {
16+
huma.Register(api, huma.Operation{
17+
Method: "GET",
18+
Path: "/wait",
19+
OperationID: "waitExit",
20+
Description: "Wait for the container main process to exit",
21+
}, e.wait)
22+
23+
huma.Register(api, huma.Operation{
24+
Path: "/signal",
25+
Method: "POST",
26+
OperationID: "signal",
27+
Description: "Send a signal to the container main process",
28+
}, e.signal)
29+
}
30+
31+
type WaitRequest struct{}
32+
33+
type WaitResponse struct {
34+
Body initd.WaitResult
35+
}
36+
37+
func (e *InternalEndpoint) wait(ctx context.Context, req *WaitRequest) (*WaitResponse, error) {
38+
return &WaitResponse{Body: e.env.Wait()}, nil
39+
}
40+
41+
type SignalRequest struct {
42+
Body initd.SignalOptions
43+
}
44+
45+
type SignalResponse struct{}
46+
47+
func (e *InternalEndpoint) signal(ctx context.Context, req *SignalRequest) (*SignalResponse, error) {
48+
err := e.env.Signal(req.Body.Signal)
49+
if err != nil {
50+
return nil, err
51+
}
52+
return &SignalResponse{}, nil
53+
}

0 commit comments

Comments
 (0)