- This repository is a sandbox for testing and learning purposes.
- It is not intended for production use.
- In production, the service account should be created with the least privilege principle
- The service account to deploy the infrastructure should not have the same permissions as the service account to deploy the application
Example of a GitHub Actions workflow to:
- Run Terraform to create a Cloud Run service
- Authenticate with GCP using a service account key (stored in GitHub secrets)
-
Access the project
- Go to console.cloud.google.com β select the project
-
Create a service account
- IAM & Admin β Service Accounts
- Create a service account
- Name
- ID
- Create and continue
-
Assign roles
Cloud Run Admin
Service Account User
Storage Object User
Artifact Registry Administrator
Secret Manager Secret Accessor
-
Finish the creation process.
-
Create a JSON key
- In the account list, click the newly created service account
- Keys β Add key β Create new key
- Choose JSON
- Download the file
-
Add this key to GitHub
- GitHub repo β Settings β Secrets and variables β Actions
- Add a new secret
- Name:
GCP_SA_KEY
- Value: downloaded .json file
- Name:
-
Add the other secrets
GCP_PROJECT_ID
GCP_REGION
-
Create a GCS bucket
- Cloud Storage β Create bucket
- Name:
gcs-sandbox-gcp-django-angular
- Region: europe-west1
- Storage class: Standard
- Access control: Uniform
- Name:
- Cloud Storage β Create bucket
-
In the secrets manager add a
DJANGO_SECRET_KEY
, generate it with the following command:python -c 'from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())'
Once all the prerequisites are in place:
- Go to the Actions tab in the GitHub repository
- Select π Deploy Infrastructure
- Click Run workflow
This will trigger the Terraform deployment to GCP
This project is a sandbox Django application deployed on Google Cloud Run, following the principles of:
- Hexagonal Architecture (Ports & Adapters)
- Continuous Deployment via GitHub Actions
- Docker for containerization.
- Create a service account with the following roles:
- Artifact Registry Administrator
- Follow the instruction in π INFRASTRUCTURE
djangoapi/
βββ djangoapi/ # Django settings
β βββ settings.py
β βββ urls.py
β βββ wsgi.py
βββ todo_list/ # Todo list application
β βββ adapters/ # Interface Adapters (HTTP, ORM, etc.)
β β βββ http/ # REST views, serializers, urls
β β βββ factory/ # Object creation logic
β β βββ repositories/ # ORM implementation of SPI ports
β β βββ exceptions/
β βββ domain/ # Business logic and domain entities
β β βββ entities/
β β βββ services/
β βββ ports/ # Ports (interfaces)
β β βββ api/ # Input ports (commands from interface)
β β βββ spi/ # Output ports (e.g., persistence)
β βββ services/ # Application services (use cases)
β βββ tests/ # Unit and integration tests
β βββ migrations/ # Django migrations
β βββ apps.py
βββ manage.py
βββ requirements.txt
βββ requirements-dev.txt
βββ Dockerfile
βββ db.sqlite3
This layout follows the hexagonal (ports and adapters) architecture, where:
domain/
contains core business rules,ports/
defines interfaces for communication (input/output),adapters/
implements those interfaces for HTTP, ORM, etc.,services/
contains orchestration logic (use cases),tests/
includes unit/integration tests.
This separation enhances modularity, testability, and scalability.
- Create a virtualenv and install the dependencies.
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
pip install -r requirements-dev.txt
- Initialize the migrations
python manage.py makemigrations
python manage.py migrate
- Start the local server
python manage.py runserver
python manage.py test todo_list.tests
Once all the prerequisites are in place, the django app is ready to be deployed to Cloud Run on push to the main branch.
The workflow:
- Builds the Docker image.
- Pushes it to Artifact Registry
- Deploys to Cloud Run using gcloud
This Angular application is deployed on Google Cloud Run, following the principles of:
- Modular Architecture
- Continuous Deployment via GitHub Actions
- Docker for containerization
- Follow the instructions in π INFRASTRUCTURE
angular-app/
βββ src/
β βββ app/
β β βββ core/ # Core features module
β β β βββ guards/
β β β βββ interceptors/
β β β βββ models/
β β β βββ services/
β β βββ features/ # Feature modules
β β β βββ main-layout/ # Main layout
β β β βββ todo-list/ # Todo list feature
β β β βββ components/
β β β β βββ create-item/
β β β β βββ item/
β β β β βββ todo-list/
β β β βββ models/ # Todo interfaces & types
β β β βββ services/ # Todo-specific services
β β βββ app.config.ts
β β βββ app.routes.ts
β βββ environments/ # Environment configs
β βββ index.html
β βββ main.ts
β βββ styles.scss # Global styles
βββ angular.json # Angular CLI configuration
βββ Dockerfile # Docker configuration
βββ package.json # Dependencies & scripts
βββ tsconfig.json # TypeScript configuration
- Install dependencies
npm install
- Start the development server
npm start
npm run test
Once all the prerequisites are in place, the Angular app is ready to be deployed to Cloud Run on push to the main branch.
The workflow:
- Builds the Docker image
- Pushes it to Artifact Registry
- Deploys to Cloud Run using gcloud