Skip to content

Allow building docker manifests having empty template values #5824

@caarlos0

Description

@caarlos0

Discussed in https://github.com/orgs/goreleaser/discussions/5822

Originally posted by zerospiel June 10, 2025
Hi all,

I am trying to build a new configuration for my CI, and I'd like to keep everything within a single config file instead of producing boilerplates. Having that said, I am struggling to implement something close to a conditional expression within the docker_manifests package section, having the following (simplified/trimmed) .goreleaser.yaml:

builds:
  - id: amd64
    env:
      - CGO_ENABLED=0
      - GO111MODULE=on
    goos:
      - linux
    goarch:
      - amd64
  - id: arm_and_arm64
    env:
      - CGO_ENABLED=0
      - GO111MODULE=on
    goos:
      - linux
    goarch:
      - arm
      - arm64
    goarm:
      - "7"
    builder: go
    # Here is the conditional skip
    skip: >-
      {{ if isEnvSet "SKIP_ARM" }}{{ true }}{{ else }}false{{ end }}

dockers:
  - id: linux-amd64
    goos: linux
    goarch: amd64
    image_templates:
      - "{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:{{ .Version }}-amd64"
    skip_push: false
    dockerfile: "goreleaser.dockerfile"
    use: buildx
    ids:
      - amd64
    build_flag_templates:
      - --platform=linux/amd64
  - id: linux-arm64
    goos: linux
    goarch: arm64
    image_templates:
      - "{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:{{ .Version }}-arm64v8"
    skip_push: false
    dockerfile: "goreleaser.dockerfile"
    use: buildx
    ids:
      - arm_and_arm64
    build_flag_templates:
      - --platform=linux/arm64/v8

docker_manifests:
  - name_template: '{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:{{ .Version }}'
    image_templates:
      - '{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:{{ .Version }}-amd64'
      # Here is my attempt to skip these images from being added to the manifest
      - >- 
        {{ if isEnvSet "SKIP_ARM" }}{{""}}{{ else }}{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:{{ .Version }}-arm64v8{{ end }}
      - >- 
        {{ if isEnvSet "SKIP_ARM" }}{{""}}{{ else }}{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:{{ .Version }}-armv7{{ end }}
    skip_push: false
    use: docker

So, here at the last lines, I have a list with ifs, what I want to achieve is to skip creating a manifest from non-existent digests (because the images from dockers will be skipped due to set ids section, which is done on purpose), but unfortunately, the current implementation does not skip empty image names after evaluating a template name.

Hence, my question is: am I doing it wrong, or is it worth adding an extra if statement to the line of code mentioned above?

Would appreciate any tips!

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions