Skip to content

Support templating in build.artifacts.*.image #7455

Open
@dinvlad

Description

Expected behavior

I'm trying to create a skaffold.yaml config to be reused among multiple projects. Right now, the only blocker is inability to set build.artifacts.image via a template variable, like so:

apiVersion: skaffold/v2beta28
kind: Config
build:
  artifacts:
  - image: &name "{{.PROJECT}}"
    jib:
      project: *name
deploy:
  helm:
    releases:
    - name: *name
      chartPath: helm
      artifactOverrides:
        image: *name

which could work from a project directory using something like

PROJECT=$(basename $PWD) skaffold dev -f ../skaffold.yaml

Actual behavior

Instead, since template variables are not understood in build.artifacts.*.image, we have to either

  1. hard-code the image name and thus have a separate copy of skaffold.yaml for each individual project, or
  2. use an external template substitution tool, for example envsubst or gomplate to pre-process skaffold.yaml, like so:
PROJECT=$(basename $PWD) envsubst <../skaffold.yaml | skaffold dev -f -

Otherwise, Skaffold complains with a message like invalid image "{{.PROJECT}}": invalid reference format.

We cannot use --default-repo with a generic image for this use case either, since other values in the template depend on the image name and must be unique per-project (and they don't support {{.IMAGE_NAME}} either).

Information

  • Skaffold version: v1.38.0
  • Operating system: MacOS 12.4
  • Installed via: Homebrew Google Cloud SDK
  • Contents of skaffold.yaml: please see above

Steps to reproduce the behavior

  1. Create a Skaffold config similar to the above, with template variables in build.artifacts.*.image
  2. Use any Skaffold command with it
  3. Observe that template variables are not understood in build.artifacts.*.image

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions