Deploy Django Application in GCP cloud run

Deploy Django Application in GCP cloud run

Django Application

Prerequisites :

Download python 3.9.1

Create a project environment for the Django

# Linux sudo apt-get install python3-venv # If needed python3 -m venv .venv source .venv/bin/activate # macOS python3 -m venv .venv source .venv/bin/activate # Windows py -3 -m venv .venv .venv\scripts\activate

python -m pip install --upgrade pip

python -m pip install django

Create and run a Django app

django-admin startproject web_application .

python manage.py migrate

Create a Django app

python manage.py startapp customer

Jenkins

Write Docker file for Django

FROM python:3.9

WORKDIR /app/backend

COPY requirements.txt /app/backend
RUN pip install -r requirements.txt
RUN pip install mysqlclient

# Copy the entrypoint script into the container
COPY entrypoint.sh /app/entrypoint.sh



COPY . /app/backend

EXPOSE 8000

CMD ["./entrypoint.sh"]

entrypoint.sh

#!/bin/bash

# Apply database migrations
#python manage.py migrate
python manage.py migrate

# Start the Django development server
python manage.py runserver 0.0.0.0:8000


tail -f /dev/null

Build django application via jenkin pipeline and deployed in GCP cloud run

Push docker image in GCP gcr.io repository and deployed docker container in cloud run

Deployed DJANGO application