Azure / app-service-linux-docs

Azure App Service: Frequently Asked Questions on Linux App Service
Creative Commons Attribution 4.0 International
139 stars 79 forks source link

Post Deployment Script in Azure Web App for Containers #31

Open GisliGeorgs opened 4 years ago

GisliGeorgs commented 4 years ago

Is it possible to run a post-deploy script inside a container in Azure Web App for Containers(not the "regular" Web App with Kudu).

I have an ARM template that creates some resources, including a Web App for Containers where I use a Dockerhub image. I want to run a post-deployment script inside the container(a database migration script if that matters("bundle exec rake db:migrate" specifically)).

I can put the command into the Startup File in the Container Settings in the Azure Portal. That runs the command successfully, but it doesn't start up the container normally. So, I have to remove the Startup File migration command after it completes and then restart the Web App for it to start up normally. This is not optimal, neither is running the migration command on every startup/restart and then starting up the webserver.

This type of post-deploy script option is available in Heroku's template deployments, using the scripts object and the postdeploy key in it. See https://devcenter.heroku.com/articles/app-json-schema#scripts.

Does such a post-deploy script option exist for Azure Web App for Containers? I believe such an option exists for the regular Web Apps, but I haven't seen anything related to Web App for Containers. If not, is there a simpler/better way to run the migrate command than what I'm currently doing?

svains commented 4 years ago

@GisliGeorgs did you manage to solve this issue?

GisliGeorgs commented 4 years ago

No, not really, at least not in any better way than what I described.

rvvincelli commented 1 year ago

No, as of AppService v2 this just cannot be done. It is an architectural matter, the two components, Kudu and the application (PHP, Node.js, Tomcat etc) are distinct and there is no way to run a remote command on the app side via Kudu.

There're many discussions and questions around this, and in my understanding this is rooted on an architectural design choice which is there for security reasons. Nevertheless, this leaves the deployment with poor ergonomics, so poor that basically you might be forced to take care of your post-processing activities in the startup script of the webapp (making sure you don't block there).

Hopefully, v3 will provide better engagement in this sense. For our PHP-based deployment, this lack of viable solutions kept us guessing for a while, until we eventually gave up and take care of migration commands and stuff from inside the AppService start script.