Lifecycle
repository·main·Indexed 42 days ago
https://github.com/buildpacks/lifecycleA reference implementation of the Cloud Native Buildpacks (CNB) specification. It provides the orchestration logic for building, running, and rebasing container images, including core phases such as analyzer, detector, restorer, builder, and exporter.
What's inside Lifecycle
- Lifecycle is a reference implementation of the Cloud Native Buildpacks specification. It provides the core logic for orchestrating the build and run phases of a buildpack-based container image creation process.
Use Lifecycle for Build, Run, and Rebase operations
mainLifecycle can be used at different granularities depending on whether you want to run individual phases or the entire orchestration.
Build Operations
You can run the full build process using the
creatorcommand, or execute individual phases manually:analyzer: Reads metadata from the previous image and ensures registry access.detector: Chooses buildpacks (via/bin/detect) and produces a build plan.restorer: Restores layer metadata from the previous image and from the cache, and restores cached layers.builder: Executes buildpacks (via/bin/build).exporter: Creates an image and caches layers.creator: Runs the five phases (analyzer,detector,restorer,builder, andexporter) in order.
Run Operations
launcher: Invokes a chosen process within the container.
Rebase Operations
rebaser: Creates a new image from a previous image using updated base layers.
Verify and download the attached CycloneDX SBOM
mainA CycloneDX Software Bill of Materials (SBOM) is attached to the image and signed. You can verify the attachment and then download it using
cosign(version 2.0.0+).cosign version # must be at least 2.0.0 cosign verify \ --certificate-identity-regexp "https://github.com/buildpacks/lifecycle/.github/workflows/post-release.yml" \ --certificate-oidc-issuer https://token.actions.githubusercontent.com \ -a tag=<tag> -attachment sbom \ buildpacksio/lifecycle:<tag> cosign download sbom buildpacksio/lifecycle:<tag>Set up the lifecycle development environment
mainTo develop on the
lifecycleproject, you must install the following prerequisites based on your operating system:macOS
- Git: Built-in
- Go:
brew install go - jq & yj:
brew install jq yj - Make/Build Tools:
xcode-select --install - Docker: Install Docker Desktop
Windows
- Git:
choco install git -yand setgit config --global core.autocrlf false - Go:
choco install golang -y - jq & yj:
choco install jq -yandgo get github.com/sclevine/yj - Make/Build Tools:
choco install cygwin make -yand addC:\tools\cygwin\binto your system PATH - Docker: Install Docker Desktop
Run lifecycle development tasks with Make
mainThe project uses
maketo automate common development tasks. You can run all tasks at once or execute them individually.Run all tasks
Creates archives for both Linux and Windows at
out/.make allYou can specify a custom version for the output archives by prepending
LIFECYCLE_VERSION:LIFECYCLE_VERSION=1.2.3 make allIndividual tasks
Task Command Description Test make testFormats, vets, and runs tests. Generate Mocks make generateGenerates Go mocks. Lint/Format make format lintFormats and lints code (run after make generate).Build make buildBuilds binaries to out/linux/lifecycle/andout/windows/lifecycle/.Package make packageCreates .tgzarchives from the built binaries.Clean make cleanRemoves the out/directory.# Example: Building with a specific version $ LIFECYCLE_VERSION=1.2.3 make all # Example: Running tests $ make test # Example: Generating mocks and formatting $ make generate $ make format lintTest GitHub Actions workflows on a fork
mainThe lifecycle release process uses a chain of GitHub actions (build, draft-release, and post-release). To test changes to these workflows, fork the
buildpacks/lifecyclerepository and run the release process end-to-end.Required Secrets for Forks:
DOCKER_PASSWORD(if not usingghcr.io)DOCKER_USERNAME(if not usingghcr.io)
You can use the
tools/test-fork.shscript to update the source code to reflect the state of your fork by providing the registry repository name../tools/test-fork.sh <registry repo name>Verify the integrity of the lifecycle image
mainThe lifecycle images are signed with
cosign. To ensure the image has not been tampered with, verify the signature against the official GitHub Actions workflow identity. Ensure you are usingcosignversion 2.0.0 or later.cosign version # must be at least 2.0.0 cosign verify \ --certificate-identity-regexp "https://github.com/buildpacks/lifecycle/.github/workflows/post-release.yml" \ --certificate-oidc-issuer https://token.actions.githubusercontent.com \ buildpacksio/lifecycle:<tag>Configure Lifecycle Environment via Platform API
mainThe lifecycle behavior is heavily influenced by platform inputs. A critical environment variable is
CNB_PLATFORM_API.If
CNB_PLATFORM_APIis unset, the lifecycle will issue a warning and default to a specific version (defined byplatform.DefaultPlatformAPI). It is highly recommended to set this variable to ensure stability and avoid breaking changes when the lifecycle tool is upgraded.Other inputs that affect the CLI execution include:
NoColor: If set, disables color output in the logs.LogLevel: Sets the verbosity of thecmd.DefaultLogger.
Descriptor schema for lifecycle.toml
mainThe
imagetool reads alifecycle.tomlfile from the provided lifecycle TGZ to extract metadata. The expected structure is:[lifecycle] version = "0.21.20" [apis.buildpack] supported = ["v1"] deprecated = [] [apis.platform] supported = ["v1"] deprecated = []This data is used to populate the image labels
io.buildpacks.lifecycle.apis,io.buildpacks.lifecycle.version, and the legacyio.buildpacks.builder.metadatalabel.Skip vendor-specific registry keychains
mainIf you are building a platform that manages credentials manually, you can prevent the lifecycle from automatically attempting to load vendor-specific keychain implementations. This can improve performance by avoiding unnecessary helper invocations based on the hosting environment or registries being accessed.
Set the following environment variables to
trueto skip the respective keychain:CNB_REGISTRY_AUTH_KEYCHAIN_SKIP_AMAZON: Skips the Amazon/AWS ECR credhelper.CNB_REGISTRY_AUTH_KEYCHAIN_SKIP_AZURE: Skips the Microsoft/Azure ACR credhelper.
# Example: Skip both Amazon and Azure keychains export CNB_REGISTRY_AUTH_KEYCHAIN_SKIP_AMAZON=true export CNB_REGISTRY_AUTH_KEYCHAIN_SKIP_AZURE=trueConfigure export modes: Remote, Daemon, or Layout
mainThe
exportercommand determines how to create the output image based on the flags provided:- Remote Export (Default): If neither
--use-daemonnor--use-layoutis specified, the exporter communicates directly with remote registries using the provided credentials. - Daemon Export: Using the
--use-daemonflag instructs the exporter to use a local Docker daemon to build and manage the image. - Layout Export: Using the
--use-layoutflag instructs the exporter to write the image to an OCI layout directory specified by--layout-dir.
- Remote Export (Default): If neither
Use SOURCE_DATE_EPOCH for reproducible builds
mainThe exporter respects the
SOURCE_DATE_EPOCHenvironment variable to set the creation timestamp of the image. This is useful for achieving reproducible builds. If the variable is set to a valid Unix timestamp, it will be used instead of the current system time.export SOURCE_DATE_EPOCH=1694736000 lifecycle exporter my-app:latest ...