Skip to content

Commit 1a85bf6

Browse files
committed
exec fixed
1 parent b71fd01 commit 1a85bf6

File tree

3 files changed

+6
-9
lines changed

3 files changed

+6
-9
lines changed

cmd/exec.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,11 @@ var execCmd = &cobra.Command{
1818
Args: cobra.MinimumNArgs(1),
1919
Run: func(cmd *cobra.Command, args []string) {
2020
viper.SetDefault("run.launch_type", "FARGATE")
21-
var containerName string
21+
//var containerName string
2222
var commandArgs []string
2323
if name := viper.GetString("container_name"); name == "" {
24-
containerName = args[0]
2524
commandArgs = args[1:]
2625
} else {
27-
containerName = name
2826
commandArgs = args
2927
}
3028

@@ -34,8 +32,6 @@ var execCmd = &cobra.Command{
3432
err := lib.ExecFargate(
3533
viper.GetString("profile"),
3634
viper.GetString("cluster"),
37-
viper.GetString("run.service"),
38-
containerName,
3935
commandString, // Pass the combined command string
4036
)
4137
if err != nil {

lib/exec.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/aws/aws-sdk-go-v2/config"
99
"github.com/aws/aws-sdk-go-v2/service/ecs"
1010
"github.com/fujiwara/ecsta"
11+
"os"
1112
)
1213

1314
var sessionInstance *ecs.Client
@@ -22,14 +23,16 @@ func InitAWS(profile string) error {
2223
if err != nil {
2324
return fmt.Errorf("failed to load configuration: %w", err)
2425
}
26+
os.Setenv("AWS_PROFILE", profile) //required for aws sdk
2527
sessionInstance = ecs.NewFromConfig(cfg)
2628
sessionConfig = cfg // Save session configuration
2729
}
2830
return nil
2931
}
3032

3133
// ExecFargate executes a command in a specified container on an ECS Fargate service
32-
func ExecFargate(profile, cluster, service, containerName, command string) error {
34+
func ExecFargate(profile, cluster, command string) error {
35+
3336
if err := InitAWS(profile); err != nil {
3437
return fmt.Errorf("failed to initialize AWS session: %w", err)
3538
}
@@ -39,15 +42,13 @@ func ExecFargate(profile, cluster, service, containerName, command string) error
3942
if err != nil {
4043
return fmt.Errorf("failed to create ecsta application: %w", err)
4144
}
42-
service = "app"
4345

4446
entrypoint := "/usr/bin/ssm-parent"
4547
configPath := "/app/.ssm-parent.yaml"
4648
fullCommand := fmt.Sprintf("%s -c %s run -- %s", entrypoint, configPath, command)
4749
execOpt := ecsta.ExecOption{
4850
Command: fullCommand,
4951
}
50-
fmt.Println(execOpt)
5152
if err := ecstaApp.RunExec(context.Background(), &execOpt); err != nil {
5253
return fmt.Errorf("failed to execute command: %w", err)
5354
}

lib/runFargate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ securityGroups, err := fetchSecurityGroupsByName(svcEC2, securityGroupFilter)
6363
var foundContainerName bool
6464
if err := modifyContainerDefinitionImages(imageTag, imageTags, workDir, taskDefinition.ContainerDefinitions, ctx); err != nil {
6565
return 1, err
66-
}
66+
}
6767
for n, containerDefinition := range taskDefinition.ContainerDefinitions {
6868
if aws.StringValue(containerDefinition.Name) == containerName {
6969
foundContainerName = true

0 commit comments

Comments
 (0)