This repository contains Terraform scripts and GitHub Actions workflow to set up and use a remote BuildKit instance for running Docker builds.
The main components of this setup are:
main.tf
: Terraform script to create an EC2 instance with BuildKit installed.terraform.tfvars
: Variables file for Terraform (you need to populate this).Dockerfile
: A sample Dockerfile for testing.buildkit-test.yml
: Example GitHub Actions workflow to use the remote BuildKit instance.Clone this repository.
Configure AWS CLI with your credentials.
Populate terraform.tfvars
with your GitHub organization and repository name:
github_org = "your-org-name"
github_repo = "your-repo-name"
Run Terraform:
terraform init
terraform plan
terraform apply
After terraform apply
is successful, you'll get the public IP of your BuildKit instance. Use this to set the BUILDKIT_HOST
environment variable.
Set the following environment secrets variables in your GitHub repo:
BUILDKIT_HOST
: The public IP address of your EC2 instance (you'll get this after applying Terraform).AWS_ACCOUNT_ID
: Your AWS account ID.The main.tf
file sets up the following resources:
The EC2 instance is configured with user data to install and set up BuildKit. It exposes BuildKit on port 9999 by default.
The included workflow file (buildkit-test.yml
) demonstrates how to use the remote BuildKit instance in your CI/CD pipeline. It sets up the AWS credentials, configures BuildKit to use the remote instance, and runs a Docker build.
⚠️ Warning: The current setup does not exclusively whitelist GitHub Actions runners' IPs. For production use, it's strongly recommended to restrict the security group ingress rules to only allow traffic from GitHub Actions IP ranges and trusted sources.
main.tf
if you need additional AWS services access.Contributions to improve this setup are welcome! Please submit a pull request or open an issue to discuss proposed changes.