Skip to content

Commit

Permalink
Use file for database for staging
Browse files Browse the repository at this point in the history
  • Loading branch information
ai committed Feb 26, 2025
1 parent 0175a88 commit 3a1d8b0
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/actions/deploy/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ runs:
- name: Auth Google Cloud
uses: google-github-actions/[email protected]
with:
workload_identity_provider: projects/223708816691/locations/global/workloadIdentityPools/github/providers/hplush
workload_identity_provider: projects/900797847730/locations/global/workloadIdentityPools/github/providers/hplush
service_account: github-deploy@${{ inputs.projectId }}.iam.gserviceaccount.com
- name: Install Google Cloud
uses: google-github-actions/[email protected]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
- name: Deploy to Google Cloud
uses: ./.github/actions/deploy
with:
projectId: slowreader-421120
projectId: slowreader-452120
region: europe-west1
folder: ./web/
registry: staging/web
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/preview-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ jobs:
id: deploy
uses: ./.github/actions/deploy
with:
projectId: slowreader-421120
projectId: slowreader-452120
region: europe-west1
folder: ./server/
registry: staging/server
service: staging-server
tag: preview-${{ env.PR_NUMBER }}
env: ASSETS=1,PROXY_ORIGIN=^https:\/\/preview-\d+---staging-server-jfj4bxwwxq-ew\.a\.run\.app$
flags: |
--update-secrets=DATABASE_URL=preview-db-url:latest
env: ASSETS=1,DATABASE_URL=memory://,PROXY_ORIGIN=^https:\/\/preview-\d+---staging-server-jfj4bxwwxq-ew\.a\.run\.app$
# flags: |
# --update-secrets=DATABASE_URL=preview-db-url:latest
- name: Update deployment status
uses: bobheadxi/[email protected]
if: always()
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/proxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ jobs:
- name: Deploy to Google Cloud
uses: ./.github/actions/deploy
with:
projectId: slowreader-421120
projectId: slowreader-452120
region: europe-west1
folder: ./proxy/
registry: staging/proxy
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,16 @@ jobs:
- name: Deploy to Google Cloud
uses: ./.github/actions/deploy
with:
projectId: slowreader-421120
projectId: slowreader-452120
region: europe-west1
folder: ./server/
registry: staging/server
service: staging-server
env: ASSETS=,PROXY_ORIGIN=
env: ASSETS=,PROXY_ORIGIN=,DATABASE_URL=file:///var/mnt/staging-db/pgdata
# Persistent database was disable temporary to save money
# flags: |
# --vpc-connector db-connector
# --update-secrets=DATABASE_URL=staging-db-url:latest
flags: |
--update-secrets=DATABASE_URL=preview-db-url:latest
--add-volume=name=db,type=cloud-storage,bucket=staging-db
--add-volume-mount=volume=db,mount-path=/var/mnt/staging-db/
19 changes: 14 additions & 5 deletions scripts/prepare-google-cloud.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Google Cloud settings can be complex. We have this file to not forget them.
# Do not change Google Cloud by web. Always use `gcloud` and update this script.

PROJECT_ID=slowreader-421120
PROJECT_ID=slowreader-452120
REGION=europe-west1
WORKFLOWS=(
".github/actions/deploy/action.yml"
Expand Down Expand Up @@ -64,7 +64,19 @@ gcloud iam service-accounts add-iam-policy-binding "$ACCOUNT_EMAIL" \
--role="roles/iam.workloadIdentityUser" \
--member="principalSet://iam.googleapis.com/${WORKLOAD_IDENTITY_POOL_ID}/attribute.repository/hplush/slowreader"

# Persistent database was disable temporary to save money
# In-memory storage for preview
echo -n "memory://" | gcloud secrets create preview-db-url \
--replication-policy=automatic \
--data-file=-

# To save money on prototype state, we will use file for DB
gcloud storage buckets create gs://staging-db \
--project=$PROJECT_ID \
--location=$REGION
echo -n "file:///var/mnt/staging-db/pgdata" | gcloud secrets create staging-db-url \
--replication-policy=automatic \
--data-file=-

# # Create private network for database
# gcloud services enable compute.googleapis.com --project=$PROJECT_ID
# gcloud services enable servicenetworking.googleapis.com --project=$PROJECT_ID
Expand Down Expand Up @@ -115,9 +127,6 @@ gcloud iam service-accounts add-iam-policy-binding "$ACCOUNT_EMAIL" \
# echo -n $STAGING_DB | gcloud secrets create staging-db-url \
# --replication-policy=automatic \
# --data-file=-
echo -n "memory://" | gcloud secrets create preview-db-url \
--replication-policy=automatic \
--data-file=-

# Enable Google Cloud Run
gcloud services enable run.googleapis.com --project=$PROJECT_ID
Expand Down

0 comments on commit 3a1d8b0

Please sign in to comment.