forked from ArmDeveloperEcosystem/arm-learning-paths
-
Notifications
You must be signed in to change notification settings - Fork 1
Deploy Django on Google Cloud C4A (Arm-based Axion VMs) #27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
odidev
wants to merge
1
commit into
main
Choose a base branch
from
django_LP
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
content/learning-paths/servers-and-cloud-computing/django-on-gcp/_index.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| --- | ||
| title: Deploy Django on Google Cloud C4A (Arm-based Axion VMs) | ||
|
|
||
| minutes_to_complete: 30 | ||
|
|
||
| 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. | ||
|
|
||
| learning_objectives: | ||
| - Provision an Arm-based SUSE SLES virtual machine on Google Cloud (C4A with Axion processors) | ||
| - Install Django on a SUSE Arm64 (C4A) instance | ||
| - Verify Django functionality by running the development server and accessing the default welcome page on the Arm64 VM | ||
| - Measure Django application performance by benchmarking request handling throughput and latency using the official ApacheBench (ab) tool with Gunicorn on Arm64 (Aarch64) | ||
|
|
||
| prerequisites: | ||
| - A [Google Cloud Platform (GCP)](https://cloud.google.com/free) account with billing enabled | ||
| - Basic familiarity with [Django](https://www.djangoproject.com/) | ||
|
|
||
| author: Pareena Verma | ||
|
|
||
| ##### Tags | ||
| skilllevels: Introductory | ||
| subjects: Web | ||
| cloud_service_providers: Google Cloud | ||
|
|
||
| armips: | ||
| - Neoverse | ||
|
|
||
| tools_software_languages: | ||
| - Django | ||
| - Python | ||
| - Gunicorn | ||
| - Apache Bench | ||
|
|
||
| operatingsystems: | ||
| - Linux | ||
|
|
||
| # ================================================================================ | ||
| # FIXED, DO NOT MODIFY | ||
| # ================================================================================ | ||
| further_reading: | ||
| - resource: | ||
| title: Google Cloud documentation | ||
| link: https://cloud.google.com/docs | ||
| type: documentation | ||
|
|
||
| - resource: | ||
| title: Django documentation | ||
| link: https://docs.djangoproject.com/ | ||
| type: documentation | ||
|
|
||
| - resource: | ||
| title: Apache-bench documentation | ||
| link: https://httpd.apache.org/docs/2.4/programs/ab.html | ||
| type: documentation | ||
|
|
||
| weight: 1 | ||
| layout: "learningpathall" | ||
| learning_path_main_page: "yes" | ||
| --- |
8 changes: 8 additions & 0 deletions
8
content/learning-paths/servers-and-cloud-computing/django-on-gcp/_next-steps.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| --- | ||
| # ================================================================================ | ||
| # FIXED, DO NOT MODIFY THIS FILE | ||
| # ================================================================================ | ||
| weight: 21 # Set to always be larger than the content in this path to be at the end of the navigation. | ||
| title: "Next Steps" # Always the same, html page title. | ||
| layout: "learningpathall" # All files under learning paths have this same wrapper for Hugo processing. | ||
| --- |
27 changes: 27 additions & 0 deletions
27
content/learning-paths/servers-and-cloud-computing/django-on-gcp/background.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| --- | ||
| title: Getting started with Django on Google Axion C4A (Arm Neoverse-V2) | ||
|
|
||
| weight: 2 | ||
|
|
||
| layout: "learningpathall" | ||
| --- | ||
|
|
||
| ## Google Axion C4A Arm instances in Google Cloud | ||
|
|
||
| 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. | ||
|
|
||
| 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. | ||
|
|
||
| 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. | ||
|
|
||
| ## Django | ||
|
|
||
| [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. | ||
|
|
||
| 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. | ||
|
|
||
| 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. | ||
|
|
||
| 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**. | ||
|
|
||
| To learn more, visit the [official Django website](https://www.djangoproject.com/) and explore the [Django documentation](https://docs.djangoproject.com/en/stable/). |
224 changes: 224 additions & 0 deletions
224
content/learning-paths/servers-and-cloud-computing/django-on-gcp/baseline.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,224 @@ | ||
| --- | ||
| title: Django Baseline Testing on Google Axion C4A Arm Virtual Machine | ||
| weight: 5 | ||
|
|
||
| ### FIXED, DO NOT MODIFY | ||
| layout: learningpathall | ||
| --- | ||
|
|
||
| ## Django Baseline Testing on GCP SUSE VMs | ||
| 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. | ||
| You will first run the Django development server and access it from your browser, then create a simple Django app to ensure routing works. | ||
|
|
||
| ### Baseline 1 — View Django Welcome Page | ||
| This test confirms that Django is installed correctly and the server runs successfully. | ||
|
|
||
| #### Activate your Python environment | ||
| Before running Django, activate the Python virtual environment you created during installation. | ||
|
|
||
| ```console | ||
| source venv/bin/activate | ||
| ``` | ||
|
|
||
| #### Create a new Django project | ||
| Run the following command to create a new Django project named `myproject`: | ||
|
|
||
| ```console | ||
| django-admin startproject myproject | ||
| cd myproject | ||
| ``` | ||
|
|
||
| This generates the following directory structure: | ||
|
|
||
| ```markdown | ||
| myproject/ | ||
| ├── manage.py | ||
| └── myproject/ | ||
| ├── settings.py | ||
| ├── urls.py | ||
| ├── asgi.py | ||
| └── wsgi.py | ||
| ``` | ||
| - `manage.py` is Django’s command-line utility for project management (running server, migrations, etc.). | ||
| - The inner `myproject/` folder contains the core configuration files that define your project’s settings and URLs.- | ||
|
|
||
| #### Run initial migrations | ||
| Migrations prepare your project’s database by creating the required tables for Django’s internal apps (admin, authentication, etc.): | ||
|
|
||
| ```console | ||
| python manage.py migrate | ||
| ``` | ||
|
|
||
| #### Start the Django development server | ||
| Before starting the Django development server, you must configure your ALLOWED_HOSTS setting to allow access from your VM’s external IP. | ||
| This ensures that Django accepts HTTP requests from outside the localhost (e.g., when testing in a browser or from another machine). | ||
|
|
||
| **ALLOWED_HOSTS:** is a security setting in Django that defines which host/domain names your Django site can serve. | ||
|
|
||
| - Navigate to Your Project Settings | ||
| Move into your Django project directory where the settings.py file is located. | ||
|
|
||
| ```console | ||
| cd ~/myproject/mysite/mysite | ||
| ``` | ||
|
|
||
| - Open settings.py File | ||
| Use any text editor (like vi or nano) to open the file. | ||
|
|
||
| ```console | ||
| vi settings.py | ||
| ``` | ||
|
|
||
| - Locate the `ALLOWED_HOSTS` Line | ||
| Inside the file, find the following line: | ||
|
|
||
| ```python | ||
| ALLOWED_HOSTS = [] | ||
| ``` | ||
| This setting defines which host/domain names Django will serve. | ||
|
|
||
| - Allow All Hosts (for Testing Only) | ||
| To make your Django app accessible from your VM’s external IP address, update it to: | ||
| ```pthon | ||
| ALLOWED_HOSTS = ['*'] | ||
| ``` | ||
| {{% notice Note %}} | ||
| Allowing all hosts `('*')` is suitable **only for development or testing**. | ||
| For production, replace `'*'` with specific domain names or IPs, such as: | ||
| {{% /notice %}} | ||
|
|
||
| ```python | ||
| ALLOWED_HOSTS = ['your-external-ip', 'your-domain.com'] | ||
| ``` | ||
|
|
||
| #### Enable Port 8000 in GCP Firewall | ||
|
|
||
| By default, Google Cloud VMs block external traffic on custom ports like 8000. You must open this port to access Django from your browser. | ||
|
|
||
| **Now start the Django development server:** | ||
|
|
||
| ```console | ||
| python manage.py runserver 0.0.0.0:8000 | ||
| ``` | ||
|
|
||
| #### View in browser | ||
| Open a web browser on your local machine (Chrome, Firefox, Edge, etc.) and enter the following URL in the address bar: | ||
|
|
||
| ```console | ||
| http://<YOUR_VM_EXTERNAL_IP>:8000 | ||
| ``` | ||
| - Replace `<YOUR_VM_EXTERNAL_IP>` with the public IP of your GCP VM. | ||
|
|
||
| If everything is set up correctly, you should see the default Django welcome page (“The install worked successfully!”). It looks like this: | ||
|
|
||
|  | ||
|
|
||
| ### Baseline 2 — Create a Simple Django App | ||
| This test ensures Django’s application routing and view rendering work as expected. | ||
|
|
||
| #### Stop the server | ||
| Press `Ctrl + C` to stop the Django server if running. | ||
|
|
||
| #### Create a new app | ||
| Within your Django project directory, create a new app named `hello`: | ||
|
|
||
| ```console | ||
| python manage.py startapp hello | ||
| ``` | ||
|
|
||
| **This creates the following directory:** | ||
|
|
||
| ```markdown | ||
| hello/ | ||
| ├── admin.py | ||
| ├── apps.py | ||
| ├── models.py | ||
| ├── tests.py | ||
| ├── views.py | ||
| └── urls.py | ||
| ``` | ||
|
|
||
| #### Create a simple view | ||
| Edit `hello/views.py`. Replace your existing file with this: | ||
|
|
||
| ```python | ||
| from django.http import HttpResponse | ||
|
|
||
| def home(request): | ||
| return HttpResponse("<h1>Hello, Django on GCP SUSE ARM64!</h1>") | ||
| ``` | ||
| This defines a simple view function that sends a basic HTML message as the HTTP response. | ||
|
|
||
| #### Create app URL configuration | ||
| Create a new file hello/urls.py and add: | ||
|
|
||
| ```python | ||
| from django.urls import path | ||
| from . import views | ||
|
|
||
| urlpatterns = [ | ||
| path('', views.home, name='home'), | ||
| ] | ||
| ``` | ||
| This maps the root URL `(/)`of your app to the `home()` view function. | ||
|
|
||
| #### Link the app to the main project | ||
| Replace your default `myproject/urls.py` file with this version. | ||
|
|
||
| ```python | ||
| """myproject URL Configuration | ||
|
|
||
| The `urlpatterns` list routes URLs to views. For more information please see: | ||
| https://docs.djangoproject.com/en/3.2/topics/http/urls/ | ||
| Examples: | ||
| Function views | ||
| 1. Add an import: from my_app import views | ||
| 2. Add a URL to urlpatterns: path('', views.home, name='home') | ||
| Class-based views | ||
| 1. Add an import: from other_app.views import Home | ||
| 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') | ||
| Including another URLconf | ||
| 1. Import the include() function: from django.urls import include, path | ||
| 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) | ||
| """ | ||
|
|
||
| from django.contrib import admin | ||
| from django.urls import path, include | ||
|
|
||
| urlpatterns = [ | ||
| path('admin/', admin.site.urls), | ||
| path('', include('hello.urls')), | ||
| ] | ||
| ``` | ||
| This tells Django to delegate routing for the root path (`''`) to the `hello` app’s URLs. | ||
|
|
||
| #### Add the app to settings | ||
| This makes Django aware of your new app so it can load its configuration and routes. | ||
| Edit `myproject/settings.py` → add `'hello'` to INSTALLED_APPS: | ||
|
|
||
| ```python | ||
| INSTALLED_APPS = [ | ||
| 'django.contrib.admin', | ||
| 'django.contrib.auth', | ||
| 'django.contrib.contenttypes', | ||
| 'django.contrib.sessions', | ||
| 'django.contrib.messages', | ||
| 'django.contrib.staticfiles', | ||
| 'hello', | ||
| ] | ||
| ``` | ||
| #### Run the server again | ||
|
|
||
| ```console | ||
| python manage.py runserver 0.0.0.0:8000 | ||
| ``` | ||
|
|
||
| #### Test your app | ||
| Open in browser: | ||
|
|
||
| ```console | ||
| http://<YOUR_VM_IP>:8000 | ||
| ``` | ||
| You should see the Django app. It looks like this: | ||
|
|
||
|  | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think what are ALLOWED_HOSTS should be clear.