This guide documents the process for migrating ScriptureBot from an existing Google Cloud Project (Source) to a new Google Cloud Project (Destination), specifically targeting the asia-southeast1 region.
Before starting the migration, ensure the following are set up in the Destination Project:
- Project Created: You should have the new Project ID ready.
- APIs Enabled:
- Cloud Run Admin API
- Secret Manager API
- Artifact Registry API
- Cloud Datastore API (Firestore in Datastore mode)
- Artifact Registry:
- Create a Docker repository in
asia-southeast1. - Note the Repository Name (e.g.,
scripturebot-repo).
- Create a Docker repository in
- Service Accounts:
- CI/CD Agent: A service account for GitHub Actions (e.g.,
cicd-agent@<project-id>.iam.gserviceaccount.com).- Grant
Cloud Run Admin,Service Account User,Artifact Registry Writer. - Create Key: Generate a new JSON key for this service account and download it.
- Grant
- Compute Service Account: The default compute service account (or a custom one) for Cloud Run.
- Grant
Datastore User(orCloud Datastore User) andSecret Manager Secret Accessor.
- Grant
- CI/CD Agent: A service account for GitHub Actions (e.g.,
Update the following secrets in the GitHub Repository settings:
GCLOUD_PROJECT_ID: The new Project ID.GCLOUD_SA_KEY: The content of the JSON key file you downloaded for the CI/CD Agent.GCLOUD_ARTIFACT_REPOSITORY_ID: The name of the repository created in Artifact Registry.TELEGRAM_ID: The Telegram Bot Token (ensure it matches the one used in the source project if preserving identity).TELEGRAM_ADMIN_ID: Your Telegram User ID.BIBLE_API_URL: The URL for the Bible API (required for new features).BIBLE_API_KEY: The API Key for the Bible API.
A migration tool has been added to cmd/migrate/main.go to assist with transferring User data. This tool avoids complex cross-project permissions by running locally with your admin credentials.
Ensure you are authenticated with gcloud and have access to both projects.
gcloud auth login
gcloud auth application-default loginRun the export command against the Source Project.
go run cmd/migrate/main.go -mode export -gcloud_project_id <SOURCE_GCLOUD_PROJECT_ID> -file backup_users.json- This will fetch all users and save them to
backup_users.json. - Review the file to ensure data looks correct.
Run the import command against the Destination Project.
go run cmd/migrate/main.go -mode import -gcloud_project_id <DESTINATION_GCLOUD_PROJECT_ID> -file backup_users.json- This will read
backup_users.jsonand upload each user to the new Datastore. - Note: Ensure the Destination Project has Datastore (Firestore in Datastore mode) enabled.
The deployment.yml workflow has been updated to deploy to asia-southeast1 using Service Account Key authentication.
- Push the changes to the
masterbranch. - Monitor the "Build, Stage and Deploy Automation" action in GitHub.
- Once successful, verify the new Cloud Run service URL.
- Open the new Cloud Run service logs.
- Send a message to the bot (e.g.,
/startor/verse). - Verify that the bot responds and no database errors occur in the logs.
- If you migrated data, check if your user preferences (e.g., translation version) are preserved.