Aspect Workflows runs Bazel directly on the host machine, not in a container, to avoid Docker-in-Docker complications. Runners therefore use a cloud machine image, not a container image. Aspect publishes open-source starter machine images, but you may need to build a custom image with Packer when:
- You require tight control over security patches and versions of the OS and packages.
- The starter images don’t include fixes for every vulnerability you track.
- Your non-hermetic build or tests require specific system-level packages.
Step 1: Prepare the build machine
- Download Packer for your operating system. To have Bazel manage the Packer binary instead, see the starter images repository linked in step 5.
- Authenticate with your cloud provider (Amazon Web Services or Google Cloud Platform). Packer needs permission to create EC2 or Compute Engine instances.
Step 2: Choose a base image
AWS
- Access the AWS console.
- Access the EC2 Dashboard and select AMIs from the left sidebar.
Start with an Amazon-supplied image, for example Amazon Linux 2023 (al2023-ami).
See Packer’s Getting Started with AWS for building AMIs.
GCP
- Access the GCP console.
- Navigate to Compute Engine > Images.
- Search for the image that suits your needs, for example
debian-13 or ubuntu-2404-lts.
Step 3: Create a Packer script
Packer scripts use the HashiCorp Configuration Language (HCL), like Terraform, with the .pkr.hcl file extension.
- Add the Packer plugin for your cloud provider to your Packer script:
- Create a
locals block for the values you reuse:
- Create a
source block and a build block, following the Packer documentation.
Step 4: Dependencies
Minimal dependencies
Every custom machine image needs:
AWS AMI requirements
AWS AMIs also need:
amazon-ssm-agent comes pre-installed on Amazon Linux 2 and Amazon Linux 2023 base AMIs.
GCP image requirements
GCP images also need:
GitHub Actions requirements
Runners for GitHub Actions also need:
Recommended dependencies
Step 5: Add dependencies for your build
Install the packages your build needs, such as Docker, with apt-get or yum depending on your Linux distribution:
Step 6: Test a new image
Test image changes on a separate canary runner group before they reach the runners your developers depend on. In your Workflows Terraform configuration:
- Add a
data "aws_ami" or data "google_compute_image" block that selects the canary image.
- Add an entry to
resource_types with image_id set to the canary image ID.
- Add a runner group under
runners (for example in runners.bk.groups) that selects the new resource type.
- Run
terraform apply.
- Point one or more jobs in your CI configuration at the canary runner group’s queue.
To test the new image fully, force a complete, non-incremental build by adding cache-busting environment variables for actions and repository rules to .bazelrc: