MCPcopy Index your code
hub / github.com/chainguard-dev/apko

github.com/chainguard-dev/apko @v1.2.22

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.2.22 ↗ · + Follow
1,115 symbols 4,689 edges 125 files 323 documented · 29% 1 cross-repo links
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

apko: apk-based OCI image builder

Build and publish OCI container images built from apk packages.

apko has the following key features:

  • Fully reproducible by default. Run apko twice and you will get exactly the same binary.
  • Fast. apko aims to build images in ms.
  • Small. apko generated images only contain what's needed by the application, in the style of distroless.
  • SBOM Support. apko produces a Software Bill of Materials (SBOM) for images, detailing all the packages inside.
  • Services. apko supports using the s6 supervision suite to run multiple processes in a container without reaping or signalling issues.

Please note that apko is a work in progress and details are subject to change!

Installation

You can install apko from Homebrew:

brew install apko

You can also install apko from source:

go install chainguard.dev/apko@latest

You can also use the apko container image:

docker run cgr.dev/chainguard/apko version

To use the examples, you'll generally want to mount your current directory into the container, e.g.:

docker run -v "$PWD":/work cgr.dev/chainguard/apko build examples/alpine-base.yaml apko-alpine:edge apko-alpine.tar

Quickstart

An apko file for building an Alpine base image looks like this:

contents:
  repositories:
    - https://dl-cdn.alpinelinux.org/alpine/v3.22/main
  packages:
    - alpine-base

entrypoint:
  command: /bin/sh -l

# optional environment configuration
environment:
  PATH: /usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin

We can build this with apko from any environment with apk tooling:

apko build examples/alpine-base.yaml apko-alpine:test apko-alpine.tar
...
2022/04/08 13:22:31 apko (aarch64): generating SBOM
2022/04/08 13:22:31 building OCI image from layer '/tmp/apko-3027985148.tar.gz'
2022/04/08 13:22:31 OCI layer digest: sha256:ba034c07d0945abf6caa46fe05268d2375e4209e169ff7fdd34d40cf4e5f2dd6
2022/04/08 13:22:31 OCI layer diffID: sha256:9b4ab6bb8831352b25c4bd21ee8259d1f3b2776deec573733291d71a390157bb
2022/04/08 13:22:31 output OCI image file to apko-alpine.tar

or, with Docker:

docker run -v "$PWD":/work cgr.dev/chainguard/apko build examples/alpine-base.yaml apko-alpine:test apko-alpine.tar

You can then load the generated tar image into a Docker environment:

docker load < apko-alpine.tar
Loaded image: apko-alpine:test
docker run -it apko-alpine:test
e289dc84c4ad:/# echo boo!
boo!

You can also publish the image directly to a registry:

apko publish examples/alpine-base.yaml myrepo/alpine-apko:test

See the docs for details of the file format and the examples directory for more, err, examples!

Why

apko was created by Chainguard, who require secure and reproducible container images for their tooling. Speed is also a critical factor; Chainguard require images to be rebuilt constantly in response to new versions and patches.

The design of apko is heavily influenced by the ko and distroless projects.

Declarative Nature

By design, apko doesn't support an equivalent of RUN statements in Dockerfiles. This means apko files are fully declarative and allows apko to make stronger statements about the contents of images. In particular, apko images are fully bitwise reproducible and can generate SBOMs covering their complete contents.

In order to install bespoke tooling or applications into an image, they must first be packaged into an apk. This can be done with apko's sister tool melange.

The combination of melange and apko cover the vast majority of use cases when building container images. In the cases where they are not a good fit, our recommendation is to build a base image with apko and melange, then use traditional tooling such as Dockerfiles for the final step.

Further Reading

Tutorials and guides for apko can be found at the Chainguard Academy.

For questions, please find us on the Kubernetes Slack in the #apko channel.

Related Work and Resources

The melange project is designed to produce apk packages to be used in apko.

The ko project builds Go projects from source in a similar manner to apko.

The kontain.me service creates fresh container images on demand using different forms of declarative configuration (including ko and apko).

Extension points exported contracts — how you extend this code

Authenticator (Interface)
Authenticator is an interface for types that can add HTTP basic auth to a request. [8 implementers]
pkg/apk/auth/auth.go
Generator (Interface)
Generator defines the interface for SBOM generators. [1 implementers]
pkg/sbom/generator/generator.go
BaseFS (Interface)
BaseFS is the required interfaces for an underlay filesystem which is used with VFS.
pkg/vfs/vfs.go
PublishOption (FuncType)
PublishOption is an option for publishing
internal/cli/options.go
ReaderFS (Interface)
ReaderFS is a filesystem that supports read-only operations. [4 implementers]
pkg/apk/fs/fs.go
GeneratorFactory (FuncType)
GeneratorFactory is a function that creates a Generator.
pkg/sbom/generator/generator.go
FullFS (Interface)
FullFS is a filesystem that supports all filesystem operations. [4 implementers]
pkg/apk/fs/fs.go
LocatablePackage (Interface)
LocatablePackage represents a minimal set of information needed to locate a package for retrieval over a network. [3 implementers]
pkg/apk/apk/package.go

Core symbols most depended-on inside this repo

Stat
called by 108
pkg/apk/fs/fs.go
MkdirAll
called by 100
pkg/apk/fs/fs.go
ReadFile
called by 94
pkg/apk/fs/fs.go
TempDir
called by 93
pkg/options/options.go
Error
called by 80
pkg/apk/apk/repo.go
WriteFile
called by 79
pkg/apk/fs/fs.go
Name
called by 66
pkg/apk/apk/repo.go
Open
called by 61
pkg/apk/fs/fs.go

Shape

Method 489
Function 438
Struct 148
Interface 21
FuncType 10
TypeAlias 9

Languages

Go100%

Modules by API surface

pkg/apk/fs/rwosfs.go55 symbols
pkg/tarfs/fs.go53 symbols
pkg/apk/apk/repo.go49 symbols
pkg/apk/fs/memfs.go48 symbols
pkg/apk/fs/fs.go41 symbols
pkg/apk/apk/implementation.go35 symbols
pkg/apk/expandapk/tarfs/tarfs.go32 symbols
pkg/sbom/generator/spdx/spdx.go31 symbols
pkg/vfs/vfs.go29 symbols
pkg/apk/apk/repo_test.go28 symbols
pkg/apk/fs/sub.go26 symbols
pkg/apk/fs/rwosfs_test.go26 symbols

Used by 1 indexed graphs manifest dependencies, hub-wide

For agents

$ claude mcp add apko \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact