@@ -3,7 +3,6 @@ package main
33import (
44 "fmt"
55 "os"
6- "os/exec"
76 "os/signal"
87 "path/filepath"
98 "strings"
@@ -92,6 +91,7 @@ func main() {
9291 Destination : & options .runtime ,
9392 EnvVars : []string {"RUNTIME" },
9493 },
94+ // TODO: Remove runtime-args
9595 & cli.StringFlag {
9696 Name : "runtime-args" ,
9797 Aliases : []string {"u" },
@@ -136,7 +136,7 @@ func validateFlags(_ *cli.Context, o *options) error {
136136 if err := toolkit .ValidateOptions (& o .toolkitOptions , o .toolkitRoot ()); err != nil {
137137 return err
138138 }
139- if err := runtime .ValidateOptions (& o .runtimeOptions , o .toolkitRoot ()); err != nil {
139+ if err := runtime .ValidateOptions (& o .runtimeOptions , o .runtime , o . toolkitRoot ()); err != nil {
140140 return err
141141 }
142142 return nil
@@ -160,7 +160,7 @@ func Run(c *cli.Context, o *options) error {
160160 return fmt .Errorf ("unable to install toolkit: %v" , err )
161161 }
162162
163- err = setupRuntime ( o )
163+ err = runtime . Setup ( c , & o . runtimeOptions , o . runtime )
164164 if err != nil {
165165 return fmt .Errorf ("unable to setup runtime: %v" , err )
166166 }
@@ -171,7 +171,7 @@ func Run(c *cli.Context, o *options) error {
171171 return fmt .Errorf ("unable to wait for signal: %v" , err )
172172 }
173173
174- err = cleanupRuntime ( o )
174+ err = runtime . Cleanup ( c , & o . runtimeOptions , o . runtime )
175175 if err != nil {
176176 return fmt .Errorf ("unable to cleanup runtime: %v" , err )
177177 }
@@ -264,51 +264,13 @@ func initialize(pidFile string) error {
264264 return nil
265265}
266266
267- func setupRuntime (o * options ) error {
268- toolkitDir := filepath .Join (o .root , toolkitSubDir )
269-
270- log .Infof ("Setting up runtime" )
271-
272- cmdline := fmt .Sprintf ("%v setup %v %v\n " , o .runtime , o .runtimeArgs , toolkitDir )
273-
274- //nolint:gosec // TODO: Can we harden this so that there is less risk of command injection
275- cmd := exec .Command ("sh" , "-c" , cmdline )
276- cmd .Stdout = os .Stdout
277- cmd .Stderr = os .Stderr
278- err := cmd .Run ()
279- if err != nil {
280- return fmt .Errorf ("error running %v command: %v" , o .runtime , err )
281- }
282-
283- return nil
284- }
285-
286267func waitForSignal () error {
287268 log .Infof ("Waiting for signal" )
288269 waitingForSignal <- true
289270 <- signalReceived
290271 return nil
291272}
292273
293- func cleanupRuntime (o * options ) error {
294- toolkitDir := filepath .Join (o .root , toolkitSubDir )
295-
296- log .Infof ("Cleaning up Runtime" )
297-
298- cmdline := fmt .Sprintf ("%v cleanup %v %v\n " , o .runtime , o .runtimeArgs , toolkitDir )
299-
300- //nolint:gosec // TODO: Can we harden this so that there is less risk of command injection
301- cmd := exec .Command ("sh" , "-c" , cmdline )
302- cmd .Stdout = os .Stdout
303- cmd .Stderr = os .Stderr
304- err := cmd .Run ()
305- if err != nil {
306- return fmt .Errorf ("error running %v command: %v" , o .runtime , err )
307- }
308-
309- return nil
310- }
311-
312274func shutdown (pidFile string ) {
313275 log .Infof ("Shutting Down" )
314276
0 commit comments