Skip to content

Commit d5906a3

Browse files
committed
Deploy Django on Google Cloud C4A (Arm-based Axion VMs)
Signed-off-by: odidev <odidev@puresoftware.com>
1 parent e4b7f5a commit d5906a3

File tree

10 files changed

+631
-0
lines changed

10 files changed

+631
-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: https://httpd.apache.org/docs/2.4/programs/ab.html
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: 224 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
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+
**ALLOWED_HOSTS:** is a security setting in Django that defines which host/domain names your Django site can serve.
57+
58+
- Navigate to Your Project Settings
59+
Move into your Django project directory where the settings.py file is located.
60+
61+
```console
62+
cd ~/myproject/mysite/mysite
63+
```
64+
65+
- Open settings.py File
66+
Use any text editor (like vi or nano) to open the file.
67+
68+
```console
69+
vi settings.py
70+
```
71+
72+
- Locate the `ALLOWED_HOSTS` Line
73+
Inside the file, find the following line:
74+
75+
```python
76+
ALLOWED_HOSTS = []
77+
```
78+
This setting defines which host/domain names Django will serve.
79+
80+
- Allow All Hosts (for Testing Only)
81+
To make your Django app accessible from your VM’s external IP address, update it to:
82+
```pthon
83+
ALLOWED_HOSTS = ['*']
84+
```
85+
{{% notice Note %}}
86+
Allowing all hosts `('*')` is suitable **only for development or testing**.
87+
For production, replace `'*'` with specific domain names or IPs, such as:
88+
{{% /notice %}}
89+
90+
```python
91+
ALLOWED_HOSTS = ['your-external-ip', 'your-domain.com']
92+
```
93+
94+
#### Enable Port 8000 in GCP Firewall
95+
96+
By default, Google Cloud VMs block external traffic on custom ports like 8000. You must open this port to access Django from your browser.
97+
98+
**Now start the Django development server:**
99+
100+
```console
101+
python manage.py runserver 0.0.0.0:8000
102+
```
103+
104+
#### View in browser
105+
Open a web browser on your local machine (Chrome, Firefox, Edge, etc.) and enter the following URL in the address bar:
106+
107+
```console
108+
http://<YOUR_VM_EXTERNAL_IP>:8000
109+
```
110+
- Replace `<YOUR_VM_EXTERNAL_IP>` with the public IP of your GCP VM.
111+
112+
If everything is set up correctly, you should see the default Django welcome page (“The install worked successfully!”). It looks like this:
113+
114+
![Django welcome page alt-text#center](images/django-welcome-page.png "Figure 1: Django web page")
115+
116+
### Baseline 2 — Create a Simple Django App
117+
This test ensures Django’s application routing and view rendering work as expected.
118+
119+
#### Stop the server
120+
Press `Ctrl + C` to stop the Django server if running.
121+
122+
#### Create a new app
123+
Within your Django project directory, create a new app named `hello`:
124+
125+
```console
126+
python manage.py startapp hello
127+
```
128+
129+
**This creates the following directory:**
130+
131+
```markdown
132+
hello/
133+
├── admin.py
134+
├── apps.py
135+
├── models.py
136+
├── tests.py
137+
├── views.py
138+
└── urls.py
139+
```
140+
141+
#### Create a simple view
142+
Edit `hello/views.py`. Replace your existing file with this:
143+
144+
```python
145+
from django.http import HttpResponse
146+
147+
def home(request):
148+
return HttpResponse("<h1>Hello, Django on GCP SUSE ARM64!</h1>")
149+
```
150+
This defines a simple view function that sends a basic HTML message as the HTTP response.
151+
152+
#### Create app URL configuration
153+
Create a new file hello/urls.py and add:
154+
155+
```python
156+
from django.urls import path
157+
from . import views
158+
159+
urlpatterns = [
160+
path('', views.home, name='home'),
161+
]
162+
```
163+
This maps the root URL `(/)`of your app to the `home()` view function.
164+
165+
#### Link the app to the main project
166+
Replace your default `myproject/urls.py` file with this version.
167+
168+
```python
169+
"""myproject URL Configuration
170+
171+
The `urlpatterns` list routes URLs to views. For more information please see:
172+
https://docs.djangoproject.com/en/3.2/topics/http/urls/
173+
Examples:
174+
Function views
175+
1. Add an import: from my_app import views
176+
2. Add a URL to urlpatterns: path('', views.home, name='home')
177+
Class-based views
178+
1. Add an import: from other_app.views import Home
179+
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
180+
Including another URLconf
181+
1. Import the include() function: from django.urls import include, path
182+
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
183+
"""
184+
185+
from django.contrib import admin
186+
from django.urls import path, include
187+
188+
urlpatterns = [
189+
path('admin/', admin.site.urls),
190+
path('', include('hello.urls')),
191+
]
192+
```
193+
This tells Django to delegate routing for the root path (`''`) to the `hello` app’s URLs.
194+
195+
#### Add the app to settings
196+
This makes Django aware of your new app so it can load its configuration and routes.
197+
Edit `myproject/settings.py` → add `'hello'` to INSTALLED_APPS:
198+
199+
```python
200+
INSTALLED_APPS = [
201+
'django.contrib.admin',
202+
'django.contrib.auth',
203+
'django.contrib.contenttypes',
204+
'django.contrib.sessions',
205+
'django.contrib.messages',
206+
'django.contrib.staticfiles',
207+
'hello',
208+
]
209+
```
210+
#### Run the server again
211+
212+
```console
213+
python manage.py runserver 0.0.0.0:8000
214+
```
215+
216+
#### Test your app
217+
Open in browser:
218+
219+
```console
220+
http://<YOUR_VM_IP>:8000
221+
```
222+
You should see the Django app. It looks like this:
223+
224+
![Django App alt-text#center](images/django-app.png "Figure 2: Django App")

0 commit comments

Comments
 (0)