github.com/GoogleContainerTools/skaffold/v2@v2.13.2/docs-v1/content/en/docs/tutorials/artifact-dependencies.md (about)

     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/main/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/main/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.