Lightpress uses AWS CodeBuild as its CI/CD execution environment. TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/reds-skywalker/Lightpress/llms.txt
Use this file to discover all available pages before exploring further.
buildspec.yml file at the project root tells CodeBuild how to build, test, and deploy each service. A single buildspec can handle all microservices sequentially, or you can maintain one buildspec per service for independent pipelines — Lightpress ships with a single shared buildspec that iterates over the microservices/ directory.
CodeBuild executes the buildspec in a managed build environment that you choose when configuring the project. Lightpress uses the standard AWS managed image
aws/codebuild/standard:7.0, which includes Node.js 20 and Python 3.11 out of the box.Buildspec format
Abuildspec.yml has four top-level sections:
| Section | Required | Purpose |
|---|---|---|
version | Yes | Buildspec schema version. Always 0.2. |
env | No | Declare environment variables and secrets. |
phases | Yes | Ordered commands: install → pre_build → build → post_build. |
artifacts | No | Files to export after a successful build. |
cache | No | Directories to cache between builds to speed up installs. |
Complete example
The following buildspec builds all Node.js microservices, runs tests, builds Docker images, pushes them to Amazon ECR, and triggers a deployment update.buildspec.yml
Phases
install
The install phase runs before any of your code. Use it to:
- Declare runtime versions using
runtime-versions(Node.js, Python, Java, etc.) - Install global CLI tools (
npm,pip,awscli) - Install project dependencies with
npm ciorpip install -r requirements.txt
pre_build
Runs after install but before the main build. Use it to:
- Run linters and static analysis
- Execute unit and integration tests
- Authenticate with external registries (ECR, npm, PyPI)
- Generate code or run database migrations
pre_build exits with a non-zero code, the build fails and build / post_build do not run.
build
The primary compilation phase. Use it to:
- Compile TypeScript with
tscor bundle with a tool like Vite or esbuild - Build Docker images with
docker build - Package Lambda functions or CloudFormation templates
post_build
Runs after build succeeds. Use it to:
- Push Docker images to ECR
- Deploy to ECS, Lambda, or S3
- Send notifications (Slack, SNS)
- Write deployment metadata for downstream pipelines
Environment variables
CodeBuild makes the following variables available automatically in every build. You do not need to declare them.| Variable | Description |
|---|---|
CODEBUILD_BUILD_ID | Unique identifier for the current build run. |
CODEBUILD_BUILD_NUMBER | Sequential build number within the project. |
CODEBUILD_BUILD_SUCCEEDING | 1 if all phases so far have succeeded, 0 otherwise. |
CODEBUILD_RESOLVED_SOURCE_VERSION | Full Git commit SHA of the source being built. Use as a Docker image tag for immutable references. |
CODEBUILD_SOURCE_REPO_URL | URL of the source repository. |
CODEBUILD_SRC_DIR | Path to the directory where source code was checked out (default: /codebuild/output/src*/src). |
AWS_DEFAULT_REGION | AWS region of the CodeBuild project. Same as AWS_REGION. |
AWS_ACCOUNT_ID | AWS account ID of the CodeBuild project. |
Sourcing secrets
Hardcoding secret values inbuildspec.yml is a security risk — even when the file is in a private repository. Use one of the following approaches instead:
- Parameter Store
- Secrets Manager
- CodeBuild console
Reference SSM Parameter Store values in the The CodeBuild service role must have
env.parameter-store block. CodeBuild retrieves them at build start and injects them as environment variables.ssm:GetParameters permission on the relevant parameter paths.Artifacts
Theartifacts section defines which files CodeBuild exports to S3 after a successful build. These can be consumed by downstream pipeline stages (e.g. a deployment stage in CodePipeline).
discard-paths: yes to flatten all matched files into the root of the artifact zip, which is useful when a downstream action expects files at the top level.
Cache
Cachingnode_modules dramatically reduces install time. CodeBuild stores the cached directories in S3 between builds and restores them at the start of the next build.
You must enable caching in the CodeBuild project settings (choose “Amazon S3” as the cache type and specify a bucket) for the
cache section in buildspec.yml to have any effect.Debugging a failed build
When a build fails, the most useful debugging approaches are:Check the phase log
In the AWS console, open the failed build and expand the phase that failed. Each command’s stdout and stderr is captured there.
Add verbose output
Temporarily add
set -x at the top of the failing phase’s commands list to print every command before it executes. Remember to remove it before merging.Reproduce locally with CodeBuild Local
AWS provides a CodeBuild local agent Docker image that lets you run your buildspec locally without pushing to AWS. This is the fastest way to iterate on build scripts.