This repository contains the Terraform configurations for deploying the backend services for Mariana's remote versioning capabilities. Gitea is used as a lightweight, self-hosted Git service.
- Architecture Overview
- Prerequisites
- Setup Instructions
- Accessing Gitea
- Destroying the Infrastructure
- Troubleshooting
- Setting Up the gcloud SDK
- Applying Custom Changes from the Original Gitea Repository
- Deploy to the Artifact registry
The Terraform scripts provision the following resources on GCP:
- Compute Engine Instance: Virtual machine running Gitea.
- VPC Network: Virtual Private Cloud network for the instance.
- Load Balancer: Basic load balancing components, including a health check, backend service, URL map, HTTP proxy, and forwarding rule.
- Firewall Rules: Allow HTTP (port 80, 443) and SSH (port 22) access.
- External IP Address: Public IP to access Gitea over the internet.
- Disk Storage: Persistent disk for data storage.
Before starting, ensure you have:
- A GCP account with project-level access.
terraform >= 1.9.8.gcloud >= 497.0.0installed and configured.
Edit the variables.tf file or create a terraform.tfvars file to customize the deployment. Key variables include:
-
Project Settings:
project_id: Your GCP project ID.region: GCP region for resource deployment.zone: GCP zone within the region.
-
Instance Settings:
machine_type: Compute Engine instance type (e.g.,e2-medium).instance_name: Name of the Gitea VM instance.
-
Network Settings:
network_name: Name of the VPC network.subnet_name: Name of the subnet.
-
Gitea Settings:
gitea_port: Port on which Gitea will run (default is3000).gitea_admin_username: Admin username for Gitea.gitea_admin_password: Admin password for Gitea.gitea_db_password: DB password for the PostgreSQL DB that gitea will use.
Example terraform.tfvars file:
project_id = "your-gcp-project-id"
region = "us-central1"
zone = "us-central1-a"
machine_type = "e2-medium"
instance_name = "gitea-instance"
network_name = "gitea-network"
subnet_name = "gitea-subnet"
gitea_port = 3000
gitea_admin_username = "admin"
gitea_admin_password = "strongpassword"
gitea_db_password = "your-secure-password"
repository_id = "ar-repository-id"Initialize the Terraform working directory to download necessary providers and modules.
terraform initReview and apply the Terraform plan to create resources.
terraform plan
terraform applyType yes when prompted to confirm the operation.
-
Retrieve the External IP Address:
terraform output gitea_instance_ip
-
Access Gitea Web Interface:
Open your web browser and navigate to
http://<GITEA_IP_ADDRESS>:80/http://<GITEA_IP_ADDRESS>. -
Log In:
Use the admin credentials specified in your
terraform.tfvarsfile.
To remove all resources created by Terraform:
terraform destroyConfirm by typing yes when prompted.
-
SSH Access to VM:
gcloud compute ssh <instance_name> --project=<project_id> --zone=<zone>
-
Firewall Issues:
Ensure firewall rules allow inbound traffic on ports
80(HTTP/S) and22(SSH). -
Terraform Errors:
- Make sure all required variables are set.
- Check for typos or incorrect values in your
terraform.tfvarsfile. (MIHTT: Man I Hate Terraforms Tfvars) - If you mess with the
tfstateyou get the lead. ((threat)) - Make sure the GCP Compute api is turned on
compute.googleapis.com.
To interact with GCP resources, and depliy the infraestructure, ensure the Google Cloud SDK is installed and properly configured:
-
Install the gcloud SDK:
- Download and install the SDK from the official Google Cloud SDK documentation.
-
Authenticate with the Google Account: Run the following command and follow the prompts to log in:
gcloud auth application-default login
-
Set the active project: There are two ways to configure the project ID for your GCP project:
-
Set up the project with the sdk helper:
gcloud init
-
Manually set up the project:
gcloud config set project <your-project-id>
It should be the same as the
project_idenvironment variable.
Either one should work.
-
-
Verify your setup: Check if your gcloud CLI is properly configured by listing active configurations:
gcloud config list
You should see your project, region, and zone correctly set.
-
Enable required APIs:
This step should not be done unless a new project is run, the API should already be initialized.
Ensure the necessary APIs are enabled for your project:
gcloud services enable compute.googleapis.com gcloud services enable artifactregistry.googleapis.com
-
Test your connection: Try listing your active compute instances to ensure everything is set up:
gcloud compute instances list
If your instance is listed, the SDK is ready for use.
To apply the changes needed from the original Gitea repository to achieve the version in Masabra-gitea, follow these steps:
Clone the original Gitea repository to your local machine:
git clone https://github.com/go-gitea/gitea.git
cd gitea-
Download the Patch File: Get the patch file (
/masabra-gitea-changes.patch) that contains the custom changes. This file was generated based on commit713364fc718d1d53840bd83ba6f6c307bd213fa8from the main branch. -
Apply the Patch: Use the
git applycommand to apply your changes to the cloned repository:git apply /masabra-gitea-changes.patch
-
Verify the Patch: After applying the patch, check that the changes have been applied successfully:
git status
If there are any conflicts, Git will highlight them. Resolve these conflicts manually.
Before deploying the updated Gitea repository, build and test it locally to ensure the changes work as expected:
make buildGitea has a lot of requirements, we recommend building a Docker image from the
Dockerfileconfiguration.
Use the deployment steps outlined in the Deploy to the Artifact Registry section to build and deploy the updated Gitea image to your GCP infrastructure.
If you encounter issues while applying the patch:
- Ensure the patch file corresponds to the correct version of the original repository.
- Resolve any merge conflicts manually by editing the conflicting files.
- Use
git logandgit diffto debug and verify applied changes.
To deploy an image to the artifact registry follow these commands:
-
Set up
gcloudto push to the corresponding docker pkg.gcloud auth configure-docker <var.registry_region>-docker.pkg.dev
The region in
<var.registry_region>should be set to the correct region. -
Build the image with a name.
image_namedocker build -t <image_name> .
-
Tag the image with the corresponding artifact registry location
docker tag <image_name> <var.registry_region>-docker.pkg.dev-docker.pkg.dev/<var.project_id>/<ar_repository_name>/<image_name>
Remember to replace all
<vars>with the corresponding values. -
Push the tagged image to the remote docker registry
docker push <var.registry_region>-docker.pkg.dev/<var.project_id</<output.ar_repository_name</<image_name>
