I am wondering if anybody has experience with integrating a python manage.py migrate command into a MS Azure release pipeline. The app is being deployed using CI/CD pipeline through DevOps. In the release pipeline portion, the app is being deployed to three different stages (dev, test and prod). I have not been successful in being able to integrate the migrate command into the deployment process. I have tried achieving this by using a post deployment inline script:
/antenv/bin/python /home/site/wwwroot/manage.py collectstatic
/antenv/bin/python /home/site/wwwroot/manage.py migrate
If I run the above commands in the sandbox environment via SSH they are carried out successfully. However, including them in the release pipeline as a post deployment script raises the following error:
2020-03-22T19:00:32.8641689Z Standard error from script: 
2020-03-22T19:00:32.8727872Z ##[error]/home/site/VSTS_PostDeployment_1321584903618191/kuduPostDeploymentScript.sh: 1: /home/site/VSTS_PostDeployment_1321584903618191/kuduPostDeploymentScript.sh: /antenv/bin/python: not found
/home/site/VSTS_PostDeployment_1321584903618191/kuduPostDeploymentScript.sh: 2: /home/site/VSTS_PostDeployment_1321584903618191/kuduPostDeploymentScript.sh: /antenv/bin/python: not found
2020-03-22T19:01:34.3372528Z ##[error]Error: Unable to run the script on Kudu Service. Error: Error: Executed script returned '127' as return code. Error: /home/site/VSTS_PostDeployment_1321584903618191/kuduPostDeploymentScript.sh: 1: /home/site/VSTS_PostDeployment_1321584903618191/kuduPostDeploymentScript.sh: /antenv/bin/python: not found
/home/site/VSTS_PostDeployment_1321584903618191/kuduPostDeploymentScript.sh: 2: /home/site/VSTS_PostDeployment_1321584903618191/kuduPostDeploymentScript.sh: /antenv/bin/python: not found
I also attempted running the above in-line script as:
manage.py collectstatic
manage.py migrate
But to no avail.
Based on the Oryx documentation, it seems as though manage.py collectstatic is being run, but not manage.py migrate
Any ideas or suggestions would be very much appreciated! Thanks in advance.
Since we want to be able to use the release pipeline infrastructure on Azure DevOps, we cannot use startUpCommand:  python3.6 manage.py migrate because there is no YAML file associated with the release in devops (at least as of yet). Instead, what finally worked was:
Procfile.sh. In this file I added the following two lines of code:python manage.py migrate
python manage.py collectstatic --no-input
 {
    "name": "POST_BUILD_SCRIPT_PATH",
    "slotSetting": false,
    "value": "Procfile.sh"
  }
If you are running the collectstatic command in your script, you will want to disable the Oryx engine from running it as well:
{
    "name": "DISABLE_COLLECTSTATIC",
    "slotSetting": false,
    "value": "true"
  },
See Oryx documentation for more details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With