-
Notifications
You must be signed in to change notification settings - Fork 5
Feature/fargate #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Feature/fargate #35
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
f182856
fargate support
teaguru c2c4b14
fargate support
teaguru 117ab1b
start working on exec
teaguru 02f844a
exec command
teaguru b71fd01
exec command
teaguru 1a85bf6
exec fixed
teaguru c49a42d
bump go
teaguru 3db714d
go version for releaser
teaguru 35b8d6f
public subnets support for Runfargate
teaguru f661b9d
Readme update
teaguru c0442c3
Merge branch 'master' into feature/fargate
teaguru 51cd96b
temp commit with exex improvements
teaguru e6cca82
exec linting commit
teaguru dce0f5e
gh actions fix
teaguru 9603938
Refactor exec command and improve code quality
teaguru File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "os" | ||
| "strings" | ||
|
|
||
| "github.com/apex/log" | ||
| "github.com/spf13/cobra" | ||
| "github.com/spf13/viper" | ||
| "github.com/springload/ecs-tool/lib" | ||
| ) | ||
|
|
||
| var execCmd = &cobra.Command{ | ||
| Use: "exec", | ||
| Short: "Executes a command in an existing ECS Fargate container", | ||
|
|
||
| Long: `Executes a specified command in a running container on an ECS Fargate cluster.`, | ||
| Args: cobra.MinimumNArgs(1), | ||
| Run: func(cmd *cobra.Command, args []string) { | ||
| viper.SetDefault("run.launch_type", "FARGATE") | ||
| var containerName string | ||
| var commandArgs []string | ||
| if name := viper.GetString("container_name"); name == "" { | ||
| // If container_name not provided via flag, use first arg as container name | ||
| if len(args) < 2 { | ||
| log.Error("When --container_name is not provided, at least 2 arguments are required: <container_name> <command>") | ||
| os.Exit(1) | ||
| } | ||
| containerName = args[0] | ||
| commandArgs = args[1:] | ||
| } else { | ||
| containerName = name | ||
| commandArgs = args | ||
| } | ||
|
|
||
| // Validate that we have a command to execute | ||
| if len(commandArgs) == 0 { | ||
| log.Error("No command provided to execute") | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| // Join the commandArgs to form a single command string | ||
| commandString := strings.Join(commandArgs, " ") | ||
|
|
||
| err := lib.ExecFargate(lib.ExecConfig{ | ||
| Profile: viper.GetString("profile"), | ||
| Cluster: viper.GetString("cluster"), | ||
| Command: commandString, | ||
| TaskID: viper.GetString("task_id"), | ||
| TaskDefinitionName: viper.GetString("task_definition"), | ||
| ContainerName: containerName, | ||
| }) | ||
| if err != nil { | ||
| log.WithError(err).Error("Can't execute command in Fargate mode") | ||
| os.Exit(1) | ||
| } | ||
| }, | ||
| } | ||
|
|
||
| func init() { | ||
| rootCmd.AddCommand(execCmd) | ||
| execCmd.PersistentFlags().StringP("task_id", "", "", "Task ID to use (will auto-extract task definition)") | ||
| viper.BindPFlag("task_id", execCmd.PersistentFlags().Lookup("task_id")) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "os" | ||
|
|
||
| "github.com/apex/log" | ||
| "github.com/spf13/cobra" | ||
| "github.com/spf13/viper" | ||
| "github.com/springload/ecs-tool/lib" | ||
| ) | ||
|
|
||
| var runFargateCmd = &cobra.Command{ | ||
| Use: "runFargate", | ||
| Short: "Runs a command in Fargate mode", | ||
| Long: `Runs the specified command on an ECS cluster, optionally catching its output. | ||
|
|
||
| This command is specifically tailored for future Fargate-specific functionality.`, | ||
| Args: cobra.MinimumNArgs(1), | ||
| Run: func(cmd *cobra.Command, args []string) { | ||
| viper.SetDefault("run.launch_type", "FARGATE") | ||
| viper.SetDefault("run.security_group_filter", "ec2") | ||
| var containerName string | ||
| var commandArgs []string | ||
| if name := viper.GetString("container_name"); name == "" { | ||
| containerName = args[0] | ||
| commandArgs = args[1:] | ||
| } else { | ||
| containerName = name | ||
| commandArgs = args | ||
| } | ||
|
|
||
| exitCode, err := lib.RunFargate( | ||
| viper.GetString("profile"), | ||
| viper.GetString("cluster"), | ||
| viper.GetString("run.service"), | ||
| viper.GetString("task_definition"), | ||
| viper.GetString("image_tag"), | ||
| viper.GetStringSlice("image_tags"), | ||
| viper.GetString("workdir"), | ||
| containerName, | ||
| viper.GetString("log_group"), | ||
| viper.GetString("run.launch_type"), | ||
| viper.GetString("run.security_group_filter"), | ||
| commandArgs, | ||
| ) | ||
| if err != nil { | ||
| log.WithError(err).Error("Can't run task in Fargate mode") | ||
| } | ||
| os.Exit(exitCode) | ||
| }, | ||
| } | ||
|
|
||
| func init() { | ||
| rootCmd.AddCommand(runFargateCmd) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,36 +1,69 @@ | ||
| module github.com/springload/ecs-tool | ||
|
|
||
| go 1.17 | ||
| go 1.21 | ||
|
|
||
| require ( | ||
| github.com/Shopify/ejson v1.2.1 | ||
| github.com/apex/log v1.0.0 | ||
| github.com/aws/aws-sdk-go v1.55.5 | ||
| github.com/aws/aws-sdk-go v1.43.24 | ||
| github.com/aws/aws-sdk-go-v2 v1.26.1 | ||
| github.com/aws/aws-sdk-go-v2/config v1.26.3 | ||
| github.com/aws/aws-sdk-go-v2/service/ecs v1.41.7 | ||
| github.com/fujiwara/ecsta v0.4.5 | ||
| github.com/imdario/mergo v0.3.11 | ||
| github.com/spf13/cobra v0.0.3 | ||
| github.com/spf13/viper v1.0.2 | ||
| golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4 | ||
| golang.org/x/crypto v0.14.0 | ||
| ) | ||
|
|
||
| require ( | ||
| github.com/BurntSushi/toml v0.3.1 // indirect | ||
| github.com/davecgh/go-spew v1.1.1 // indirect | ||
| github.com/Songmu/flextime v0.1.0 // indirect | ||
| github.com/Songmu/prompter v0.5.1 // indirect | ||
| github.com/alecthomas/kong v0.7.0 // indirect | ||
| github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.5.4 // indirect | ||
| github.com/aws/aws-sdk-go-v2/credentials v1.16.14 // indirect | ||
| github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.11 // indirect | ||
| github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.5 // indirect | ||
| github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.5 // indirect | ||
| github.com/aws/aws-sdk-go-v2/internal/ini v1.7.2 // indirect | ||
| github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs v1.31.0 // indirect | ||
| github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.10.4 // indirect | ||
| github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.10.10 // indirect | ||
| github.com/aws/aws-sdk-go-v2/service/sns v1.26.7 // indirect | ||
| github.com/aws/aws-sdk-go-v2/service/ssm v1.44.7 // indirect | ||
| github.com/aws/aws-sdk-go-v2/service/sso v1.18.6 // indirect | ||
| github.com/aws/aws-sdk-go-v2/service/ssooidc v1.21.6 // indirect | ||
| github.com/aws/aws-sdk-go-v2/service/sts v1.26.7 // indirect | ||
| github.com/aws/smithy-go v1.20.2 // indirect | ||
| github.com/creack/pty v1.1.20 // indirect | ||
| github.com/dustin/gojson v0.0.0-20160307161227-2e71ec9dd5ad // indirect | ||
| github.com/fsnotify/fsnotify v1.4.7 // indirect | ||
| github.com/fujiwara/tracer v1.0.2 // indirect | ||
| github.com/hashicorp/hcl v0.0.0-20180404174102-ef8a98b0bbce // indirect | ||
| github.com/inconshreveable/mousetrap v1.0.0 // indirect | ||
| github.com/itchyny/gojq v0.12.11 // indirect | ||
| github.com/itchyny/timefmt-go v0.1.5 // indirect | ||
| github.com/jmespath/go-jmespath v0.4.0 // indirect | ||
| github.com/magiconair/properties v1.8.0 // indirect | ||
| github.com/mattn/go-isatty v0.0.16 // indirect | ||
| github.com/mattn/go-runewidth v0.0.14 // indirect | ||
| github.com/mitchellh/mapstructure v0.0.0-20180511142126-bb74f1db0675 // indirect | ||
| github.com/olekukonko/tablewriter v0.0.5 // indirect | ||
| github.com/pelletier/go-toml v1.2.0 // indirect | ||
| github.com/pkg/errors v0.9.1 // indirect | ||
| github.com/rivo/uniseg v0.3.4 // indirect | ||
| github.com/samber/lo v1.36.0 // indirect | ||
| github.com/smartystreets/goconvey v1.6.4 // indirect | ||
| github.com/spf13/afero v1.1.1 // indirect | ||
| github.com/spf13/cast v1.2.0 // indirect | ||
| github.com/spf13/jwalterweatherman v0.0.0-20180109140146-7c0cea34c8ec // indirect | ||
| github.com/spf13/pflag v1.0.1 // indirect | ||
| github.com/stretchr/testify v1.5.1 // indirect | ||
| golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e // indirect | ||
| golang.org/x/text v0.3.7 // indirect | ||
| gopkg.in/yaml.v2 v2.3.0 // indirect | ||
| github.com/tkuchiki/go-timezone v0.2.2 // indirect | ||
| github.com/tkuchiki/parsetime v0.3.0 // indirect | ||
| golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17 // indirect | ||
| golang.org/x/sys v0.13.0 // indirect | ||
| golang.org/x/term v0.13.0 // indirect | ||
| golang.org/x/text v0.13.0 // indirect | ||
| gopkg.in/yaml.v2 v2.4.0 // indirect | ||
| ) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.