-
Notifications
You must be signed in to change notification settings - Fork 0
serverless deploy #143
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
trett
wants to merge
21
commits into
main
Choose a base branch
from
gcr-delpoy
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
serverless deploy #143
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
2e384f1
gcp deploy
trett 34e43e8
remove otel
trett 6127cb2
faster init
trett 5e446ad
address comments
trett 39012d9
add tests
trett 1fd3e51
revert app cds
trett 69469b1
Update DEPLOY.md
trett 5fa2c2c
Update DEPLOY.md
trett 383caee
use SerialGC
trett f42e544
fixes
trett f3faa50
graalvm build
trett be9dbe5
fix build
trett 2d1c8a8
build native
trett 016145d
build fix
trett 28ab2d6
build fix
trett b542a15
build fix
trett 2a74912
build fix
trett 919ee76
build fix
trett a439632
build fix
trett e704c37
build fix
trett 10540e9
build fix
trett 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
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,140 @@ | ||
| # Deployment Guide for Google Cloud Run | ||
|
|
||
| This guide outlines the steps to deploy the RSS Reader application to Google Cloud Run, including setting up the PostgreSQL database and background update tasks. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| * **Google Cloud Platform Account** with billing enabled. | ||
| * **gcloud CLI** installed and authenticated. | ||
| * **Existing Docker Image** hosted in Google Container Registry (GCR) or Artifact Registry. | ||
|
|
||
| ## 1. Environment Setup | ||
|
|
||
| Define the following environment variables for your deployment. | ||
|
|
||
| ```bash | ||
| export PROJECT_ID="your-gcp-project-id" | ||
| export REGION="us-central1" # Or your preferred region | ||
| export IMAGE_URL="docker.pkg.dev/your-gcp-project-id/your-repo/your-image:latest" | ||
trett marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| export DB_INSTANCE_NAME="rss-postgres" | ||
| export DB_NAME="rss" | ||
| export DB_USER="rss_user" | ||
| export DB_PASSWORD="your-secure-password" | ||
| export SERVICE_NAME="rss-reader" | ||
| export JOB_TOKEN="your-secret-job-token" # Generate a strong random string | ||
| export JWT_SECRET="your-secure-jwt-secret" # Generate a strong random string for token signing | ||
| export OAUTH_CLIENT_ID="your-google-oauth-client-id" | ||
| export OAUTH_CLIENT_SECRET="your-google-oauth-client-secret" | ||
| export GOOGLE_API_KEY="your-google-gemini-api-key" | ||
trett marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ``` | ||
|
|
||
| ## 2. Infrastructure Setup | ||
|
|
||
| ### Create Cloud SQL Instance | ||
|
|
||
| Create a PostgreSQL instance (if you haven't already). | ||
|
|
||
| ```bash | ||
| gcloud sql instances create $DB_INSTANCE_NAME \ | ||
| --database-version=POSTGRES_15 \ | ||
| --cpu=1 \ | ||
| --memory=3840MiB \ | ||
| --region=$REGION | ||
| ``` | ||
|
|
||
| Create the database and user. | ||
|
|
||
| ```bash | ||
| gcloud sql databases create $DB_NAME --instance=$DB_INSTANCE_NAME | ||
|
|
||
| gcloud sql users create $DB_USER \ | ||
| --instance=$DB_INSTANCE_NAME \ | ||
| --password=$DB_PASSWORD | ||
| ``` | ||
|
|
||
| ## 3. Configuration | ||
|
|
||
| ### Service Definition | ||
| Create a `service.yaml` file with the following content. This defines the Cloud Run service. | ||
|
|
||
| **Important:** Replace placeholders (like `YOUR_PROJECT_ID`, `YOUR_IMAGE_URL`) with your actual values or use `envsubst`. | ||
|
|
||
| ```yaml | ||
| apiVersion: serving.knative.dev/v1 | ||
| kind: Service | ||
| metadata: | ||
| name: rss-reader | ||
| annotations: | ||
| run.googleapis.com/maxScale: '1' | ||
| run.googleapis.com/launch-stage: BETA | ||
| spec: | ||
| template: | ||
| metadata: | ||
| annotations: | ||
| run.googleapis.com/cloudsql-instances: ${PROJECT_ID}:${REGION}:${DB_INSTANCE_NAME} | ||
| run.googleapis.com/execution-environment: gen1 | ||
| run.googleapis.com/startup-cpu-boost: 'true' | ||
| spec: | ||
| containers: | ||
| - image: IMAGE_URL | ||
| name: rss-reader-app | ||
| ports: | ||
| - containerPort: 8080 | ||
| env: | ||
| - name: DATASOURCE_URL | ||
| value: "jdbc:postgresql:///rss?cloudSqlInstance=$PROJECT_ID:$REGION:$DB_INSTANCE_NAME&socketFactory=com.google.cloud.sql.postgres.SocketFactory&user=$DB_USER&password=$DB_PASSWORD" | ||
| - name: CLIENT_ID | ||
| value: "$OAUTH_CLIENT_ID" | ||
| - name: CLIENT_SECRET | ||
| value: "$OAUTH_CLIENT_SECRET" | ||
| - name: GOOGLE_API_KEY | ||
| value: "$GOOGLE_API_KEY" | ||
| - name: JOB_TOKEN | ||
| value: "$JOB_TOKEN" | ||
| - name: JWT_SECRET | ||
| value: "$JWT_SECRET" | ||
| - name: SERVER_URL | ||
| value: "https://rss-reader-PROJECT_ID.REGION.run.app" # Update after first deploy if needed | ||
| - name: CORS_URL | ||
| value: "https://rss-reader-PROJECT_ID.REGION.run.app" # Update after first deploy if needed | ||
trett marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| resources: | ||
| limits: | ||
| cpu: 1000m | ||
| memory: 512Mi | ||
| startupProbe: | ||
| failureThreshold: 1 | ||
| periodSeconds: 240 | ||
| tcpSocket: | ||
| port: 8080 | ||
| timeoutSeconds: 240 | ||
| timeoutSeconds: 300 | ||
| ``` | ||
|
|
||
| ## 4. Deploy to Cloud Run | ||
|
|
||
| Deploy using the `service.yaml`. | ||
|
|
||
| ```bash | ||
| envsubst < service.yaml | gcloud run services replace - --region=$REGION | ||
| ``` | ||
|
|
||
| ## 5. Configure Cloud Scheduler | ||
|
|
||
| Set up a job to trigger the feed update every 10 minutes. | ||
|
|
||
| ```bash | ||
| # Get the Service URL | ||
| SERVICE_URL=$(gcloud run services describe $SERVICE_NAME --platform managed --region $REGION --format "value(status.url)") | ||
|
|
||
| gcloud scheduler jobs create http rss-update-job \ | ||
| --schedule="*/10 * * * *" \ | ||
| --uri="$SERVICE_URL/api/jobs/update" \ | ||
| --http-method=POST \ | ||
| --headers="Authorization=Bearer $JOB_TOKEN" \ | ||
| --location=$REGION \ | ||
| --description="Trigger RSS feed updates" | ||
| ``` | ||
|
|
||
| ## 6. Database Migrations | ||
|
|
||
| The application runs Flyway migrations automatically on startup. No manual schema application is required. | ||
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
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
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
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 @@ | ||
| {"name":"RSS Reader","short_name":"RSS","icons":[{"src":"/images/android-chrome-192x192.png","sizes":"192x192","type":"image/png"},{"src":"/images/android-chrome-512x512.png","sizes":"512x512","type":"image/png"}],"theme_color":"#ffffff","background_color":"#ffffff","display":"standalone"} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.