microsoft / Oryx

Build your repo automatically.
Other
769 stars 176 forks source link

Custom startup for Azure web app deployment #1763

Closed bryanchen-d closed 10 months ago

bryanchen-d commented 1 year ago

Hi, I want to deploy a python web app using zip deploy into an azure web service, and I have a custom startup.sh. As I can see from the deployment log, it calls oryx build and run using gunicorn, how should I configure it to run with my own startup script? Like, could it be specified in 'appsvc.yaml'?

Thanks.

cormacpayne commented 1 year ago

@bryanchen-d Hey Bryan, apologies for the delayed response -- for context: your application source that you provide as a part of zip deployment will be built within one of Oryx's build images and the build artifacts will be sent to one of Oryx's run images that will host your application. In both of these images, Oryx provides mechanisms to allow the user to run additional commands when needed.

For the build stage, you can check out our configuration.md file to see the environment variables that you can set to run additional commands, such as PRE_BUILD_COMMAND or PRE_BUILD_SCRIPT_PATH.

For the run stage, you can use an appsvc.yaml file to define the set of commands that you want to run, including executing a startup.sh script that you have.

Please feel free to let us know if this doesn't handle your scenario or doesn't work for you and we can assist anyway we can. Thanks!

bryanchen-d commented 1 year ago

For the run stage, you can use an appsvc.yaml file to define the set of commands that you want to run, including executing a startup.sh script that you have.

This link doesn't show how to specify a custom startup.sh script, for appsvc.yaml file, it seems to only support two settings, and they are all for the "build" stage:


version: 1

pre-build: | apt install curl

post-build: | python manage.py makemigrations python manage.py migrate


Do I miss anything?
cormacpayne commented 1 year ago

@bryanchen-d Sorry, it looks like our documentation around this file wasn't update when we added support for the run property -- you should be able to do the following in your appsvc.yaml file:

version: 1

run: ./startup.sh

(you may need to include the full path to your startup.sh script in the run command)

bryanchen-d commented 1 year ago

Thanks @cormacpayne , I just tried that but it doesn't seem to work. Below is partial of the log, I wonder if that oryx build has this support or not, or do I miss something, could you take a look?

1:03:58 PM streamlit-test-app: Running oryx build... 1:03:58 PM streamlit-test-app: Command: oryx build /tmp/zipdeploy/extracted -o /home/site/wwwroot --platform python --platform-version 3.10 -p virtualenvname=antenv --log-file /tmp/build-debug.log -i /tmp/8daef605cc4e174 --compress-destination-dir | tee /tmp/oryx-build.log 1:03:59 PM streamlit-test-app: Operation performed by Microsoft Oryx, https://github.com/Microsoft/Oryx 1:03:59 PM streamlit-test-app: You can report issues at https://github.com/Microsoft/Oryx/issues 1:03:59 PM streamlit-test-app: Oryx Version: 0.2.20220825.1, Commit: 24032445dbf7bf6ef068688f1b123a7144453b7f, ReleaseTagName: 20220825.1 1:03:59 PM streamlit-test-app: Build Operation ID: |UGNS8d2KTe8=.d676f917 1:03:59 PM streamlit-test-app: Repository Commit : 16272e38-1ba9-459b-8b6b-e30f625e7222 1:03:59 PM streamlit-test-app: Detecting platforms... 1:04:00 PM streamlit-test-app: Detected following platforms: 1:04:00 PM streamlit-test-app: python: 3.10.9 1:04:00 PM streamlit-test-app: Version '3.10.9' of platform 'python' is not installed. Generating script to install it...

cormacpayne commented 1 year ago

Chatted with @bryanchen-d offline to get additional context on his scenario -- it looks like there is some disjoint between what we do when reading the run property in the appsvc.yaml and what App Service does when a user provides a value for Startup Command through the Portal.

App Service allows users to provide a command (or set of commands) or a startup script to the Startup Command field in the Portal; when provided, App Service will provide the value to the -userStartupCommand argument that's part of the oryx create-script command called by App Service when launching the app. If a value is provided to -userStartupCommand, the default platform run script that Oryx creates is ignored entirely in favor of the command(s)/script provided.

As of this PR, Oryx began reading the run property when set in the appsvc.yaml file to allow users to provide a command (or set of commands) to run at the end of the generated run.sh script. However, to me, it's not entirely clear that the run property is just appending a value, and run clashes with the naming convention we have for the other pre-build and post-build properties that prepend or append to the build script, respectively.

This leaves us with two seemingly disjointed behaviors: one where the user can go through the Portal to override the set of commands ran when launched entirely, and one where the user can append a set of commands to the end of the run script using the appsvc.yaml file. For the scenario outlined by @bryanchen-d, he's looking to run a command before the run script, which we don't currently offer, nor do we offer the ability to replace the entire run script we generate similar to the Portal behavior.

In practice, I would expect the following naming conventions within the appsvc.yaml file:

pre-run: <command(s) ran before the run script that's generated>

run: <command(s) that should be run instead of the run script that's generated>

post-run: <command(s) ran after the run script that's generated>

I think this is something worth double-checking with App Service as to what we would want the targeted behavior to be here.

paoloriccardi commented 1 year ago

Hi, I'm trying to deploy a django webapp with saml2 authentication which requires some packages to be downloaded via apt. The runtime is python 3.9. Following the documentation about appsvc I tried to install said packages with:

version: 1
pre-build: apt install -y xmlsec1 libssl-dev libsasl2-dev

But the build failed with the error:

E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)\n
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root?

The same happens if I put the instruction in post-build as well. I tried to put the command in run and the deployment completed, but it seems that it was just ignored (even though the webapp was instead regularly deployed without the packages required).

I am sure I'm missing something. Any help would be appreciated, thanks in advance.

Thanks

simonjj commented 10 months ago

We're closing this issue due to its age. If this is still impacting you please open a new issue and simply link back to this one.