Skip to content

Commit eace20c

Browse files
authored
Doc update; new example; new tutorial for artifact dependencies (#4971)
* add tutorial for `microservices` example with artifact dependencies * Fix test * update feature maturity.json * add new example and redo the tutorial. * Update doc for Docker builder
1 parent ba5bb69 commit eace20c

File tree

15 files changed

+178
-1
lines changed

15 files changed

+178
-1
lines changed

docs/content/en/docs/pipeline-stages/builders/docker.md

+8
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ Which is equivalent to:
4444

4545
{{% readfile file="samples/builders/local-full.yaml" %}}
4646

47+
**Artifact dependency**
48+
49+
You can additionally define dependency on other artifacts using the `requires` expression:
50+
51+
{{% readfile file="samples/builders/artifact-dependencies/docker-local.yaml" %}}
52+
53+
The specified alias `IMAGE2` becomes available as a build-arg in the Dockerfile for `image1` and it's value automatically set to the image built from `image2`.
54+
4755
## Dockerfile in-cluster with Kaniko
4856

4957
[Kaniko](https://github.com/GoogleContainerTools/kaniko) is a Google-developed

docs/content/en/docs/tutorials/_index.md

+1
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ Take a look at our other guides:
2626
| Detailed Tutorials |
2727
|--------------------|
2828
| [Custom Build Script]({{< relref "/docs/tutorials/custom-builder" >}}) |
29+
| [Build Artifact Dependencies]({{< relref "/docs/tutorials/artifact-dependencies" >}}) |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
---
2+
title: "Defining dependencies between artifacts"
3+
linkTitle: "Build Dependencies"
4+
weight: 100
5+
---
6+
7+
This page describes how to define dependencies between artifacts and reference them in the [docker builder]({{<relref "/docs/pipeline-stages/builders/docker" >}}).
8+
9+
## Before you begin
10+
11+
First, you will need to have Skaffold and a Kubernetes cluster set up.
12+
To learn more about how to set up Skaffold and a Kubernetes cluster, see the [quickstart docs]({{< relref "/docs/quickstart" >}}).
13+
14+
## Tutorial - Simple artifact dependency
15+
16+
This tutorial will be based on the [simple-artifact-dependency](https://github.com/GoogleContainerTools/skaffold/tree/master/examples/simple-artifact-dependency) example in our repository.
17+
18+
19+
## Adding an artifact dependency
20+
21+
We have a `base` artifact which has a single Dockerfile that we build with the [docker builder]({{<relref "/docs/pipeline-stages/builders/docker" >}}):
22+
{{% readfile file="samples/builders/artifact-dependencies/Dockerfile.base" %}}
23+
24+
This artifact is used as the base image for the `app` artifact. We express this dependency in the `skaffold.yaml` using the `requires` expression.
25+
{{% readfile file="samples/builders/artifact-dependencies/skaffold.yaml" %}}
26+
27+
The image alias `BASE` is now available as a build-arg in the Dockerfile for `app`:
28+
29+
{{% readfile file="samples/builders/artifact-dependencies/Dockerfile.app" %}}
30+
31+
## Build and Deploy
32+
33+
In the [simple-artifact-dependency](https://github.com/GoogleContainerTools/skaffold/tree/master/examples/simple-artifact-dependency) directory, run:
34+
35+
```text
36+
skaffold dev
37+
```
38+
39+
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.
40+
41+
```text
42+
Checking cache...
43+
- base: Not found. Building
44+
- app: Not found. Building
45+
46+
Building [base]...
47+
<docker build logs here>
48+
49+
Building [app]...
50+
<docker build logs here>
51+
```
52+
It will then deploy a single container pod, while also monitoring for file changes.
53+
54+
```text
55+
Watching for changes...
56+
[simple-artifact-dependency-app] Hello World
57+
[simple-artifact-dependency-app] Hello World
58+
```
59+
60+
Modify the text in file `base/hello.txt` to something else instead:
61+
62+
```text
63+
Hello World!!!
64+
```
65+
66+
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:
67+
68+
```text
69+
Watching for changes...
70+
[simple-artifact-dependency-app] Hello World!!!
71+
[simple-artifact-dependency-app] Hello World!!!
72+
```
73+
74+
## Cleanup
75+
76+
Hitting `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.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
ARG BASE
2+
FROM golang:1.12.9-alpine3.10 as builder
3+
...
4+
FROM $BASE
5+
COPY --from=builder /app .
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM alpine:3.10
2+
COPY hello.txt .
3+
CMD ["./app"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
build:
2+
artifacts:
3+
- image: image1
4+
requires:
5+
- image: image2
6+
alias: IMAGE2
7+
- image: image2
8+
local: {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: skaffold/v2beta9
2+
kind: Config
3+
build:
4+
artifacts:
5+
- image: app
6+
context: app
7+
requires:
8+
- image: base
9+
alias: BASE
10+
- image: base
11+
context: base

docs/data/maturity.json

+10
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@
2424
"maturity": "beta",
2525
"description": "build locally using a custom build script "
2626
},
27+
"build.dependencies": {
28+
"dev": "x",
29+
"build": "x",
30+
"run": "x",
31+
"debug": "x",
32+
"area": "Build",
33+
"feature": "Build Artifact Dependencies",
34+
"maturity": "alpha",
35+
"description": "Define build artifact dependencies"
36+
},
2737
"build": {
2838
"dev": "x",
2939
"build": "x",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
ARG BASE
2+
FROM golang:1.12.9-alpine3.10 as builder
3+
COPY main.go .
4+
5+
RUN go build -o /app .
6+
7+
FROM $BASE
8+
COPY --from=builder /app .
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
name: simple-artifact-dependency-app
5+
spec:
6+
containers:
7+
- name: simple-artifact-dependency-app
8+
image: app
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"io/ioutil"
6+
"time"
7+
)
8+
9+
func main() {
10+
dat, err := ioutil.ReadFile("hello.txt")
11+
if err != nil {
12+
panic(err)
13+
}
14+
15+
for {
16+
fmt.Println(string(dat))
17+
time.Sleep(time.Second * 1)
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM alpine:3.10
2+
COPY hello.txt .
3+
CMD ["./app"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hello World
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
apiVersion: skaffold/v2beta9
2+
kind: Config
3+
build:
4+
artifacts:
5+
- image: app
6+
context: app
7+
requires:
8+
- image: base
9+
alias: BASE
10+
- image: base
11+
context: base
12+
deploy:
13+
kubectl:
14+
manifests:
15+
- app/k8s-pod.yaml
16+

pkg/skaffold/schema/samples_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const (
3636
)
3737

3838
var (
39-
ignoredSamples = []string{"structureTest.yaml", "build.sh", "globalConfig.yaml"}
39+
ignoredSamples = []string{"structureTest.yaml", "build.sh", "globalConfig.yaml", "Dockerfile.app", "Dockerfile.base"}
4040
)
4141

4242
// Test that every example can be parsed and produces a valid

0 commit comments

Comments
 (0)