GoogleContainerTools / skaffold

Easy and Repeatable Kubernetes Development
https://skaffold.dev/
Apache License 2.0
15.03k stars 1.62k forks source link

Allow Reuse of Code Across Configs #6921

Open adawalli opened 2 years ago

adawalli commented 2 years ago

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"

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!

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

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

The only thing I have found that works is to copy the same config options into all of the children configs, which is

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

Steps to reproduce the behavior

please see above

adawalli commented 2 years ago

I think I would even consider using a patch copy command in a pinch, but I don't think you can reference a "required" configs section in that way

adawalli commented 2 years ago

@briandealwis - let me know if I need to provide better clarification. Thanks!

briandealwis commented 2 years ago

This is great @adawalli. We've also heard people wanting to be able to:

tomasko-labuda commented 1 month ago

Hello, has this been somehow addressed in recent versions? Is there a way to share configuration between modules? E.g. If you have complex tag policy that you want to use in all modules, do you need to copy it to and maintain it across all the modules? Thank you.