|
1 | 1 | package cmd |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "os" |
| 4 | + "os" |
5 | 5 |
|
6 | | - "github.com/apex/log" |
7 | | - "github.com/spf13/cobra" |
8 | | - "github.com/spf13/viper" |
9 | | - "github.com/springload/ecs-tool/lib" |
| 6 | + "github.com/apex/log" |
| 7 | + "github.com/spf13/cobra" |
| 8 | + "github.com/spf13/viper" |
| 9 | + "github.com/springload/ecs-tool/lib" |
10 | 10 | ) |
11 | 11 |
|
12 | | -var runCmd = &cobra.Command{ |
13 | | - Use: "runFargate", |
14 | | - Short: "Runs a command", |
15 | | - Long: `Runs the specified command on an ECS cluster, optionally catching its output. |
16 | | -
|
17 | | -It can modify the container command. |
18 | | -`, |
19 | | - Args: cobra.MinimumNArgs(1), |
20 | | - Run: func(cmd *cobra.Command, args []string) { |
21 | | - var containerName string |
22 | | - var commandArgs []string |
23 | | - if name := viper.GetString("container_name"); name == "" { |
24 | | - containerName = args[0] |
25 | | - commandArgs = args[1:] |
26 | | - } else { |
27 | | - containerName = name |
28 | | - commandArgs = args |
29 | | - } |
30 | | - |
31 | | - exitCode, err := lib.RunTask( |
32 | | - viper.GetString("profile"), |
33 | | - viper.GetString("cluster"), |
34 | | - viper.GetString("run.service"), |
35 | | - viper.GetString("task_definition"), |
36 | | - viper.GetString("image_tag"), |
37 | | - viper.GetStringSlice("image_tags"), |
38 | | - viper.GetString("workdir"), |
39 | | - containerName, |
40 | | - viper.GetString("log_group"), |
41 | | - viper.GetString("run.launch_type"), |
42 | | - commandArgs, |
43 | | - ) |
44 | | - if err != nil { |
45 | | - log.WithError(err).Error("Can't run task") |
46 | | - } |
47 | | - os.Exit(exitCode) |
48 | | - }, |
| 12 | +var runFargateCmd = &cobra.Command{ |
| 13 | + Use: "runFargate", |
| 14 | + Short: "Runs a command in Fargate mode", |
| 15 | + Long: `Runs the specified command on an ECS cluster, optionally catching its output. |
| 16 | +
|
| 17 | +This command is specifically tailored for future Fargate-specific functionality but currently duplicates the 'run' command.`, |
| 18 | + Args: cobra.MinimumNArgs(1), |
| 19 | + Run: func(cmd *cobra.Command, args []string) { |
| 20 | + var containerName string |
| 21 | + var commandArgs []string |
| 22 | + if name := viper.GetString("container_name"); name == "" { |
| 23 | + containerName = args[0] |
| 24 | + commandArgs = args[1:] |
| 25 | + } else { |
| 26 | + containerName = name |
| 27 | + commandArgs = args |
| 28 | + } |
| 29 | + |
| 30 | + exitCode, err := lib.RunFargate( |
| 31 | + viper.GetString("profile"), |
| 32 | + viper.GetString("cluster"), |
| 33 | + viper.GetString("run.service"), |
| 34 | + viper.GetString("task_definition"), |
| 35 | + viper.GetString("image_tag"), |
| 36 | + viper.GetStringSlice("image_tags"), |
| 37 | + viper.GetString("workdir"), |
| 38 | + containerName, |
| 39 | + viper.GetString("log_group"), |
| 40 | + viper.GetString("run.launch_type"), |
| 41 | + viper.GetString("run.security_group_filter"), |
| 42 | + commandArgs, |
| 43 | + ) |
| 44 | + if err != nil { |
| 45 | + log.WithError(err).Error("Can't run task in Fargate mode") |
| 46 | + } |
| 47 | + os.Exit(exitCode) |
| 48 | + }, |
49 | 49 | } |
50 | 50 |
|
51 | 51 | func init() { |
52 | | - rootCmd.AddCommand(runCmd) |
53 | | - runCmd.PersistentFlags().StringP("log_group", "l", "", "Name of the log group to get output") |
54 | | - runCmd.PersistentFlags().StringP("container_name", "", "", "Name of the container to modify parameters for") |
55 | | - runCmd.PersistentFlags().StringP("task_definition", "t", "", "name of task definition to use (required)") |
56 | | - viper.BindPFlag("log_group", runCmd.PersistentFlags().Lookup("log_group")) |
57 | | - viper.BindPFlag("container_name", runCmd.PersistentFlags().Lookup("container_name")) |
58 | | - viper.BindPFlag("task_definition", runCmd.PersistentFlags().Lookup("task_definition")) |
59 | | - viper.SetDefault("run.launch_type", "EC2") |
| 52 | + rootCmd.AddCommand(runFargateCmd) |
| 53 | + viper.SetDefault("run.security_group_filter", "*ec2*") |
| 54 | + viper.SetDefault("run.launch_type", "FARGATE") |
| 55 | + |
| 56 | + |
60 | 57 | } |
0 commit comments