0

I have a Django web app on Azure. I'm using Azure's built in continuous deployment, so I don't have any .deployment files within my repo.

However, in order for my application to work correctly, I have to manually install a couple packages after that aren't available via pip. So after every deployment, I have to SSH into the deployment and execute the following 2 commands:

source home/site/wwwroot/pythonenv3.6/bin/activate
sudo apt-get install XXX XXX XXX

I believe I can simply execute this via a post deployment script, but am having a hard time finding any literature explaining exactly how to do so. Is utilizing a post deployment script the best way of doing this? I'd rather not manage a custom docker file if possible.

UPDATE Here is a screen shot of the packages installed after I manually run the apt-get command:enter image description here

And here is a screen shot of the packages installed AFTER a re-deploy: enter image description here

So unless there's a way to run this command from a post-deployment script (and have it execute correctly), my only option will be to create a custom container? I'm not wild about doing so considering that this is such a small customization... but I may no longer have a choice?

UPDATE I tried adding "apt-get install XXX XXX" to "PRE_BUILD_COMMAND" in Azure... and I got the following message as a result: enter image description here

Are there any ideas how to get around this message using a prebuild or post build command?

George Rodman
  • 289
  • 7
  • 19
  • Pls try to use `apt-get update` and `apt-get install g++`, for more details , pls read https://stackoverflow.com/questions/64640016/how-to-access-odbc-driver-on-azure-app-service/64674606#64674606 – Jason Pan Nov 18 '20 at 06:36
  • If it works pls let me know, if you need further help, you need create a sample code without any confidential information. – Jason Pan Nov 18 '20 at 06:39
  • Won't I still have to run these lines after every new deployment? I'm trying to find a solution where I can automate the execution of these commands, and so I won't have to re-run them after every deployment. – George Rodman Nov 18 '20 at 13:33
  • [This document](https://jlamch.blogspot.com/2017/03/azure-post-deployment-scripts.html) introduces files in .bat, ps1 and other formats, and commands in the file can be executed during redeploy. – Jason Pan Nov 19 '20 at 07:37
  • I will try to use `apt-get install xxx` and use redeploy to check the environment. https://stackoverflow.com/questions/64640016/how-to-access-odbc-driver-on-azure-app-service/64674606#64674606 – Jason Pan Nov 19 '20 at 07:40
  • Every step has been tested, I hope it will help you, there is another post, which can be executed normally, but it is not necessary. – Jason Pan Nov 19 '20 at 09:04

1 Answers1

0

UPDATE

The command like below.

You must have the wrong path, just enter /home, and then enter the command you want to execute, remember not to add sudo.

enter image description here

PRIVIOUS

First of all, please check this post. The pyodbc in the post cannot be used. Later, I used apt-get install xxx and pip install to solve this problem.

I know you want to use the .sh file, when you publish or re-publish, or when you publish for the first time, execute your apt-get install xxx command.

But after my test, I can tell you that you only need to execute the command once after the portal creates the webapp, or after the first release, to configure the environment without having to execute the .sh file again.

In conclusion:

It is recommended to execute commands such as apt-get install xxx and pip install xxx after the first release using git. Then modify the Readme.md file on github to trigger the redeployment process.

You don’t need to execute the .sh file for every deployment in the future. I replied to your other post. You can execute the .sh file, but there is no need to call it every time after you execute it manually. Because this is a configurable environment variable, the configuration is successful.

Step 1. Install env.

enter image description here

Step 2. Modify readme.md,check deploy status.

we can see my custom .sh command is running.But we no need to do that.

enter image description here

Step 3. Check the webapp after finishing env config .

enter image description here

Jason Pan
  • 15,263
  • 1
  • 14
  • 29
  • Thanks. But it looks like it doesn't persist for me. I've added screenshots above that show the list of packages which exist before & after deployment. And after some more research, it looks like they aren't expected to? https://learn.microsoft.com/en-us/answers/questions/8949/msdn-redirect-azure-app-services-with-linux-instal.html – George Rodman Nov 19 '20 at 18:22
  • Are you doing something else that enables them to persist? – George Rodman Nov 19 '20 at 18:22
  • I wouldn't mind having the packages installed in the install_cmd.sh, but I receive "are you root?" errors every time I try. Have you encountered those? – George Rodman Nov 19 '20 at 18:27
  • I tried executing apt-get install XXXX as part of a pre-build command, and it didn't work. I've shared the screen shot of the response above. Would love any thoughts you have? – George Rodman Nov 19 '20 at 19:56
  • All my commands are executed under the `/home` path, which is the default path under the ssh page just entered. – Jason Pan Nov 20 '20 at 02:15
  • @GeorgeRodman In addition, the script execution of `apt-get install xxx` takes time to download, and `pip install xxx` also takes time, so there is no guarantee that the installation process can be completed or the installation commands are valid before the web release is completed. – Jason Pan Nov 20 '20 at 02:18
  • @GeorgeRodman I personally tested it. I used `Post Deployment Script Commands` to install pyodbc under linux. After the first release, the project could not start normally. This method is unstable or currently not feasible. You need to find the official Microsoft confirm. Then my alternative is to manually execute it once under the `/home` path, and the project runs normally. – Jason Pan Nov 20 '20 at 02:21
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/224822/discussion-between-jason-pan-and-george-rodman). – Jason Pan Nov 20 '20 at 02:21