-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.go
69 lines (63 loc) · 1.98 KB
/
run.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
package composectl
import (
"fmt"
"github.com/containerd/containerd/platforms"
"github.com/foundriesio/composeapp/pkg/compose"
v1 "github.com/foundriesio/composeapp/pkg/compose/v1"
"github.com/spf13/cobra"
"os"
"os/exec"
"path"
"strings"
)
var (
runCmd = &cobra.Command{
Use: "run",
Short: "",
Long: ``,
Args: cobra.NoArgs,
Run: runApps,
}
runAppShortlist *string
)
func init() {
rootCmd.AddCommand(runCmd)
runAppShortlist = runCmd.Flags().String("apps", "", "Comma separated list of apps to run; all installed apps are started if not defined")
}
func runApps(cmd *cobra.Command, args []string) {
cs, err := v1.NewAppStore(config.StoreRoot, config.Platform)
DieNotNil(err)
apps, err := cs.ListApps(cmd.Context())
DieNotNil(err)
var appShortlist map[string]bool
if len(*runAppShortlist) > 0 {
appShortlist = make(map[string]bool)
for _, a := range strings.Split(*runAppShortlist, ",") {
appShortlist[a] = true
}
}
checkedApps := map[string]compose.App{}
for _, app := range apps {
if appShortlist != nil && !appShortlist[app.Name] {
fmt.Printf("%s: skipping, not in the shortlist\n", app.Name)
continue
}
a, _, err := v1.NewAppLoader().LoadAppTree(cmd.Context(), cs, platforms.OnlyStrict(config.Platform), app.String())
DieNotNil(err)
if _, ok := checkedApps[app.Name]; ok {
DieNotNil(fmt.Errorf("cannot start %s since there are two or more versions of it found in the store", app.Name))
}
checkedApps[app.Name] = a
}
for _, app := range checkedApps {
fmt.Printf("Installing %s --> %s\n", app.Name(), app.Ref().String())
err = v1.InstallApp(cmd.Context(), app, cs, path.Join(config.StoreRoot, "blobs/sha256"), config.ComposeRoot, config.DockerHost)
DieNotNil(err)
fmt.Printf("Starting %s --> %s\n", app.Name(), app.Ref().String())
cmd := exec.Command("docker", "compose", "up", "-d", "--remove-orphans")
cmd.Dir = path.Join(config.ComposeRoot, app.Name())
cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout
DieNotNil(cmd.Run())
}
}