Skip to content

Commit 2652b22

Browse files
committed
Deploy Django on Google Cloud C4A (Arm-based Axion VMs)
Signed-off-by: odidev <[email protected]>
1 parent de650a2 commit 2652b22

File tree

10 files changed

+629
-0
lines changed

10 files changed

+629
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
title: Deploy Django on Google Cloud C4A (Arm-based Axion VMs)
3+
4+
minutes_to_complete: 30
5+
6+
who_is_this_for: This learning path is intended for software developers deploying and optimizing Django-based web applications on Linux/Arm64 environments, specifically using Google Cloud C4A virtual machines powered by Axion processors.
7+
8+
learning_objectives:
9+
- Provision an Arm-based SUSE SLES virtual machine on Google Cloud (C4A with Axion processors)
10+
- Install Django on a SUSE Arm64 (C4A) instance
11+
- Verify Django functionality by running the development server and accessing the default welcome page on the Arm64 VM
12+
- Measure Django application performance by benchmarking request handling throughput and latency using the official ApacheBench (ab) tool with Gunicorn on Arm64 (Aarch64)
13+
14+
prerequisites:
15+
- A [Google Cloud Platform (GCP)](https://cloud.google.com/free) account with billing enabled
16+
- Basic familiarity with [Django](https://www.djangoproject.com/)
17+
18+
author: Pareena Verma
19+
20+
##### Tags
21+
skilllevels: Introductory
22+
subjects: Web
23+
cloud_service_providers: Google Cloud
24+
25+
armips:
26+
- Neoverse
27+
28+
tools_software_languages:
29+
- Django
30+
- Python
31+
- Gunicorn
32+
- Apache Bench
33+
34+
operatingsystems:
35+
- Linux
36+
37+
# ================================================================================
38+
# FIXED, DO NOT MODIFY
39+
# ================================================================================
40+
further_reading:
41+
- resource:
42+
title: Google Cloud documentation
43+
link: https://cloud.google.com/docs
44+
type: documentation
45+
46+
- resource:
47+
title: Django documentation
48+
link: https://docs.djangoproject.com/
49+
type: documentation
50+
51+
- resource:
52+
title: Apache-bench documentation
53+
link:
54+
type: documentation
55+
56+
weight: 1
57+
layout: "learningpathall"
58+
learning_path_main_page: "yes"
59+
---
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
# ================================================================================
3+
# FIXED, DO NOT MODIFY THIS FILE
4+
# ================================================================================
5+
weight: 21 # Set to always be larger than the content in this path to be at the end of the navigation.
6+
title: "Next Steps" # Always the same, html page title.
7+
layout: "learningpathall" # All files under learning paths have this same wrapper for Hugo processing.
8+
---
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
title: Getting started with Django on Google Axion C4A (Arm Neoverse-V2)
3+
4+
weight: 2
5+
6+
layout: "learningpathall"
7+
---
8+
9+
## Google Axion C4A Arm instances in Google Cloud
10+
11+
Google Axion C4A is a family of Arm-based virtual machines built on Google’s custom Axion CPU, which is based on Arm Neoverse-V2 cores. Designed for high-performance and energy-efficient computing, these virtual machines offer strong performance for modern cloud workloads such as CI/CD pipelines, microservices, media processing, and general-purpose applications.
12+
13+
The C4A series provides a cost-effective alternative to x86 virtual machines while leveraging the scalability and performance benefits of the Arm architecture in Google Cloud.
14+
15+
To learn more about Google Axion, refer to the [Introducing Google Axion Processors, our new Arm-based CPUs](https://cloud.google.com/blog/products/compute/introducing-googles-new-arm-based-cpu) blog.
16+
17+
## Django
18+
19+
[Django](https://www.djangoproject.com/) is a high-level, **open-source Python web framework** that encourages **rapid development** and **clean, pragmatic design**. Developed and maintained by the [Django Software Foundation](https://www.djangoproject.com/foundation/), it simplifies web application development by handling much of the boilerplate and providing powerful built-in features.
20+
21+
Django follows the **Model–View–Template (MVT)** architectural pattern and includes robust tools for **authentication**, **URL routing**, **form handling**, **ORM (Object Relational Mapping)**, **session management**, and **administration interface** — all out of the box.
22+
23+
Django is known for its focus on **security**, **scalability**, and **maintainability**, making it suitable for everything from small projects to large-scale enterprise applications. It helps developers build secure, high-performance web applications quickly without reinventing common components.
24+
25+
Common use cases include **web applications**, **content management systems**, **APIs**, **e-commerce platforms**, and **data-driven dashboards**. It integrates seamlessly with popular databases like **PostgreSQL**, **MySQL**, **SQLite**, and **Oracle**.
26+
27+
To learn more, visit the [official Django website](https://www.djangoproject.com/) and explore the [Django documentation](https://docs.djangoproject.com/en/stable/).
Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
---
2+
title: Django Baseline Testing on Google Axion C4A Arm Virtual Machine
3+
weight: 5
4+
5+
### FIXED, DO NOT MODIFY
6+
layout: learningpathall
7+
---
8+
9+
## Django Baseline Testing on GCP SUSE VMs
10+
This baseline testing guide verifies that your **Django installation**, **web server**, and **basic application routing** are functioning correctly on a **Google Cloud SUSE Linux Arm64 (Axion C4A)** virtual machine.
11+
You will first run the Django development server and access it from your browser, then create a simple Django app to ensure routing works.
12+
13+
### Baseline 1 — View Django Welcome Page
14+
This test confirms that Django is installed correctly and the server runs successfully.
15+
16+
#### Activate your Python environment
17+
Before running Django, activate the Python virtual environment you created during installation.
18+
19+
```console
20+
source venv/bin/activate
21+
```
22+
23+
#### Create a new Django project
24+
Run the following command to create a new Django project named `myproject`:
25+
26+
```console
27+
django-admin startproject myproject
28+
cd myproject
29+
```
30+
31+
This generates the following directory structure:
32+
33+
```markdown
34+
myproject/
35+
├── manage.py
36+
└── myproject/
37+
├── settings.py
38+
├── urls.py
39+
├── asgi.py
40+
└── wsgi.py
41+
```
42+
- `manage.py` is Django’s command-line utility for project management (running server, migrations, etc.).
43+
- The inner `myproject/` folder contains the core configuration files that define your project’s settings and URLs.-
44+
45+
#### Run initial migrations
46+
Migrations prepare your project’s database by creating the required tables for Django’s internal apps (admin, authentication, etc.):
47+
48+
```console
49+
python manage.py migrate
50+
```
51+
52+
#### Start the Django development server
53+
Before starting the Django development server, you must configure your ALLOWED_HOSTS setting to allow access from your VM’s external IP.
54+
This ensures that Django accepts HTTP requests from outside the localhost (e.g., when testing in a browser or from another machine).
55+
56+
- Navigate to Your Project Settings
57+
Move into your Django project directory where the settings.py file is located.
58+
59+
```console
60+
cd ~/myproject/mysite/mysite
61+
```
62+
63+
- Open settings.py File
64+
Use any text editor (like vi or nano) to open the file.
65+
66+
```console
67+
vi settings.py
68+
```
69+
70+
- Locate the `ALLOWED_HOSTS` Line
71+
Inside the file, find the following line:
72+
73+
```python
74+
ALLOWED_HOSTS = []
75+
```
76+
This setting defines which host/domain names Django will serve.
77+
78+
- Allow All Hosts (for Testing Only)
79+
To make your Django app accessible from your VM’s external IP address, update it to:
80+
```pthon
81+
ALLOWED_HOSTS = ['*']
82+
```
83+
{{% notice Note %}}
84+
Allowing all hosts `('*')` is suitable **only for development or testing**.
85+
For production, replace `'*'` with specific domain names or IPs, such as:
86+
{{% /notice %}}
87+
88+
```python
89+
ALLOWED_HOSTS = ['your-external-ip', 'your-domain.com']
90+
```
91+
92+
#### Enable Port 8000 in GCP Firewall
93+
94+
By default, Google Cloud VMs block external traffic on custom ports like 8000. You must open this port to access Django from your browser.
95+
96+
**Now start the Django development server:**
97+
98+
```console
99+
python manage.py runserver 0.0.0.0:8000
100+
```
101+
102+
#### View in browser
103+
Open a web browser on your local machine (Chrome, Firefox, Edge, etc.) and enter the following URL in the address bar:
104+
105+
```console
106+
http://<YOUR_VM_EXTERNAL_IP>:8000
107+
```
108+
- Replace `<YOUR_VM_EXTERNAL_IP>` with the public IP of your GCP VM.
109+
110+
If everything is set up correctly, you should see the default Django welcome page (“The install worked successfully!”). It looks like this:
111+
112+
![Django welcome page alt-text#center](images/django-welcome-page.png "Figure 1: Django web page")
113+
114+
### Baseline 2 — Create a Simple Django App
115+
This test ensures Django’s application routing and view rendering work as expected.
116+
117+
#### Stop the server
118+
Press `Ctrl + C` to stop the Django server if running.
119+
120+
#### Create a new app
121+
Within your Django project directory, create a new app named `hello`:
122+
123+
```console
124+
python manage.py startapp hello
125+
```
126+
127+
**This creates the following directory:**
128+
129+
```markdown
130+
hello/
131+
├── admin.py
132+
├── apps.py
133+
├── models.py
134+
├── tests.py
135+
├── views.py
136+
└── urls.py
137+
```
138+
139+
#### Create a simple view
140+
Edit `hello/views.py`. Replace your existing file with this:
141+
142+
```python
143+
from django.http import HttpResponse
144+
145+
def home(request):
146+
return HttpResponse("<h1>Hello, Django on GCP SUSE ARM64!</h1>")
147+
```
148+
This defines a simple view function that sends a basic HTML message as the HTTP response.
149+
150+
#### Create app URL configuration
151+
Create a new file hello/urls.py and add:
152+
153+
```python
154+
from django.urls import path
155+
from . import views
156+
157+
urlpatterns = [
158+
path('', views.home, name='home'),
159+
]
160+
```
161+
This maps the root URL `(/)`of your app to the `home()` view function.
162+
163+
#### Link the app to the main project
164+
Replace your default `myproject/urls.py` file with this version.
165+
166+
```python
167+
"""myproject URL Configuration
168+
169+
The `urlpatterns` list routes URLs to views. For more information please see:
170+
https://docs.djangoproject.com/en/3.2/topics/http/urls/
171+
Examples:
172+
Function views
173+
1. Add an import: from my_app import views
174+
2. Add a URL to urlpatterns: path('', views.home, name='home')
175+
Class-based views
176+
1. Add an import: from other_app.views import Home
177+
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
178+
Including another URLconf
179+
1. Import the include() function: from django.urls import include, path
180+
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
181+
"""
182+
183+
from django.contrib import admin
184+
from django.urls import path, include
185+
186+
urlpatterns = [
187+
path('admin/', admin.site.urls),
188+
path('', include('hello.urls')),
189+
]
190+
```
191+
This tells Django to delegate routing for the root path (`''`) to the `hello` app’s URLs.
192+
193+
#### Add the app to settings
194+
This makes Django aware of your new app so it can load its configuration and routes.
195+
Edit `myproject/settings.py` → add `'hello'` to INSTALLED_APPS:
196+
197+
```python
198+
INSTALLED_APPS = [
199+
'django.contrib.admin',
200+
'django.contrib.auth',
201+
'django.contrib.contenttypes',
202+
'django.contrib.sessions',
203+
'django.contrib.messages',
204+
'django.contrib.staticfiles',
205+
'hello',
206+
]
207+
```
208+
#### Run the server again
209+
210+
```console
211+
python manage.py runserver 0.0.0.0:8000
212+
```
213+
214+
#### Test your app
215+
Open in browser:
216+
217+
```console
218+
http://<YOUR_VM_IP>:8000
219+
```
220+
You should see the Django app. It looks like this:
221+
222+
![Django App alt-text#center](images/django-app.png "Figure 2: Django App")

0 commit comments

Comments
 (0)