kayac / ecspresso

ecspresso is a deployment tool for Amazon ECS
MIT License
826 stars 90 forks source link

Got panic when `ecspresso run` #749

Closed aikawame closed 3 weeks ago

aikawame commented 2 months ago

I encountered the error panic: runtime error: invalid memory address or nil pointer dereference, so I report this.

Command:

ecspresso run \
  --config ./config/deploy/staging/ecspresso-application.yml \
  --ext-str tag=develop-1d7386088d62597c8028f18d782c1ed56f3fab47 \
  --latest-task-definition \
  --watch-container application \
  --overrides '{"containerOverrides":[{"name":"application", "command":["rails db:migrate"]}]}'

The detailed error message is below.

2024/09/13 11:28:26 [INFO] ecspresso version: v2.4.1
2024/09/13 11:28:26 hoge-staging-application/ecs-hoge-staging-application Running task
2024/09/13 11:28:27 hoge-staging-application/ecs-hoge-staging-application Revision is not specified. Use latest task definition family hoge-staging-application
2024/09/13 11:28:27 hoge-staging-application/ecs-hoge-staging-application Task definition ARN: arn:aws:ecs:ap-northeast-1:364292382367:task-definition/hoge-staging-application:329
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x188 pc=0x105e2d828]

goroutine 1 [running]:
github.com/kayac/ecspresso/v2.(*App).Run(0x1400036ae80, {0x106605090, 0x140001a19c0}, {0x0, {0x0, 0x0}, 0x1, {0x1400034e690, 0x4f}, {0x0, ...}, ...})
    /home/runner/work/ecspresso/ecspresso/run.go:80 +0x4f8
github.com/kayac/ecspresso/v2.dispatchCLI({0x106605090, 0x140001a19c0}, {0x14000396fba, 0x3}, 0x140003f2b30, 0x1400018a360)
    /home/runner/work/ecspresso/ecspresso/cli.go:138 +0x31c
github.com/kayac/ecspresso/v2.CLI({0x106605090, 0x140001a19c0}, 0x1072540e0?)
    /home/runner/work/ecspresso/ecspresso/cli.go:174 +0x90
main.main()
    /home/runner/work/ecspresso/ecspresso/cmd/ecspresso/main.go:19 +0xa4

Dry-run worked fine, but when I run the actual command, it looks like the above.

fujiwara commented 2 months ago

@aikawame Thank you for the reporting!

This panic seems to be caused by the failure to find the container specified by --watch-container application.

https://github.com/kayac/ecspresso/blob/99d873bab684e08ef3de33dda37d9f676b16e9b7/run.go#L79-L80

If the watchContainer is nil, raise a panic at *watchContainer.Name.

Please check for your task definition. Does it have a container definition named application?

By the way, this panic is undesirable. I'll fix it to return an error if a container definition is not found.

aikawame commented 2 months ago

@fujiwara Thank you for your quick reply!

As you said, this problem was caused by the wrong container name. And thank you for your help in fixing panic.