aws / apprunner-roadmap

This is the public roadmap for AWS App Runner.
https://aws.amazon.com/apprunner/
Other
292 stars 13 forks source link

Can't Run Multiple Commands Under "Build command" Config? #241

Open pihish opened 3 months ago

pihish commented 3 months ago

I have the following in my package.json file:

"scripts": {
    "migrate": "knex migrate:latest"
},

Running npm run migrate works fine on my local machine. When I try to add this command onto my existing build command:

1

App Runner always gives an error and rolls back my change:

2

Does App Runner not support multiple build commands?

Leonelmarianog commented 2 months ago

I had the same problem when defining the start command.

Example:

start command -> npm ci && npm run build ✅ build command -> npm run migration:run && npm run start

I remember the error being related to the &&. What I did as a workaround is creating a new script that encapsulated everything I wanted to do:

start command -> npm ci && npm run build ✅ build command -> npm run start:cd ✅ (cd as in Continuous Deployment)

With npm run start:cd being:

"scripts": {
    "start:cd": "npm run migration:run && npm run start:prod",
},

If that still doesn't do it, I would check the service logs to see what is causing the rollback to happen.

pihish commented 2 months ago

I had the same problem when defining the start command.

Example:

start command -> npm ci && npm run build ✅ build command -> npm run migration:run && npm run start

I remember the error being related to the &&. What I did as a workaround is creating a new script that encapsulated everything I wanted to do:

start command -> npm ci && npm run build ✅ build command -> npm run start:cd ✅ (cd as in Continuous Deployment)

With npm run start:cd being:

"scripts": {
    "start:cd": "npm run migration:run && npm run start:prod",
},

If that still doesn't do it, I would check the service logs to see what is causing the rollback to happen.

So you're running your custom start:cd command as the build command - even though the second command it calls starts the server? Or did you mean to put that under the start command input on the App Runner config page?

What I think you're trying to say:

With the App Runner "build command", you're running npm ci && npm run build. Then with the App Runner "start command", you're running your custom npm run start:cd command (which runs your DB migrations and starts the Express / React server).

pihish commented 2 months ago

Another data point here - I tried running npm run migrate by itself under the App Runner "build command" and got the same rollback error. That's probably because without npm install, the knex library isn't available. I tried npm install; npm run migrate and got the rollback error too.

The crux of the problem here is that App Runner doesn't provide actual logs that tell you what went wrong. I saw this brought up as a complaint from way back in 2021 and it doesn't seem like it has ever been addressed.

pihish commented 2 months ago

The really weird thing is that I can't seem to run any command in the App Runner "build command" input other than npm install. I tried npm install -g and even that got rolled back automatically.

Would be nice if someone from the App Runner team could actually chime in and provide some insight as to why setting up basic configs do not work.