|
| 1 | +# ABFS Environment Blueprint |
| 2 | + |
| 3 | +This blueprint deploys a complete Android Build Filesystem (ABFS) environment on |
| 4 | +Google Cloud. It provides a scalable and secure solution for building Android |
| 5 | +and is ideal for teams looking to modernize their Android development |
| 6 | +infrastructure. The blueprint also includes a sophisticated CI/CD pipeline for |
| 7 | +creating and maintaining custom developer environments using Cloud Workstations. |
| 8 | + |
| 9 | +## Deployed Resources |
| 10 | + |
| 11 | +This blueprint will deploy the following key resources to stand up a fully |
| 12 | +functional ABFS environment: |
| 13 | + |
| 14 | +- **Spanner Instance and Database**: A fully managed, mission-critical, |
| 15 | + relational database service that provides a scalable and highly available |
| 16 | + backend for ABFS. |
| 17 | +- **ABFS Server**: The core component of the Android Build Filesystem, |
| 18 | + deployed on Google Compute Engine (GCE). |
| 19 | +- **ABFS Uploaders**: Services responsible for uploading build artifacts into |
| 20 | + the ABFS environment. |
| 21 | +- **Optional ABFS Client**: A Compute Engine instance can be optionally |
| 22 | + created to act as a client for interacting with and testing the ABFS setup. |
| 23 | + |
| 24 | +## ABFS Licensing and Deployment Flow |
| 25 | + |
| 26 | +Deploying the ABFS environment involves a two-step process due to licensing |
| 27 | +requirements: |
| 28 | + |
| 29 | +1. **Initial `terraform apply`**: Run `terraform apply` for the first time. |
| 30 | + This will provision the necessary project infrastructure and output the |
| 31 | + license information. |
| 32 | + |
| 33 | +2. **Submit EAP Form**: Use the license information from the Terraform output |
| 34 | + to fill out the EAP (Early Access Program) form provided by the Google team. |
| 35 | + This will initiate the licensing process for your service account. |
| 36 | + |
| 37 | +3. **Update `terraform.tfvars`**: Once you receive the license key, add it to |
| 38 | + your `terraform.tfvars` file. For example: |
| 39 | + ```hcl |
| 40 | + abfs_license = "your-license-key-here" |
| 41 | + ``` |
| 42 | +
|
| 43 | +4. **Final `terraform apply`**: Run `terraform apply` a second time. With the |
| 44 | + license key in place, Terraform will now deploy and start all the ABFS |
| 45 | + components, including the server and uploaders. |
| 46 | +
|
| 47 | +5. **Seeding and Building**: After the deployment is complete, the ABFS |
| 48 | + uploaders will begin seeding the environment with data from the Gerrit |
| 49 | + server. Once this process is finished, you can use the ABFS client to mount |
| 50 | + the filesystem and start your first Android build. |
| 51 | +
|
| 52 | +## Automated Custom Images for Cloud Workstations |
| 53 | +
|
| 54 | +A key feature of this blueprint is its ability to create and manage custom |
| 55 | +container images for |
| 56 | +[Cloud Workstations](https://cloud.google.com/workstations). This allows you to |
| 57 | +provide developers with tailored, up-to-date, and secure development |
| 58 | +environments like **Android Studio (AS)**, |
| 59 | +**Android Studio for Platform (ASfP)**, and more. |
| 60 | +
|
| 61 | +The blueprint sets up a complete, GitOps-driven CI/CD pipeline to automate the |
| 62 | +build, deployment, and maintenance of these custom images. |
| 63 | +
|
| 64 | +### The CI/CD Workflow for Custom Images |
| 65 | +
|
| 66 | +The process is designed to be fully automated after the initial setup: |
| 67 | +
|
| 68 | +1. **Initial Deployment (`terraform apply`)**: |
| 69 | + When you first apply the Terraform configuration for this blueprint, it |
| 70 | + provisions the entire CI/CD foundation, including: |
| 71 | + * A **Secure Source Manager (SSM)** repository to host the source code for |
| 72 | + your custom images. |
| 73 | + * A **Cloud Build trigger** configured with a webhook to automatically |
| 74 | + start a build on a `git push` to the SSM repository. |
| 75 | + * An **Artifact Registry** repository to securely store the built |
| 76 | + container images. |
| 77 | + * **Cloud Workstations configurations** that are pre-configured to use the |
| 78 | + `:latest` tag of your custom images. |
| 79 | + * A **Cloud Scheduler** job to periodically rebuild the images. |
| 80 | +
|
| 81 | +2. **Adding Image Source Code**: |
| 82 | + After the infrastructure is deployed, you push the source code for your |
| 83 | + custom workstation images to the repository. An example |
| 84 | + repository with Dockerfiles and build configurations can be found here: |
| 85 | + [Android Open Source Project Images](https://github.com/GoogleCloudPlatform/cloud-workstations-custom-image-examples/tree/main/examples/images/android-open-source-project). |
| 86 | + ```bash |
| 87 | + # Configure the gcloud helper for Secure Source Manager |
| 88 | + git config --global credential.'https://*.*.sourcemanager.dev'.helper gcloud.sh |
| 89 | +
|
| 90 | + # Clone the example repository |
| 91 | + git clone https://github.com/GoogleCloudPlatform/cloud-workstations-custom-image-examples.git |
| 92 | + cd cloud-workstations-custom-image-examples/examples/images/android-open-source-project |
| 93 | +
|
| 94 | + # Add your repository as a remote |
| 95 | + git remote add private $(terraform output -raw secure_source_manager_repository_git_https) |
| 96 | +
|
| 97 | + # Push the code to the main branch |
| 98 | + git push private main |
| 99 | + ``` |
| 100 | +
|
| 101 | +3. **Automated Build and Deployment**: |
| 102 | + The `git push` automatically triggers the Cloud Build pipeline via a |
| 103 | + webhook. Cloud Build: |
| 104 | + * Builds the container image from your Dockerfile. |
| 105 | + * Pushes the newly built image to Artifact Registry. |
| 106 | + * Tags the image as `:latest`. |
| 107 | +
|
| 108 | +4. **Periodic Rebuilds for Security**: |
| 109 | + The Cloud Scheduler job runs on a defined schedule (e.g., nightly) and |
| 110 | + triggers the same Cloud Build pipeline. This is critical for security and |
| 111 | + maintenance, as it ensures your custom images are regularly rebuilt on top |
| 112 | + of their base layers. This process automatically incorporates the latest OS |
| 113 | + updates and security patches into your development environments without any |
| 114 | + manual intervention. |
| 115 | +
|
| 116 | +5. **Seamless User Experience**: |
| 117 | + When a developer starts a new Cloud Workstation, it automatically pulls the |
| 118 | + `:latest` image tag from Artifact Registry. Because of the automated build |
| 119 | + and periodic rebuild process, they are always launching a workstation that |
| 120 | + is up-to-date, secure, and contains the preinstalled tools they need. |
0 commit comments