-
Notifications
You must be signed in to change notification settings - Fork 426
/
run_help.go
79 lines (65 loc) · 2.33 KB
/
run_help.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
// Copyright (c) 2018, 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.
// +build linux
package cli
import (
"encoding/json"
"os"
"path/filepath"
"github.com/opencontainers/runtime-tools/generate"
"github.com/spf13/cobra"
"github.com/sylabs/singularity/internal/pkg/buildcfg"
"github.com/sylabs/singularity/internal/pkg/runtime/engines/config"
"github.com/sylabs/singularity/internal/pkg/runtime/engines/config/oci"
"github.com/sylabs/singularity/internal/pkg/runtime/engines/singularity"
"github.com/sylabs/singularity/internal/pkg/sylog"
"github.com/sylabs/singularity/internal/pkg/util/exec"
"github.com/sylabs/singularity/src/docs"
)
func init() {
RunHelpCmd.Flags().SetInterspersed(false)
SingularityCmd.AddCommand(RunHelpCmd)
}
// RunHelpCmd singularity run-help <image>
var RunHelpCmd = &cobra.Command{
DisableFlagsInUseLine: true,
PreRun: sylabsToken,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
// Sanity check
if _, err := os.Stat(args[0]); err != nil {
sylog.Fatalf("container not found: %s", err)
}
// Help prints (if set) the sourced %help section on the definition file
abspath, err := filepath.Abs(args[0])
name := filepath.Base(abspath)
a := []string{"/bin/cat", "/.singularity.d/runscript.help"}
starter := buildcfg.LIBEXECDIR + "/singularity/bin/starter-suid"
procname := "Singularity help"
Env := []string{sylog.GetEnvVar(), "SRUNTIME=singularity"}
engineConfig := singularity.NewConfig()
ociConfig := &oci.Config{}
generator := generate.Generator{Config: &ociConfig.Spec}
engineConfig.OciConfig = ociConfig
generator.SetProcessArgs(a)
engineConfig.SetImage(abspath)
cfg := &config.Common{
EngineName: singularity.Name,
ContainerID: name,
EngineConfig: engineConfig,
}
configData, err := json.Marshal(cfg)
if err != nil {
sylog.Fatalf("CLI Failed to marshal CommonEngineConfig: %s\n", err)
}
if err := exec.Pipe(starter, []string{procname}, Env, configData); err != nil {
sylog.Fatalf("%s", err)
}
},
Use: docs.RunHelpUse,
Short: docs.RunHelpShort,
Long: docs.RunHelpLong,
Example: docs.RunHelpExample,
}