Version v1.39 of the documentation is no longer actively maintained. The site that you are currently viewing is an archived snapshot. For up-to-date documentation, see the latest version.
Defining dependencies between artifacts
This page describes how to define dependencies between artifacts and reference them in the docker builder.
Before you begin
First, you will need to have Skaffold and a Kubernetes cluster set up. To learn more about how to set up Skaffold and a Kubernetes cluster, see the quickstart docs.
Tutorial - Simple artifact dependency
This tutorial will be based on the simple-artifact-dependency example in our repository.
Adding an artifact dependency
We have a
base artifact which has a single Dockerfile that we build with the docker builder:
FROM alpine:3 COPY hello.txt . CMD ["./app"]
This artifact is used as the base image for the
app artifact. We express this dependency in the
skaffold.yaml using the
apiVersion: skaffold/v2beta9 kind: Config build: artifacts: - image: app context: app requires: - image: base alias: BASE - image: base context: base
The image alias
BASE is now available as a build-arg in the Dockerfile for
ARG BASE FROM golang:1.15-alpine as builder ... FROM $BASE COPY --from=builder /app .
Build and Deploy
In the simple-artifact-dependency directory, run:
If this is the first time you’re running this, then it should build the artifacts, starting with
base and later
app. Skaffold can handle any arbitrary dependency graph between artifacts and schedule builds in the right order. It’ll also report an error if it detects dependency cycles or self-loops.
Checking cache... - base: Not found. Building - app: Not found. Building Building [base]... <docker build logs here> Building [app]... <docker build logs here>
It will then deploy a single container pod, while also monitoring for file changes.
Watching for changes... [simple-artifact-dependency-app] Hello World [simple-artifact-dependency-app] Hello World
Modify the text in file
base/hello.txt to something else instead:
This will trigger a rebuild for the
base artifact, and since
app artifact depends on
base it’ll also trigger a rebuild for that. After deployment stabilizes, it should now show the logs reflecting this change:
Watching for changes... [simple-artifact-dependency-app] Hello World!!! [simple-artifact-dependency-app] Hello World!!!
Ctrl + C on a running Skaffold process should end it and cleanup its deployments. If there are still persisting objects then you can issue
skaffold delete command to attempt the cleanup again.