hammerkit

docker

Build a Docker image from a Dockerfile and push it, using the Docker of the machine hammerkit runs on.

Build a Docker image from a Dockerfile and push it, using the Docker of the machine hammerkit runs on. build builds the image into the local Docker, publish builds it and pushes it to its registry. Both are local tasks that call docker, so Docker has to be installed and running where you run hammerkit.

.hammerkit.yaml
includes:
  docker:
    git: https://github.com/no0dles/hammerkit.git
    ref: v1.21.0
    path: catalog/docker
    with:
      IMAGE: ghcr.io/acme/hello
      IMAGE_TAG: ${VERSION:-dev}

tasks:
  release:
    deps: [docker:publish]

Tasks

TaskWhat it doesReadsProduces
buildBuild the image and tag it IMAGE:IMAGE_TAG in the local Docker.the image
publishBuild the image for PLATFORMS and push it.the image in its registry

Neither task declares src or generates, so both run every time. The image lives in Docker, not in a folder hammerkit can check, and Docker's own layer cache makes a rebuild of an unchanged context fast.

publish does not log in. Log in before you run it, with docker login or your CI's login step, preferably with a short-lived token of a service account rather than a personal login. The credentials stay in Docker's config and never reach the build file.

Inputs

InputDefaultMeaning
IMAGEappThe image name, including the registry (ghcr.io/acme/app).
IMAGE_TAGdevThe tag of the image. Take it from the environment with ${VERSION:-dev} in with, as above, and run VERSION=1.0.0 hammerkit release.
DOCKERFILEDockerfileThe Dockerfile to build, relative to the working directory.
CONTEXT.The build context, relative to the working directory.
PLATFORMSlinux/amd64The platforms publish builds, comma separated, for example linux/amd64,linux/arm64. More than one needs a builder that supports multi-platform images.

The entry

catalog/docker/build.yaml
# Builds a Docker image with the Docker of the machine running hammerkit, and pushes it.
envs:
  # the image name, including the registry (ghcr.io/acme/app)
  IMAGE: app
  # the tag of the image
  IMAGE_TAG: dev
  # the Dockerfile to build, relative to the working directory
  DOCKERFILE: Dockerfile
  # the build context, relative to the working directory
  CONTEXT: .
  # the platforms to push, comma separated
  PLATFORMS: linux/amd64

tasks:
  build:
    description: build the image into the local Docker
    cmds:
      - docker build --file ${DOCKERFILE} --tag ${IMAGE}:${IMAGE_TAG} ${CONTEXT}

  publish:
    description: build the image and push it to its registry
    cmds:
      - docker buildx build --file ${DOCKERFILE} --platform ${PLATFORMS} --tag ${IMAGE}:${IMAGE_TAG} --push ${CONTEXT}

On this page