werf has a built-in alternative syntax for describing assembly instructions called Stapel. Here are its distinctive features:
- Easily support and parameterize complex configurations, reuse common snippets and generate configurations of the images of the same type using YAML format and templating.
- Dedicated commands for integrating with Git to enable incremental rebuilds based on the Git repository history.
- Image inheritance and importing files from images (similar to the Dockerfile multi-stage mechanism).
- Run arbitrary build instructions, specify directory mount options, and use other advanced tools to build images.
- More efficient caching mechanics for layers (a similar scheme is supported for Dockerfile layers when building with Buildah (currently pre-alpha)).
To build images using the Stapel builder, you have to define build instructions in the werf.yaml
configuration file. Stapel is supported for both the Docker server builder backend (assembly via shell instructions or Ansible) and for Buildah (shell instructions only).
This section describes how to build images with the Stapel builder, its advanced features and how to use them.
A stage conveyor is an ordered sequence of conditions and rules for running stages. werf uses different stage conveyors to assemble various types of images, depending on their configuration.
For each stage at every build, werf calculates a unique stage identifier called stage digest.
If a stage has no stage dependencies, it is skipped, and the stage conveyor gets reduced by one stage as a result. This means that the stage conveyor can be reduced to several stages or even to a single from stage.
Stage dependency is a piece of data that affects the stage digest. Stage dependencies include:
- files from the Git repository with their contents;
- instructions to build stage defined in the
werf.yaml
; - an arbitrary string specified by the user in the
werf.yaml
; - and so on.
Most stage dependencies are specified in the werf.yaml
, others originate from the runtime.
The tables below illustrate dependencies of a Dockerfile image, a Stapel image, and a Stapel artifact stage dependencies.
Each row covers the dependencies for a certain stage.
The left column contains a brief description of the dependencies, the right column includes the related werf.yaml
directives and contains links to sections with more details.
stage dockerfile
image: <image name... || ~>
dockerfile: <relative path>
context: <relative path>
target: <docker stage name>
args:
<build arg name>: <value>
addHost:
- <host:ip>
stage from
from: <image[:<tag>]>
fromLatest: <bool>
fromCacheVersion: <arbitrary string>
fromImage: <image name>
mount:
- from: build_dir
to: <absolute or relative path>
- from: tmp_dir
to: <absolute path>
- fromPath: <absolute or relative path>
to: <absolute path>
stage beforeInstall
shell:
beforeInstall:
- <bash command>
cacheVersion: <arbitrary string>
beforeInstallCacheVersion: <arbitrary string>
or
ansible:
beforeInstall:
- <task>
cacheVersion: <arbitrary string>
beforeInstallCacheVersion: <arbitrary string>
stage dependenciesBeforeInstall
import:
- image: <image name>
before: install
add: <absolute path>
to: <absolute path>
owner: <owner>
group: <group>
includePaths:
- <relative path or glob>
excludePaths:
- <relative path or glob>
stage gitArchive
git:
- add: <absolute path>
to: <absolute path>
owner: <owner>
group: <group>
includePaths:
- <relative path or glob>
excludePaths:
- <relative path or glob>
- url: <git repo url>
branch: <branch name>
commit: <commit>
tag: <tag>
add: <absolute path>
to: <absolute path>
owner: <owner>
group: <group>
includePaths:
- <relative path or glob>
excludePaths:
- <relative path or glob>
stage install
git:
- stageDependencies:
install:
- <relative path or glob>
shell:
install:
- <bash command>
installCacheVersion: <arbitrary string>
or
ansible:
install:
- <task>
installCacheVersion: <arbitrary string>
stage dependenciesAfterInstall
import:
- image: <image name>
after: install
add: <absolute path>
to: <absolute path>
owner: <owner>
group: <group>
includePaths:
- <relative path or glob>
excludePaths:
- <relative path or glob>
stage beforeSetup
git:
- stageDependencies:
beforeSetup:
- <relative path or glob>
shell:
beforeSetup:
- <bash command>
beforeSetupCacheVersion: <arbitrary string>
or
ansible:
beforeSetup:
- <task>
beforeSetupCacheVersion: <arbitrary string>
stage dependenciesBeforeSetup
import:
- image: <image name>
before: setup
add: <absolute path>
to: <absolute path>
owner: <owner>
group: <group>
includePaths:
- <relative path or glob>
excludePaths:
- <relative path or glob>
stage setup
git:
- stageDependencies:
setup:
- <relative path or glob>
shell:
setup:
- <bash command>
setupCacheVersion: <arbitrary string>
or
ansible:
setup:
- <task>
setupCacheVersion: <arbitrary string>
stage gitCache
stage dependenciesAfterSetup
import:
- image: <image name>
after: setup
add: <absolute path>
to: <absolute path>
owner: <owner>
group: <group>
includePaths:
- <relative path or glob>
excludePaths:
- <relative path or glob>
stage gitLatestPatch
stage dockerInstructions
docker:
VOLUME:
- <volume>
EXPOSE:
- <expose>
ENV:
<env name>: <env value>
LABEL:
<label name>: <label value>
ENTRYPOINT: <entrypoint>
CMD: <cmd>
WORKDIR: <workdir>
USER: <user>
HEALTHCHECK: <healthcheck>