|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +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. |
| 8 | + |
| 9 | +## Key Commands |
| 10 | + |
| 11 | +### Docker Build |
| 12 | +```bash |
| 13 | +# Build the Docker image (linux/amd64 platform) |
| 14 | +make build |
| 15 | + |
| 16 | +# Build and tag with git version |
| 17 | +make build-and-tag |
| 18 | + |
| 19 | +# Push to ECR |
| 20 | +make ecr-login # Login to ECR first |
| 21 | +make push # Push with :builder tag |
| 22 | +make push-tag # Push with git version tag |
| 23 | +``` |
| 24 | + |
| 25 | +### Go Development (builder/) |
| 26 | +```bash |
| 27 | +# Run tests for the builder |
| 28 | +cd builder && go test ./... |
| 29 | + |
| 30 | +# Run specific test package |
| 31 | +cd builder && go test ./build/... |
| 32 | + |
| 33 | +# Build the Go binary |
| 34 | +cd builder && go build -o apppack-builder |
| 35 | + |
| 36 | +# Run with verbose/debug output |
| 37 | +export APPPACK_DEBUG=1 |
| 38 | +``` |
| 39 | + |
| 40 | +## Architecture |
| 41 | + |
| 42 | +### Core Components |
| 43 | + |
| 44 | +The project consists of two main parts: |
| 45 | + |
| 46 | +1. **Docker Image** - Minimal build environment for AWS CodeBuild |
| 47 | + - Defined in `Dockerfile` |
| 48 | + - Pushed to ECR: `public.ecr.aws/d9q4v8a4/apppack-build` |
| 49 | + - Optimized for fast provisioning (< 25s) |
| 50 | + |
| 51 | +2. **Builder CLI** (`builder/`) - Go application that orchestrates builds |
| 52 | + - Entry point: `builder/main.go` → `cmd/root.go` |
| 53 | + - Commands: `prebuild`, `build`, `postbuild` |
| 54 | + - Uses Cobra for CLI framework |
| 55 | + |
| 56 | +### Build System Architecture |
| 57 | + |
| 58 | +The builder supports two build systems: |
| 59 | +- **Docker builds** - Traditional Dockerfile-based builds |
| 60 | +- **Buildpack builds** - Using Cloud Native Buildpacks (Heroku/Paketo) |
| 61 | + |
| 62 | +Key configuration files parsed by the builder: |
| 63 | +- `apppack.toml` - Primary AppPack configuration |
| 64 | + - Can be read from a custom location via APPPACK_TOML env var |
| 65 | + - If read from custom location, it's automatically copied to `apppack.toml` after build for artifact archival |
| 66 | + - The copy operation is handled by `filesystem.CopyAppPackTomlToDefault()` with proper error handling |
| 67 | +- `app.json` - Heroku-compatible app configuration |
| 68 | +- `metadata.toml` - Build metadata from buildpacks |
| 69 | + |
| 70 | +### AWS Integration |
| 71 | + |
| 72 | +The builder interacts with AWS services: |
| 73 | +- **SSM Parameter Store** - Fetches environment variables from configured paths |
| 74 | +- **S3** - Stores build artifacts and cache |
| 75 | +- **ECR** - Pushes built container images |
| 76 | +- **CloudFormation** - Updates stack parameters |
| 77 | + |
| 78 | +### Package Structure |
| 79 | + |
| 80 | +- `cmd/` - CLI command definitions |
| 81 | +- `build/` - Core build logic and configuration parsing |
| 82 | + - `apppacktoml.go`, `appjson.go`, `metadatatoml.go` - Config file parsers |
| 83 | + - `prebuild.go`, `build.go`, `postbuild.go` - Build phase implementations |
| 84 | +- `aws/` - AWS service integrations |
| 85 | +- `containers/` - Docker and buildpack container operations |
| 86 | +- `filesystem/` - Git and file operations |
| 87 | +- `shlex/` - Shell command parsing utilities |
| 88 | + |
| 89 | +## Build Process Flow |
| 90 | + |
| 91 | +1. **Prebuild** - Prepares environment, clones repository |
| 92 | +2. **Build** - Runs Docker or buildpack build based on configuration |
| 93 | +3. **Postbuild** - Pushes image to ECR, runs release tasks, updates CloudFormation |
| 94 | + |
| 95 | +## Default BuildSpec |
| 96 | + |
| 97 | +The following buildspec.yml is used by default in AWS CodeBuild: |
| 98 | + |
| 99 | +```yaml |
| 100 | +artifacts: |
| 101 | + files: |
| 102 | + - build.log |
| 103 | + - test.log |
| 104 | + - apppack.toml |
| 105 | + - commit.txt |
| 106 | + name: $CODEBUILD_BUILD_NUMBER |
| 107 | +phases: |
| 108 | + build: |
| 109 | + commands: apppack-builder build |
| 110 | + install: |
| 111 | + commands: |
| 112 | + - if [ -z "$CODEBUILD_START_TIME" ]; then exit 0; fi |
| 113 | + - echo "Starting Docker daemon..." |
| 114 | + - nohup /usr/local/bin/dockerd --host=unix:///var/run/docker.sock --host=tcp://127.0.0.1:2375 |
| 115 | + --storage-driver=overlay2 --registry-mirror=https://registry.apppackcdn.net |
| 116 | + &> /var/lib/docker.log & |
| 117 | + - for i in $(seq 1 10); do docker info > /dev/null 2>&1 && break || sleep 0.5; |
| 118 | + done |
| 119 | + post_build: |
| 120 | + commands: apppack-builder postbuild |
| 121 | + pre_build: |
| 122 | + commands: apppack-builder prebuild |
| 123 | +version: 0.2 |
| 124 | +``` |
| 125 | +
|
| 126 | +Key points: |
| 127 | +- Docker daemon is started during install phase with AppPack's registry mirror |
| 128 | +- The three main phases map to `apppack-builder` subcommands |
| 129 | +- Artifacts include build/test logs, apppack.toml, and commit information |
| 130 | + |
| 131 | +## Environment Variables |
| 132 | + |
| 133 | +- `APPPACK_DEBUG` - Enable debug logging |
| 134 | +- `APPPACK_TOML` - Path to apppack.toml configuration file |
| 135 | +- `ALLOW_EOL_SHIMMED_BUILDER` - Allow end-of-life shimmed builders (for testing) |
| 136 | + |
| 137 | +## Development Guidelines |
| 138 | + |
| 139 | +- **Code Formatting**: Always run `gofumpt` before committing Go code changes |
| 140 | +- **Testing**: Verify all tests pass with `go test ./...` after making changes |
0 commit comments