4

I am deploying a web app using the Python-Django framework to Microsoft Azure.

I have succeeded in deploying it, but every time I deploy, I have to open the Azure SSH tool and run the command apt-get install libgtk2.0-dev which I gather is some Linux dependency for the opencv-python image processing library.

I wonder if there is a way to install the required software using deploy.sh files.

deploy.sh

echo "Running Linux Deployment Script..."

apt-get update && apt install -y libxrender1 libxext6
apt-get install -y libfontconfig1
apt-get install libgtk2.0-dev

Thanks in advance for your help.

Sathiamoorthy
  • 8,831
  • 9
  • 65
  • 77
Nadim
  • 41
  • 2

4 Answers4

1

You can create a script to install libgtk2.0-dev, say test.sh under /home/site. And then add an app setting under 'Configuration' called PRE_BUILD_SCRIPT_PATH with /home/site/test.sh as the value.

sa23
  • 328
  • 2
  • 5
  • 1
    PRE_BUILD_SCRIPT_PATH is not run w/ root privileges, see for example here: https://github.com/microsoft/Oryx/issues/470 – HeyMan Sep 21 '21 at 13:57
1

You can run a script on every Webapp startup. Just adjust your script as described here: https://stackoverflow.com/a/69923647/2606766

Create a start.sh file, e.g. like this:

# install package & start app
apt-get update -y
apt install -y libxrender1 libxext6
apt-get install -y libfontconfig1
apt-get install libgtk2.0-dev

# don't forget to start your webapp service at the end of this script, e.g.:
python manage.py runserver

Set it as your startup script:

enter image description here

Note: There are two pitfalls to this approach:

  1. The script must be executable, so either install w/ unix and chmod 755 start.sh or use a git command (see SO).
  2. The packages are installed on every startup, thus you depend on external servers/repositories when starting the webapp.
HeyMan
  • 1,529
  • 18
  • 32
  • Every deployment, I am getting this issue `2022-09-01T08:29:17.865634150Z /opt/startup/startup.sh: 23: /opt/startup/startup.sh: start.sh: not found`. If I restart the server, the issue is not appear. the problem here, everytime, I have to restart the server – Sathiamoorthy Sep 01 '22 at 10:28
  • Yes I think there is no other way, after deployment you need to restart the server. Actually I think it should even restart automatically after deployment, doesn’t it? – HeyMan Sep 01 '22 at 12:21
  • Yes, during automatic deploy and restart I am getting this issue. After the automatic restart, the server failed to start, if I do the manual start, it ups and runs. – Sathiamoorthy Sep 01 '22 at 12:39
  • I’m currently travelling but will try to help if possible. Is your root really opt/startup? Maybe it’s a link which does not exist upon startup. Just an idea. Our root is /home/site/wwwroot or something similar – HeyMan Sep 01 '22 at 15:51
  • Ah now I understand the startup.sh is the internal system start command which calls the start.sh. Any progress on the issue? When you ssh into the system after deployment what is the path? Is the start.sh there? Is it executable? „ls -al start.sh“ – HeyMan Sep 03 '22 at 06:19
  • start.sh is there and executable. Using CI/CD, it is not executing, if I do the manual restart it works. I don't know the exact path of deployment path, but in the log found this message `Content root path: /app` – Sathiamoorthy Sep 03 '22 at 14:06
  • Strange when I deploy via ci/cd it takes a while but the system reboots automatically and everything works. Can you post your pipeline, maybe I see a difference. – HeyMan Sep 03 '22 at 18:55
  • Have you added any configuration? I am using this application configuration in my CD `-ENABLE_ORYX_BUILD true -SCM_DO_BUILD_DURING_DEPLOYMENT true` – Sathiamoorthy Sep 04 '22 at 03:44
  • Sorry I cannot look it up but as I remember we use something like deploy_as_zip. We do not use the flags you mentioned. – HeyMan Sep 04 '22 at 05:09
  • I deployed same zip format but added this settings. – Sathiamoorthy Sep 04 '22 at 09:58
  • Sorry I cannot help further at that stage. I assume you need to fiddle around with those settings. It is definitely Possible. – HeyMan Sep 04 '22 at 16:40
  • I assume the best would be to open a proper SO question for this issue then you can upload your entire pipeline etc. – HeyMan Sep 05 '22 at 05:47
0

You can set SCM_POST_DEPLOYMENT_ACTIONS_PATH environment variable to configure a folder. All scripts in this folder will be executed after deployment. As far as I can see this should work both on Windows and Linux.

If you need root permissions then I would suggest to use a custom docker container which has these packages already installed.

Alex AIT
  • 17,361
  • 3
  • 36
  • 73
0

You can start by adding this command directly to the startup script, As mentioned in the answer by @HeyMan. But instead of adding a file just add the command there apt-get update && apt install -y libxrender1 libxext6 && apt-get install -y libfontconfig1 && apt-get install libgtk2.0-dev

Add this command in a single line there.

If this method also does not work for you, then you should follow the container based approach.

  1. Create a dockerfile and add all the required dependency there.
  2. docker build to create a docker image.
  3. Push that image to Azure container registry using docker push
  4. Instead of deploying from local git, deploy with help of docker.

Look at this link for help https://learn.microsoft.com/en-us/azure/container-registry/container-registry-get-started-docker-cli?tabs=azure-cli

shashank2806
  • 480
  • 6
  • 14