Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

name: Build and Deploy to Cloud Run

on:
push:
branches:
- main

env:
PROJECT_ID: launchflow-services-dev
SERVICE_NAME: fastapi-app
REGION: us-west1

jobs:
setup-build-deploy:
name: Setup, Build, and Deploy
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Google Auth
id: auth
uses: google-github-actions/auth@v1
with:
credentials_json: ${{ secrets.GCP_SA_KEY }}

- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v1

- name: Build and push Docker image
run: |
gcloud builds submit --tag gcr.io/$PROJECT_ID/$SERVICE_NAME:${{ github.sha }}

- name: Deploy to Cloud Run
run: |
gcloud run deploy $SERVICE_NAME \
--image gcr.io/$PROJECT_ID/$SERVICE_NAME:${{ github.sha }} \
--platform managed \
--region $REGION \
--allow-unauthenticated
27 changes: 27 additions & 0 deletions cloudbuild.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

steps:
# Build the container image
- name: 'gcr.io/cloud-builders/docker'
args: ['build', '-t', 'gcr.io/$PROJECT_ID/fastapi-app:$COMMIT_SHA', '.']

# Push the container image to Container Registry
- name: 'gcr.io/cloud-builders/docker'
args: ['push', 'gcr.io/$PROJECT_ID/fastapi-app:$COMMIT_SHA']

# Deploy container image to Cloud Run
- name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'
entrypoint: gcloud
args:
- 'run'
- 'deploy'
- 'fastapi-app'
- '--image'
- 'gcr.io/$PROJECT_ID/fastapi-app:$COMMIT_SHA'
- '--region'
- 'us-west1'
- '--platform'
- 'managed'
- '--allow-unauthenticated'

images:
- 'gcr.io/$PROJECT_ID/fastapi-app:$COMMIT_SHA'
47 changes: 47 additions & 0 deletions infra/environments/dev/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

provider "google" {
project = "launchflow-services-dev"
region = "us-west1"
}

resource "google_cloud_run_v2_service" "fastapi_service" {
name = "fastapi-app"
location = "us-west1"

template {
containers {
image = "gcr.io/launchflow-services-dev/fastapi-app:latest"

ports {
container_port = 80
}

resources {
limits = {
cpu = "1"
memory = "512Mi"
}
}
}

scaling {
min_instance_count = 0
max_instance_count = 2
}
}

# Allow unauthenticated access
depends_on = [google_cloud_run_service_iam_member.public_access]
}

resource "google_cloud_run_service_iam_member" "public_access" {
location = google_cloud_run_v2_service.fastapi_service.location
service = google_cloud_run_v2_service.fastapi_service.name
role = "roles/run.invoker"
member = "allUsers"
}

# Output the service URL
output "service_url" {
value = google_cloud_run_v2_service.fastapi_service.uri
}
2 changes: 2 additions & 0 deletions infra/environments/dev/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

# No variables needed for this basic setup
47 changes: 47 additions & 0 deletions infra/environments/prod/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

provider "google" {
project = "launchflow-services-dev" # Change this to your production project ID
region = "us-west1"
}

resource "google_cloud_run_v2_service" "fastapi_service" {
name = "fastapi-app"
location = "us-west1"

template {
containers {
image = "gcr.io/launchflow-services-dev/fastapi-app:latest" # Update with your production image

ports {
container_port = 80
}

resources {
limits = {
cpu = "2"
memory = "1Gi"
}
}
}

scaling {
min_instance_count = 1 # Always have at least one instance running
max_instance_count = 5 # Scale up to 5 instances
}
}

# Allow unauthenticated access
depends_on = [google_cloud_run_service_iam_member.public_access]
}

resource "google_cloud_run_service_iam_member" "public_access" {
location = google_cloud_run_v2_service.fastapi_service.location
service = google_cloud_run_v2_service.fastapi_service.name
role = "roles/run.invoker"
member = "allUsers"
}

# Output the service URL
output "service_url" {
value = google_cloud_run_v2_service.fastapi_service.uri
}
2 changes: 2 additions & 0 deletions infra/environments/prod/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

# No variables needed for this basic setup