Skip to content

Running Django management commands using webapp-pre-deploy

Applications created and deployed to Google Cloud Platform using the webapp and deploy boilerplates include a Cloud Run job called webapp-pre-deploy. This Cloud Run job is automatically executed when a new webapp version is deployed as part of our GitLab CI/CD flow. It can also be executed directly in the Google Cloud console, or via the Google Cloud CLI.

By default the webapp-pre-deploy Cloud Run job uses the latest webapp Docker image to run the Django admin migrate command, but it can also be used to run other django-admin or management commands.

Goggle Cloud console

The webapp-pre-deploy Cloud Run job is listed alongside the webapp in the Google Cloud Run overview for the project in the Google Cloud console with details of the webapp-pre-deploy executions listed on its page.

The webapp-pre-deploy job's UI provides click-ops methods for executing the job using the default configuration, as defined in gcp-deploy-boilerplate, or by using overrides.

Executing the webapp-pre-deploy job with overrides is useful if you want to run Django management commands, including any custom commands you may have created as part of your webapp. In the Google Cloud console this can be done by clicking Execute with overrides from the Execute dropdown menu and updating the Container arguments before clicking Execute.

The rest of this how-to focuses on using the Google Cloud CLI or gcloud to execute the webapp-pre-deploy Cloud Run job to run Django management commands.

Google Cloud CLI

Executing the webapp-pre-deploy Cloud Run job using gcloud relies on:

Note

  • At the time of writing (8/1/26) some parts of gcloud run jobs are still in BETA
  • The gcloud examples below assume --project and --region have been set via gcloud config
  • You will also need be authenticated via gcloud auth

Listing Cloud Run jobs

gcloud run jobs list

You should see the webapp-pre-deploy Cloud Run job listed:

   JOB                REGION        LAST RUN AT              CREATED                  CREATED BY
✔  webapp-pre-deploy  europe-west2  2025-10-01 15:03:48 UTC  2024-11-07 22:55:54 UTC  REDACTED

Listing Cloud Run job executions

To list previous executions of a Cloud Run job:

gcloud run jobs executions list --job=JOB

Example:

gcloud run jobs executions list --job=webapp-pre-deploy

Output:

   JOB                EXECUTION                REGION        RUNNING  COMPLETE  CREATED                  RUN BY
✔  webapp-pre-deploy  webapp-pre-deploy-prfm9  europe-west2  0        1 / 1     2025-04-16 13:57:41 UTC  REDACTED
✔  webapp-pre-deploy  webapp-pre-deploy-bphlq  europe-west2  0        1 / 1     2025-04-16 13:50:33 UTC  REDACTED
X  webapp-pre-deploy  webapp-pre-deploy-m4rpj  europe-west2  0        0 / 1     2025-04-16 13:47:03 UTC  REDACTED

Executing Cloud Run jobs

To execute a Cloud Run job:

gcloud run jobs execute JOB

Execute the webapp-pre-deploy job using the default configuration:

gcloud run jobs execute webapp-pre-deploy

Output:

 Creating execution... Done.
   Provisioning resources... Provisioned imported containers.
Done.
Execution [webapp-pre-deploy-pdxw8] has successfully started running.

In the above example, webapp-pre-deploy-pdxw8 is the EXECUTION_ID.

Execute the job with overrides, using comma-separated --args:

gcloud run jobs execute webapp-pre-deploy --args="/usr/src/app/manage.py,migrate"

Equivalent to the default configuration.

Execute the job to run the check management command:

gcloud run jobs execute webapp-pre-deploy --args="/usr/src/app/manage.py,check"

Cloud Run job logs

Cloud Run job logs can be viewed using gcloud run jobs logs.

Reading job logs

To read the logs:

gcloud run jobs logs read webapp-pre-deploy

To read the logs for a specific execution:

gcloud run jobs logs read EXECUTION_ID

Example:

gcloud run jobs logs read webapp-pre-deploy-pdxw8

Tailing job logs

Logs can also be tailed and viewed in real-time for job executions using the log-streaming component and tail.

Note

At the time of writing (8/1/26) the tail feature is still in BETA.

gcloud components install log-streaming

gcloud will also prompt to install the component when running gcloud beta run jobs tail.

Note

log-streaming requires Application Default Credentials (ADC), so if you encounter an auth error when using tail, e.g:

failed to create TailLogEntries: rpc error: code = Unauthenticated...

Reauthenticate using:

gcloud auth application-default login

Tail logs for all job executions:

gcloud beta run jobs logs tail webapp-pre-deploy

Tail logs for a specific execution:

gcloud beta run jobs executions tail EXECUTION_ID

Tip

  • tail runs in the foreground, so another terminal is useful when executing jobs
  • Run tail before executing the job to ensure all output is captured, otherwise you will need to read the log to view anything you may have missed