This repo is intended to serve as an initial template for setting up and managing the infrastructure required to deploy an image that performs RAG operations on a Postgres database hosted on Cloud SQL (an image that enables the pgvector extension), and it is executed via Cloud Run V2 connected to Redis for caching purposes.
- Sign Up: Ensure you have an active GCP account. Sign up here if needed.
- New Project: Create a new GCP project. Note down the project ID for future use.
- Create Service Account: Create a service account with 'Owner' permissions in your GCP project.
- Generate Key File: Generate a JSON key file for this service account and store it securely.
- Enable Billing: Ensure billing is enabled on your GCP project for using paid services.
- Rename File: Change
terraform.tfvars.example
toterraform.tfvars
. - Insert Credentials: Add your credentials to the
terraform.tfvars
file.
- Create a personal access token by navigating to the "Developer settings" in your GitHub account. Select "Personal access tokens" and then "Generate new token". Ensure your token (classic) has no expiration date and grant the following permissions when prompted in GitHub:
repo
andread:user
. For applications in organizations, also includeread:org
permission.
For a secure connection to your Cloud SQL instance from local development environments or database management tools like DBeaver, the Cloud SQL Proxy provides a robust solution. Follow these steps to set up and use the Cloud SQL Proxy:
-
Download the Cloud SQL Proxy: Use the command below to download the latest version of Cloud SQL Proxy for Linux:
curl -o cloud-sql-proxy https://storage.googleapis.com/cloud-sql-connectors/cloud-sql-proxy/v2.8.1/cloud-sql-proxy.linux.amd64
-
Make the Proxy Executable: Change the downloaded file's permissions to make it executable:
chmod +x cloud-sql-proxy
-
Start the Cloud SQL Proxy: Launch the proxy with your Cloud SQL instance details. Replace the
[INSTANCE_CONNECTION_NAME]
with your specific Cloud SQL instance connection name:./cloud-sql-proxy --credentials-file=/path/to/credentials_file.json 'project-name:region:instance-name?port=port_number'
-
Connect using DBeaver:
- Open DBeaver and create a new database connection.
- Set the host to
localhost
and the port to5433
(or the port you specified). - Provide your Cloud SQL instance's database credentials.
For more details on using the Cloud SQL Proxy, visit the official documentation: Google Cloud SQL Proxy Documentation
-
Perform only a few modules (attention to addictions):
terraform apply -target=module.compute_instance
-
Test Cloud SQL Connection:
psql -h private_ip_address -U database_user -d database_name
For detailed implementation, refer to the contents of specific .tf
files within each module's directory.