@@ -37,14 +37,19 @@ fn getEnvFull(key: []const u8) ?[:0]const u8 {
37
37
return null ;
38
38
}
39
39
40
- fn processArgs (file : std.fs.File , allocator : std.mem.Allocator ) ! void {
40
+ fn processArgs (file : std.fs.File , parentAllocator : std.mem.Allocator ) ! void {
41
+ var arena = std .heap .ArenaAllocator .init (parentAllocator );
42
+ defer arena .deinit ();
43
+ const allocator = arena .allocator ();
44
+
41
45
var jsonReader = std .json .reader (allocator , file .reader ());
42
46
43
47
// TODO: having to specify max_value_len seems like a bug
44
48
var root_value = try std .json .Value .jsonParse (allocator , & jsonReader , .{ .max_value_len = 99999999 });
45
49
46
50
var args_json : * std .ArrayList (std .json .Value ) = undefined ;
47
51
var env_json : * std .ArrayList (std .json .Value ) = undefined ;
52
+ var mounts_json : * std .ArrayList (std .json .Value ) = undefined ;
48
53
49
54
switch (root_value ) {
50
55
.object = > | * object | {
@@ -74,6 +79,19 @@ fn processArgs(file: std.fs.File, allocator: std.mem.Allocator) !void {
74
79
},
75
80
else = > return error .InvalidJSON ,
76
81
}
82
+
83
+ if (object .getPtr ("mounts" )) | mountsVal | {
84
+ switch (mountsVal .* ) {
85
+ .array = > | * mountsArr | {
86
+ mounts_json = mountsArr ;
87
+ },
88
+ else = > return error .InvalidJSON ,
89
+ }
90
+ } else {
91
+ var array = std .json .Array .init (allocator );
92
+ mounts_json = & array ;
93
+ try object .put ("mounts" , std.json.Value { .array = array });
94
+ }
77
95
},
78
96
else = > return error .InvalidJSON ,
79
97
}
@@ -89,12 +107,22 @@ fn processArgs(file: std.fs.File, allocator: std.mem.Allocator) !void {
89
107
} else {
90
108
try env_json .append (std.json.Value { .string = getEnvFull (environment_variable ) orelse @panic ("environment variable does not exist" ) });
91
109
}
92
- } else if (eql (u8 , arg , "-p" )) {
93
- _ = args .next ();
94
- @panic ("not implemented" );
95
- } else if (eql (u8 , arg , "-v" )) {
96
- _ = args .next ();
97
- @panic ("not implemented" );
110
+ } else if (eql (u8 , arg , "-v" ) or eql (u8 , arg , "--volume" )) {
111
+ const volume_syntax = args .next () orelse @panic ("expected volume syntax" );
112
+
113
+ var mount = std .json .ObjectMap .init (allocator );
114
+
115
+ var options = std .json .Array .init (allocator );
116
+ try options .append (std.json.Value { .string = "rw" });
117
+ try options .append (std.json.Value { .string = "rbind" });
118
+ try mount .put ("options" , std.json.Value { .array = options });
119
+
120
+ const separator = std .mem .indexOfScalar (u8 , volume_syntax , ':' ) orelse @panic ("no volume destination specified" );
121
+
122
+ try mount .put ("source" , std.json.Value { .string = volume_syntax [0.. separator ] });
123
+ try mount .put ("destination" , std.json.Value { .string = volume_syntax [separator + 1.. ] });
124
+
125
+ try mounts_json .append (std.json.Value { .object = mount });
98
126
} else if (eql (u8 , arg , "--" )) {
99
127
while (args .next ()) | arg_inner | {
100
128
try args_json .append (std.json.Value { .string = arg_inner });
@@ -113,6 +141,7 @@ fn processArgs(file: std.fs.File, allocator: std.mem.Allocator) !void {
113
141
114
142
pub fn main () ! void {
115
143
var gpa = std .heap .GeneralPurposeAllocator (.{}){};
144
+ defer _ = gpa .deinit ();
116
145
const allocator = gpa .allocator ();
117
146
// defer _ = gpa.deinit();
118
147
var args = std .process .args ();
@@ -142,7 +171,7 @@ pub fn main() !void {
142
171
143
172
const args_buf = [_ ][]const u8 { squashfuse_path , "-o" , offsetArg , executable_path , filesystem_bundle_dir_null };
144
173
145
- var mountProcess = std .ChildProcess .init (& args_buf , gpa . allocator () );
174
+ var mountProcess = std .ChildProcess .init (& args_buf , allocator );
146
175
_ = try mountProcess .spawnAndWait ();
147
176
148
177
const overlayfs_options = try std .fmt .allocPrint (allocator , "lowerdir={s},upperdir={s}/upper,workdir={s}/upper" , .{
@@ -169,13 +198,13 @@ pub fn main() !void {
169
198
try processArgs (file , allocator );
170
199
}
171
200
172
- var crunProcess = std .ChildProcess .init (&[_ ][]const u8 { crun_path , "run" , "-b" , mount_dir_path , "crun_docker_c_id" }, gpa . allocator () );
201
+ var crunProcess = std .ChildProcess .init (&[_ ][]const u8 { crun_path , "run" , "-b" , mount_dir_path , "crun_docker_c_id" }, allocator );
173
202
_ = try crunProcess .spawnAndWait ();
174
203
175
- var umountOverlayProcess = std .ChildProcess .init (&[_ ][]const u8 { "umount" , mount_dir_path }, gpa . allocator () );
204
+ var umountOverlayProcess = std .ChildProcess .init (&[_ ][]const u8 { "umount" , mount_dir_path }, allocator );
176
205
_ = try umountOverlayProcess .spawnAndWait ();
177
206
178
- var umountProcess = std .ChildProcess .init (&[_ ][]const u8 { "umount" , filesystem_bundle_dir_null }, gpa . allocator () );
207
+ var umountProcess = std .ChildProcess .init (&[_ ][]const u8 { "umount" , filesystem_bundle_dir_null }, allocator );
179
208
_ = try umountProcess .spawnAndWait ();
180
209
181
210
// TODO: clean up /tmp
0 commit comments