-
Notifications
You must be signed in to change notification settings - Fork 124
/
oci_linux.go
396 lines (365 loc) · 11.6 KB
/
oci_linux.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
// Copyright (c) Contributors to the Apptainer project, established as
// Apptainer a Series of LF Projects LLC.
// For website terms of use, trademark policy, privacy policy and other
// project policies see https://lfprojects.org/policies
// Copyright (c) 2018-2020, Sylabs Inc. All rights reserved.
// This software is licensed under a 3-clause BSD license. Please consult the
// LICENSE.md file distributed with the sources of this project regarding your
// rights to use or distribute this software.
package cli
import (
"github.com/apptainer/apptainer/docs"
"github.com/apptainer/apptainer/internal/app/apptainer"
"github.com/apptainer/apptainer/pkg/cmdline"
"github.com/apptainer/apptainer/pkg/sylog"
"github.com/spf13/cobra"
)
var ociArgs apptainer.OciArgs
// -b|--bundle
var ociBundleFlag = cmdline.Flag{
ID: "ociBundleFlag",
Value: &ociArgs.BundlePath,
DefaultValue: "",
Name: "bundle",
ShortHand: "b",
Required: true,
Usage: "specify the OCI bundle path (required)",
Tag: "<path>",
EnvKeys: []string{"BUNDLE"},
}
// -s|--sync-socket
var ociSyncSocketFlag = cmdline.Flag{
ID: "ociSyncSocketFlag",
Value: &ociArgs.SyncSocketPath,
DefaultValue: "",
Name: "sync-socket",
ShortHand: "s",
Usage: "specify the path to unix socket for state synchronization",
Tag: "<path>",
EnvKeys: []string{"SYNC_SOCKET"},
}
// --empty-process
var ociCreateEmptyProcessFlag = cmdline.Flag{
ID: "ociCreateEmptyProcessFlag",
Value: &ociArgs.EmptyProcess,
DefaultValue: false,
Name: "empty-process",
Usage: "run container without executing container process (eg: for POD container)",
EnvKeys: []string{"EMPTY_PROCESS"},
}
// -l|--log-path
var ociLogPathFlag = cmdline.Flag{
ID: "ociLogPathFlag",
Value: &ociArgs.LogPath,
DefaultValue: "",
Name: "log-path",
ShortHand: "l",
Usage: "specify the log file path",
Tag: "<path>",
EnvKeys: []string{"LOG_PATH"},
}
// --log-format
var ociLogFormatFlag = cmdline.Flag{
ID: "ociLogFormatFlag",
Value: &ociArgs.LogFormat,
DefaultValue: "kubernetes",
Name: "log-format",
Usage: "specify the log file format. Available formats are basic, kubernetes and json",
Tag: "<format>",
EnvKeys: []string{"LOG_FORMAT"},
}
// --pid-file
var ociPidFileFlag = cmdline.Flag{
ID: "ociPidFileFlag",
Value: &ociArgs.PidFile,
DefaultValue: "",
Name: "pid-file",
Usage: "specify the pid file",
Tag: "<path>",
EnvKeys: []string{"PID_FILE"},
}
// -s|--signal
var ociKillSignalFlag = cmdline.Flag{
ID: "ociKillSignalFlag",
Value: &ociArgs.KillSignal,
DefaultValue: "SIGTERM",
Name: "signal",
ShortHand: "s",
Usage: "signal sent to the container",
Tag: "<signal>",
EnvKeys: []string{"SIGNAL"},
}
// -f|--force
var ociKillForceFlag = cmdline.Flag{
ID: "ociKillForceFlag",
Value: &ociArgs.ForceKill,
DefaultValue: false,
Name: "force",
ShortHand: "f",
Usage: "kill container process with SIGKILL",
EnvKeys: []string{"FORCE"},
}
// -t|--timeout
var ociKillTimeoutFlag = cmdline.Flag{
ID: "ociKillTimeoutFlag",
Value: &ociArgs.KillTimeout,
DefaultValue: uint32(0),
Name: "timeout",
ShortHand: "t",
Usage: "timeout in second before killing container",
}
// -f|--from-file
var ociUpdateFromFileFlag = cmdline.Flag{
ID: "ociUpdateFromFileFlag",
Value: &ociArgs.FromFile,
DefaultValue: "",
Name: "from-file",
ShortHand: "f",
Usage: "specify path to OCI JSON cgroups resource file ('-' to read from STDIN)",
EnvKeys: []string{"FROM_FILE"},
}
func init() {
addCmdInit(func(cmdManager *cmdline.CommandManager) {
cmdManager.RegisterCmd(OciCmd)
cmdManager.RegisterSubCmd(OciCmd, OciStartCmd)
cmdManager.RegisterSubCmd(OciCmd, OciCreateCmd)
cmdManager.RegisterSubCmd(OciCmd, OciRunCmd)
cmdManager.RegisterSubCmd(OciCmd, OciDeleteCmd)
cmdManager.RegisterSubCmd(OciCmd, OciKillCmd)
cmdManager.RegisterSubCmd(OciCmd, OciStateCmd)
cmdManager.RegisterSubCmd(OciCmd, OciAttachCmd)
cmdManager.RegisterSubCmd(OciCmd, OciExecCmd)
cmdManager.RegisterSubCmd(OciCmd, OciUpdateCmd)
cmdManager.RegisterSubCmd(OciCmd, OciPauseCmd)
cmdManager.RegisterSubCmd(OciCmd, OciResumeCmd)
cmdManager.RegisterSubCmd(OciCmd, OciMountCmd)
cmdManager.RegisterSubCmd(OciCmd, OciUmountCmd)
cmdManager.SetCmdGroup("create_run", OciCreateCmd, OciRunCmd)
createRunCmd := cmdManager.GetCmdGroup("create_run")
cmdManager.RegisterFlagForCmd(&ociBundleFlag, createRunCmd...)
cmdManager.RegisterFlagForCmd(&ociSyncSocketFlag, createRunCmd...)
cmdManager.RegisterFlagForCmd(&ociLogPathFlag, createRunCmd...)
cmdManager.RegisterFlagForCmd(&ociLogFormatFlag, createRunCmd...)
cmdManager.RegisterFlagForCmd(&ociPidFileFlag, createRunCmd...)
cmdManager.RegisterFlagForCmd(&ociCreateEmptyProcessFlag, OciCreateCmd)
cmdManager.RegisterFlagForCmd(&ociKillForceFlag, OciKillCmd)
cmdManager.RegisterFlagForCmd(&ociKillSignalFlag, OciKillCmd)
cmdManager.RegisterFlagForCmd(&ociKillTimeoutFlag, OciKillCmd)
cmdManager.RegisterFlagForCmd(&ociUpdateFromFileFlag, OciUpdateCmd)
cmdManager.RegisterFlagForCmd(&ociSyncSocketFlag, OciStateCmd)
})
}
// OciCreateCmd represents oci create command.
var OciCreateCmd = &cobra.Command{
Args: cobra.ExactArgs(1),
DisableFlagsInUseLine: true,
PreRun: CheckRoot,
Run: func(cmd *cobra.Command, args []string) {
if err := apptainer.OciCreate(args[0], &ociArgs); err != nil {
sylog.Fatalf("%s", err)
}
},
Use: docs.OciCreateUse,
Short: docs.OciCreateShort,
Long: docs.OciCreateLong,
Example: docs.OciCreateExample,
}
// OciRunCmd allow to create/start in row.
var OciRunCmd = &cobra.Command{
Args: cobra.ExactArgs(1),
DisableFlagsInUseLine: true,
PreRun: CheckRoot,
Run: func(cmd *cobra.Command, args []string) {
if err := apptainer.OciRun(cmd.Context(), args[0], &ociArgs); err != nil {
sylog.Fatalf("%s", err)
}
},
Use: docs.OciRunUse,
Short: docs.OciRunShort,
Long: docs.OciRunLong,
Example: docs.OciRunExample,
}
// OciStartCmd represents oci start command.
var OciStartCmd = &cobra.Command{
Args: cobra.ExactArgs(1),
DisableFlagsInUseLine: true,
PreRun: CheckRoot,
Run: func(cmd *cobra.Command, args []string) {
if err := apptainer.OciStart(args[0]); err != nil {
sylog.Fatalf("%s", err)
}
},
Use: docs.OciStartUse,
Short: docs.OciStartShort,
Long: docs.OciStartLong,
Example: docs.OciStartExample,
}
// OciDeleteCmd represents oci delete command.
var OciDeleteCmd = &cobra.Command{
Args: cobra.ExactArgs(1),
DisableFlagsInUseLine: true,
PreRun: CheckRoot,
Run: func(cmd *cobra.Command, args []string) {
if err := apptainer.OciDelete(cmd.Context(), args[0]); err != nil {
sylog.Fatalf("%s", err)
}
},
Use: docs.OciDeleteUse,
Short: docs.OciDeleteShort,
Long: docs.OciDeleteLong,
Example: docs.OciDeleteExample,
}
// OciKillCmd represents oci kill command.
var OciKillCmd = &cobra.Command{
Args: cobra.MinimumNArgs(1),
DisableFlagsInUseLine: true,
PreRun: CheckRoot,
Run: func(cmd *cobra.Command, args []string) {
timeout := int(ociArgs.KillTimeout)
killSignal := ""
if len(args) > 1 && args[1] != "" {
killSignal = args[1]
} else {
killSignal = ociArgs.KillSignal
}
if ociArgs.ForceKill {
killSignal = "SIGKILL"
}
if err := apptainer.OciKill(args[0], killSignal, timeout); err != nil {
sylog.Fatalf("%s", err)
}
},
Use: docs.OciKillUse,
Short: docs.OciKillShort,
Long: docs.OciKillLong,
Example: docs.OciKillExample,
}
// OciStateCmd represents oci state command.
var OciStateCmd = &cobra.Command{
Args: cobra.ExactArgs(1),
DisableFlagsInUseLine: true,
PreRun: CheckRoot,
Run: func(cmd *cobra.Command, args []string) {
if err := apptainer.OciState(args[0], &ociArgs); err != nil {
sylog.Fatalf("%s", err)
}
},
Use: docs.OciStateUse,
Short: docs.OciStateShort,
Long: docs.OciStateLong,
Example: docs.OciStateExample,
}
// OciAttachCmd represents oci attach command.
var OciAttachCmd = &cobra.Command{
Args: cobra.ExactArgs(1),
DisableFlagsInUseLine: true,
PreRun: CheckRoot,
Run: func(cmd *cobra.Command, args []string) {
if err := apptainer.OciAttach(cmd.Context(), args[0]); err != nil {
sylog.Fatalf("%s", err)
}
},
Use: docs.OciAttachUse,
Short: docs.OciAttachShort,
Long: docs.OciAttachLong,
Example: docs.OciAttachExample,
}
// OciExecCmd represents oci exec command.
var OciExecCmd = &cobra.Command{
Args: cobra.MinimumNArgs(1),
DisableFlagsInUseLine: true,
PreRun: CheckRoot,
Run: func(cmd *cobra.Command, args []string) {
if err := apptainer.OciExec(args[0], args[1:]); err != nil {
sylog.Fatalf("%s", err)
}
},
Use: docs.OciExecUse,
Short: docs.OciExecShort,
Long: docs.OciExecLong,
Example: docs.OciExecExample,
}
// OciUpdateCmd represents oci update command.
var OciUpdateCmd = &cobra.Command{
Args: cobra.MinimumNArgs(1),
DisableFlagsInUseLine: true,
PreRun: CheckRoot,
Run: func(cmd *cobra.Command, args []string) {
if err := apptainer.OciUpdate(args[0], &ociArgs); err != nil {
sylog.Fatalf("%s", err)
}
},
Use: docs.OciUpdateUse,
Short: docs.OciUpdateShort,
Long: docs.OciUpdateLong,
Example: docs.OciUpdateExample,
}
// OciPauseCmd represents oci pause command.
var OciPauseCmd = &cobra.Command{
Args: cobra.ExactArgs(1),
DisableFlagsInUseLine: true,
PreRun: CheckRoot,
Run: func(cmd *cobra.Command, args []string) {
if err := apptainer.OciPauseResume(args[0], true); err != nil {
sylog.Fatalf("%s", err)
}
},
Use: docs.OciPauseUse,
Short: docs.OciPauseShort,
Long: docs.OciPauseLong,
Example: docs.OciPauseExample,
}
// OciResumeCmd represents oci resume command.
var OciResumeCmd = &cobra.Command{
Args: cobra.ExactArgs(1),
DisableFlagsInUseLine: true,
PreRun: CheckRoot,
Run: func(cmd *cobra.Command, args []string) {
if err := apptainer.OciPauseResume(args[0], false); err != nil {
sylog.Fatalf("%s", err)
}
},
Use: docs.OciResumeUse,
Short: docs.OciResumeShort,
Long: docs.OciResumeLong,
Example: docs.OciResumeExample,
}
// OciMountCmd represents oci mount command.
var OciMountCmd = &cobra.Command{
Args: cobra.ExactArgs(2),
DisableFlagsInUseLine: true,
PreRun: CheckRoot,
Run: func(cmd *cobra.Command, args []string) {
if err := apptainer.OciMount(args[0], args[1]); err != nil {
sylog.Fatalf("%s", err)
}
},
Use: docs.OciMountUse,
Short: docs.OciMountShort,
Long: docs.OciMountLong,
Example: docs.OciMountExample,
}
// OciUmountCmd represents oci mount command.
var OciUmountCmd = &cobra.Command{
Args: cobra.ExactArgs(1),
DisableFlagsInUseLine: true,
PreRun: CheckRoot,
Run: func(cmd *cobra.Command, args []string) {
if err := apptainer.OciUmount(args[0]); err != nil {
sylog.Fatalf("%s", err)
}
},
Use: docs.OciUmountUse,
Short: docs.OciUmountShort,
Long: docs.OciUmountLong,
Example: docs.OciUmountExample,
}
// OciCmd apptainer oci runtime.
var OciCmd = &cobra.Command{
Run: nil,
DisableFlagsInUseLine: true,
Use: docs.OciUse,
Short: docs.OciShort,
Long: docs.OciLong,
Example: docs.OciExample,
}