Build and push an image
Build the repository's Dockerfile, push the image to the branchd registry, and run a job in the image you built.
Available in repositories branchd reads pipeline files for. It is switching repositories on one at a time: until yours is, it keeps running its
.forge-ci.yamlor.xeonr-ci.yaml. See What is available.
# .branchd/pipelines/ci.yaml
# Test, then build the repository's Dockerfile and push the image to the
# branchd registry on pushes to main. The build job passes the image's
# reference on as an output.
name: CI
on:
push:
branches: [main]
pull_request:
jobs:
test:
image: golang:1.26
steps:
- run: go test ./...
build:
needs: [test]
if: branch == 'main' && event == 'push'
outputs:
image: ${{ steps.image.outputs.image }}
steps:
- id: image
uses: ci/image-build@1
with:
image: $CI_REGISTRY_IMAGE
tag: $CI_PIPELINE_IID
dockerfile: Dockerfile
smoke:
# build runs only on pushes to main, so smoke has the same if:. A need
# on a job that does not run is refused, unless it is optional: true.
if: branch == 'main' && event == 'push'
needs: [build]
# The job runs in the image the build job pushed.
image: ${{ needs.build.outputs.image }}
steps:
- run: /app/server --version
uses: ci/image-build@1is a typed step: a step that branchd provides, which runs in its own image. It buildsdockerfilefrom the checkout and pushesimage:tag. Its outputimageis the pushed reference,<image>:<tag>@<digest>.$CI_REGISTRY_IMAGEis this repository's path in the branchd registry, and$CI_PIPELINE_IIDthe run's number.$NAMEof a variable known when the run is compiled expands inwith:.- The job's
outputs:pass the step's output on. A job that needsbuildreads it as${{ needs.build.outputs.image }}, here as theimage:of the job that runs next. - The same
if:onbuildandsmoke:smokeneedsbuild, and a need on a job that does not run is refused. On a pull request neither runs.
As the job's only step, a typed step needs nothing more: the job is the
step, so it has no image: and no run: steps, and its if: goes on the
job. Among run: steps it must be marked isolated: true; see
Isolate a step from the job. A
job of its own, as here, is the simpler choice when the next step needs
only its output.
ci/image-build@1 takes image, tag and dockerfile (all required), and
build_args (a map of --build-arg values), push_latest and
build_mode. @1 is the newest 1.x.y; @1.0.1 is exact.