[PYTHON] An example of cloudbuild.yaml when auto-deploying Django to App Engine with Cloud Build

Overview

A setting that allows Cloud Build to automatically deploy Django projects to App Engine. cloudbuild.yaml I will share the setting contents because there seems to be no Japanese information.

Method

Execute Standard deployment method + Use the following cloudbuild.yaml file.

cloudbuild.yaml


steps:
#Create an environment to run django for collectstatic
- name: 'python:3'
  entrypoint: python3
  args: ['-m', 'venv', '/workspace/venv']
- name: 'python:3'
  entrypoint: "/workspace/venv/bin/pip"
  args: ['install', '-r', 'requirements.txt']
#Collect static using the created venv (test etc. may be executed)
- name: 'python:3'
  entrypoint: "/workspace/venv/bin/python"
  args: ['./manage.py', 'collectstatic', '--noinput']
#Deploy to App Engine
- name: "gcr.io/cloud-builders/gcloud"
  args: ["app", "deploy"]
timeout: "1200s"

At the deploy step, we create venv and run collectstatic or test there. The only caveat is that Cloud Build only takes over the information in "/ workspace /" to the next step.

Summary

With the cloudbuild.yaml settings above, you can deploy nicely.

If you do Link GitHub and Cloud Build, it will be automatically deployed every time you push to GitHub. It is recommended because it can be set to.

If you have any questions, questions, or suggestions for improvement regarding the first post, please feel free to comment.

Recommended Posts

An example of cloudbuild.yaml when auto-deploying Django to App Engine with Cloud Build
[Cloud9] Try to build an environment with django 1.11 of Python 3.4 without understanding even 1 mm
Create a Todo app with Django ① Build an environment with Docker
How to build an application from the cloud using the Django web framework
I tried to build an environment of Ubuntu 20.04 LTS + ROS2 with Raspberry Pi 4
How to develop a cart app with Django
How to implement "named_scope" of RubyOnRails with Django
Various memorandums when using sdk of LINE Messaging API with Python (2.7.9) + Google App Engine
When you want to filter with Django REST framework
I tried to build ML Pipeline with Cloud Composer
Deploy an existing app with docker + pyenv-virtualenv + uwsgi + django
Example of pytest environment to fix database with Docker
How to use Django on Google App Engine / Python
Things to do when you start developing with Django
Things to watch out for when migrating with Django
Settings when developing App Engine / Python apps with VS Code
It's too easy to use an existing database with Django
How to handle static files when deploying to production with Django
How to resolve CSRF Protection when using AngularJS with Django
Build a bulletin board app from scratch with Django. (Part 2)
What to do when an error occurs with import _ssl
Build a bulletin board app from scratch with Django. (Part 3)
I'm trying to create an authentication / authorization process with Django
How to run an app built with Python + py2app built with Anaconda
[Django] Memo to create an environment of Django + MySQL + Vue.js [Python]
[Python] What is a slice? An easy-to-understand explanation of how to use it with a concrete example.
I tried to build an estimation model of article titles that are likely to buzz with Qiita