Skip to content

marcusmonteirodesouza/google-cloud-translation-playground

Repository files navigation

Google Cloud Translation Playground

A copy of Google Translate's page for translating documents, with the addition that plain text files can also be translated.

google-cloud-translation-playground-demo.mp4

System Overview

Architecture Diagram

system architecture diagram

Components

A Node.js server written using Express and socket.io, running on Cloud Run. It:

  1. Receives the translation request, creates a "translation job" record in Firestore.
  2. Uploads the file to the Cloud Storage bucket to trigger a translation.
  3. After the "translation job" has started, it connects to clients via socket.io to keep them updated about the "translation job's" status. To figure out that status, it gets realtime updates about the corresponding document.
  4. It provides a route for the user to downlod the translated document when the job is done.

A Cloud Function triggered by files being created in a GCS bucket. It:

  1. Uses the Cloud Translation API to translate the document.
  2. Uploads the translated file to another GCS bucket.
  3. Updates the "translation job's" status.

An user interface written using React, bootstrapped with create-react-app. It uses bulma as the main provider of components.

Costs

Be aware of the costs incurred by the running system, in particular:

  1. Cloud Load Balancing
  2. Translation API. This system makes use of the Cloud Translation - Advanced features.

Deployment

The system is deployed using terraform, running in Cloud Build.

Pre-requisites

  1. Create a Google Cloud Organization.
  2. Install terraform.
  3. Install the gcloud CLI.
  4. Have a domain and the ability to create A Records to connect that domain to the Load Balancer.

Bootstrap

This is the process that creates the Google Cloud Project, enables the required APIs, and grants the necessary permissions to the Service Accounts, including the ones required for the Cloud Build Service Account to deploy the system.

  1. Run gcloud auth login
  2. Run gcloud auth application-default login.
  3. cd into the deployment/google-cloud/terraform/bootstrap folder.
  4. Comment out the entire contents of the deployment/google-cloud/terraform/bootstrap/backend.tf file.
  5. Create a terraform.tfvars file and add your variables' values. Leave the sourcerepo_name empty for now.
  6. Run terraform init.
  7. Run terraform apply -target=module.project.
  8. Uncomment the deployment/google-cloud/terraform/bootstrap/backend.tf file's contents and add the value of the tfstate_bucket output as the value of the bucket attribute.
  9. Run terraform init and answer yes.
  10. Create a Cloud Source Repository in the project your just created. Optionally, fork this repository and create a Cloud Source Repository by mirroring your forked repo. Update the sourcerepo_name variable with the repository name.
  11. Run terraform apply.
  12. If you have errors related to granting permissions to the Google Storage Service Agent, you can go to your project's Google Cloud console, then go to Cloud Storage -> Settings and check for the presence of the Service Agent. Then re-run terraform apply.

Deployment

This is a Cloud Build build that actually deploys the system.

  1. The pipeline can be triggered by either:
    • Push a commit to your Cloud Source Repository or to your Github fork.
    • Go to your project's Cloud Build Dashboard and manually run the push-to-branch-deployment trigger.
  2. After the build is successful, connect your domain to the Load Balancer.