Reputation: 345
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.
Upvotes: 4
Views: 3447
Reputation: 345
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.
Upvotes: 3
Reputation: 19461
When using Django, you typically want to migrate the data models using manage.py migrate
after deploying the app code. You can add startUpCommand
with post-deployment script for this purpose:
startUpCommand: python3.6 manage.py migrate
For details ,please refer to this official document.
Upvotes: 0