GoogleContainerTools / GoogleContainerTools/skaffold

Allow Reuse of Code Across Configs

Open
#6,921 4 comments 2 reactions 0 assignees View on GitHub
area/config kind/design discussion kind/feature-request priority/p2
Dominant language
Go
Stars
15.9k
Forks
1.7k
Avg merge
3d 9h
Merged PRs (30d)
10

Description

### Expected behavior
I would expect that blocks of code could propagate or be reused within "required" config modules.

### Actual behavior

When trying to break up a large skaffold config file into multiple configs (separate files), some of the reuse opportunities go away. Consider the following "monolith"

```yaml
apiVersion: skaffold/v2beta24
kind: Config
metadata:
name: monolith
build:
tagPolicy:
gitCommit:
variant: CommitSha
artifacts:
- image: artifact1
context: artifact1/
- image: artifact2
context: artifact2/
local:
useDockerCLI: true
useBuildkit: true
```
In this case, we can build two artifacts that share a common set of docker settings (**useDockerCLI** and **useBuildKit**).

As the complexity (and number of artifacts grows), we decide to get fancy and use configs!

```yaml
apiVersion: skaffold/v2beta24
kind: Config
metadata:
name: child1
build:
tagPolicy:
gitCommit:
variant: CommitSha
artifacts:
- image: artifact1
context: artifact1/
---
apiVersion: skaffold/v2beta24
kind: Config
metadata:
name: child2
build:
tagPolicy:
gitCommit:
variant: CommitSha
artifacts:
- image: artifact2
context: artifact2/
---
apiVersion: skaffold/v2beta24
kind: Config
metadata:
name: parent
requires:
- configs: [child1, child2]
build:
tagPolicy:
gitCommit:
variant: CommitSha
local:
useDockerCLI: true
useBuildkit: true
```
_Note: In real life, I would have moved child1 and child2 to separate files, but this is just for the sake of simplicty_
Now, I go to render the output
`skaffold diagnose --yaml-only -f skaffold-multi.yaml --module parent`

```yaml
apiVersion: skaffold/v2beta26
kind: Config
metadata:
name: child1
build:
artifacts:
- image: artifact1
context: /tmp/test/artifact1
docker:
dockerfile: Dockerfile
tagPolicy:
gitCommit: {}
local:
concurrency: 1
deploy:
logs:
prefix: container
---
apiVersion: skaffold/v2beta26
kind: Config
metadata:
name: child2
build:
artifacts:
- image: artifact2
context: /tmp/test/artifact2
docker:
dockerfile: Dockerfile
tagPolicy:
gitCommit: {}
local:
concurrency: 1
deploy:
logs:
prefix: container
---
apiVersion: skaffold/v2beta26
kind: Config
metadata:
name: parent
build:
tagPolicy:
gitCommit:
variant: CommitSha
local:
useDockerCLI: true
useBuildkit: true
deploy:
logs:
prefix: container
```
Uh-oh, I can see that the two children aren't using my `local` context for Docker (or my tagging strategy)....since they have their own `build` stanzas.

Things I have tried (unsuccessfully) as work-arounds
- **Patching `local` context into children configs from parent.** Unfortunately, this doesn't work since wildcard contexts aren't supported in JSONPATCH
- **Using a global YAML Anchore with "local" context** - I can't seem to get this to work as the parent's anchors don't seem to be available to the children/config

The only thing I have found that works is to copy the same config options into all of the children configs, which is
- Ugly and reduces readability of the config files
- Prone to Errors (did I remember to set Buildkit back to `false` everywhere?)

It's very possible that I am missing something obvious as I am fairly new to Skaffold, so any suggestions would be greatly appreciated!

### Information

- Skaffold version: v1.35.0
- Operating system: Ubuntu 18.04.6 LTS (Bionic)
- Installed via: Installed from releases page on Github

### Steps to reproduce the behavior

please see above

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.