9. Automate deployment using runscripts management command

9.1. Overview:

The idea is to make the deployment process easier by running one management command responsible for running all scripts in one release. The runscript management command checks the current version of the release settings.CODE_VERSION, determines all non-applied scripts specific to that version then, applies them.

9.2. Adding a new script to be run:

  • Make sure to update settings.CODE_VERSION before running the script.

  • Go to the following path: pearlcertification/core/management/commands/runscripts.py and write the list of scripts to apply in the scripts list under Command class (make sure to add any arguments or kwargs the script needs):

scripts = [
    Script("testscript", "v3.25.0", database="resnet", site="cert"),
    Script("import", "v3.25.0", "file.txt", database="resnet", site="pqs"),
]
  • To execute the runscripts command use the following code:

python manage.py runscripts
  • Any script that was successfully applied will be stored in the database under the ManagementCommand model whose data can be viewed under django admin page /cert_admin/core/managementcommand/.

  • To make scripts run only in one specific site (cert, green_door, pqs, rea) set site kwarg in Script() as following:

Script("testscript", "v3.25.0", database="resnet", site="cert")