This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is the AppPack Codebuild Image - a minimal Docker image used by AWS CodeBuild for AppPack application builds. The project contains both the Docker image configuration and a Go-based build orchestration tool.
# Build the Docker image (linux/amd64 platform)
make build
# Build and tag with git version
make build-and-tag
# Push to ECR
make ecr-login # Login to ECR first
make push # Push with :builder tag
make push-tag # Push with git version tag# Run tests for the builder
cd builder && go test ./...
# Run specific test package
cd builder && go test ./build/...
# Build the Go binary
cd builder && go build -o apppack-builder
# Run with verbose/debug output
export APPPACK_DEBUG=1The project consists of two main parts:
-
Docker Image - Minimal build environment for AWS CodeBuild
- Defined in
Dockerfile - Pushed to ECR:
public.ecr.aws/d9q4v8a4/apppack-build - Optimized for fast provisioning (< 25s)
- Defined in
-
Builder CLI (
builder/) - Go application that orchestrates builds- Entry point:
builder/main.go→cmd/root.go - Commands:
prebuild,build,postbuild - Uses Cobra for CLI framework
- Entry point:
The builder supports two build systems:
- Docker builds - Traditional Dockerfile-based builds
- Buildpack builds - Using Cloud Native Buildpacks (Heroku/Paketo)
Key configuration files parsed by the builder:
apppack.toml- Primary AppPack configuration- Can be read from a custom location via APPPACK_TOML env var
- If read from custom location, it's automatically copied to
apppack.tomlafter build for artifact archival - The copy operation is handled by
filesystem.CopyAppPackTomlToDefault()with proper error handling
app.json- Heroku-compatible app configurationmetadata.toml- Build metadata from buildpacks
The builder interacts with AWS services:
- SSM Parameter Store - Fetches environment variables from configured paths
- S3 - Stores build artifacts and cache
- ECR - Pushes built container images
- CloudFormation - Updates stack parameters
cmd/- CLI command definitionsbuild/- Core build logic and configuration parsingapppacktoml.go,appjson.go,metadatatoml.go- Config file parsersprebuild.go,build.go,postbuild.go- Build phase implementations
aws/- AWS service integrationscontainers/- Docker and buildpack container operationsfilesystem/- Git and file operationsshlex/- Shell command parsing utilities
- Prebuild - Prepares environment, clones repository
- Build - Runs Docker or buildpack build based on configuration
- Postbuild - Pushes image to ECR, runs release tasks, updates CloudFormation
The following buildspec.yml is used by default in AWS CodeBuild:
artifacts:
files:
- build.log
- test.log
- apppack.toml
- commit.txt
name: $CODEBUILD_BUILD_NUMBER
phases:
build:
commands: apppack-builder build
install:
commands:
- if [ -z "$CODEBUILD_START_TIME" ]; then exit 0; fi
- echo "Starting Docker daemon..."
- nohup /usr/local/bin/dockerd --host=unix:///var/run/docker.sock --host=tcp://127.0.0.1:2375
--storage-driver=overlay2 --registry-mirror=https://registry.apppackcdn.net
&> /var/lib/docker.log &
- for i in $(seq 1 10); do docker info > /dev/null 2>&1 && break || sleep 0.5;
done
post_build:
commands: apppack-builder postbuild
pre_build:
commands: apppack-builder prebuild
version: 0.2Key points:
- Docker daemon is started during install phase with AppPack's registry mirror
- The three main phases map to
apppack-buildersubcommands - Artifacts include build/test logs, apppack.toml, and commit information
APPPACK_DEBUG- Enable debug loggingAPPPACK_TOML- Path to apppack.toml configuration fileALLOW_EOL_SHIMMED_BUILDER- Allow end-of-life shimmed builders (for testing)
- Code Formatting: Always run
gofumptbefore committing Go code changes - Testing: Verify all tests pass with
go test ./...after making changes