air-verse / air

☁️ Live reload for Go apps
GNU General Public License v3.0
16.35k stars 771 forks source link

Continuous processes in cmd do not trigger subsequent builds #548

Open andrehoong-pixieset opened 3 months ago

andrehoong-pixieset commented 3 months ago

Hello, I am trying to set up air for an AWS Lambda development environment. I have this cmd defined in the .air.toml file: cmd = "go build -o ./tmp/main . ; ~/.aws-lambda-rie/aws-lambda-rie ./go/main main.handle

The idea is whenever air rebuilds the executable we launch aws-lambda-rie with that new executable. My issue is when using this command, air does not rebuild any changes. In the logs I will only get main.go has changed , but no build is triggered after that.

I suspect this is because ~/.aws-lambda-rie/aws-lambda-rie ./go/main main.handle starts an ongoing process and as a result running cmd does not return an exit code. I was considering running the aws-lambda-rie through the post_cmd, but it looks like that isn't implemented at all.

Any suggestions are greatly appreciated!

kema-dev commented 2 weeks ago

Hello ! You might be trying to locally run your lambda, maybe this setup can help you :shrug:

I use public.ecr.aws/lambda/provided:al2023 as base image for my local-dev image, install go from sources, then add this as ENTRYPOINT:

ENTRYPOINT ["air", "-c", "config/.air-local.toml"]

Here is a relevant part of air-local.toml

[build]
cmd = "go build -o /var/runtime/bootstrap ./cmd/${GO_MAIN_FILE_DIR}"
bin = "/lambda-entrypoint.sh"
args_bin = ["whatever"]

Doing so, editing my Go files triggers a build and re-runs aws-lambda-rie as needed (this is handled by default in the image's /lambda-entrypoint.sh)

You can find a bit of help in the official doc