Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tag images with 'latest' and release tags #226

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pkg/konfluxgen/docker-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ spec:
description: Path to a file with build arguments for buildah, see https://www.mankier.com/1/buildah-build#--build-arg-file
name: build-args-file
type: string
- default: []
description: Additional image tags
name: additional-tags
type: array
results:
- description: ""
name: IMAGE_URL
Expand Down Expand Up @@ -393,6 +397,8 @@ spec:
params:
- name: IMAGE
value: $(tasks.build-container.results.IMAGE_URL)
- name: ADDITIONAL_TAGS
value: $(params.additional-tags)
runAfter:
- build-container
taskRef:
Expand Down
6 changes: 6 additions & 0 deletions pkg/konfluxgen/fbc-builder.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ spec:
description: Build a source image.
name: build-source-image
type: string
- default: []
description: Additional image tags
name: additional-tags
type: array
results:
- description: ""
name: IMAGE_URL
Expand Down Expand Up @@ -232,6 +236,8 @@ spec:
params:
- name: IMAGE
value: $(tasks.build-container.results.IMAGE_URL)
- name: ADDITIONAL_TAGS
value: $(params.additional-tags)
runAfter:
- build-container
taskRef:
Expand Down
6 changes: 5 additions & 1 deletion pkg/konfluxgen/konfluxgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func Generate(cfg Config) error {
}
}

applications[appKey][dockerfileComponentKey(cfg.ComponentNameFunc, c.ReleaseBuildConfiguration, ib)] = DockerfileApplicationConfig{
r := DockerfileApplicationConfig{
ApplicationName: cfg.ApplicationName,
ComponentName: Truncate(Sanitize(cfg.ComponentNameFunc(c.ReleaseBuildConfiguration, ib))),
ReleaseBuildConfiguration: c.ReleaseBuildConfiguration,
Expand All @@ -181,7 +181,9 @@ func Generate(cfg Config) error {
Nudges: append(cfg.Nudges, cfg.NudgesFunc(c.ReleaseBuildConfiguration, ib)...),
Pipeline: pipeline,
AdditionalTektonCELExpression: cfg.AdditionalTektonCELExpressionFunc(c.ReleaseBuildConfiguration, ib),
Tags: []string{"latest"},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I probably miss something, but just to be sure here: as we use the same pipeline for on-push and on-pr, wouldn't we tag images from PRs also with latest?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, the parameter is only added for push pipeline

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    {{{- if eq .Event "push" }}}
    - name: additional-tags
      value: [{{{ range $tag := .Tags }}} {{{ $tag }}}, {{{ end }}}]
    {{{- end }}}

Copy link
Member Author

@pierDipi pierDipi Sep 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example:

spec:
  params:
    - name: dockerfile
      value: olm-catalog/serverless-operator/index/Dockerfile
    - name: git-url
      value: '{{source_url}}'
    - name: image-expires-after
      value: 5d
    - name: output-image
      value: quay.io/redhat-user-workloads/ocp-serverless-tenant/serverless-operator-release-134/serverless-index:on-pr-{{revision}}
    - name: revision
      value: '{{revision}}'
  params:
    - name: dockerfile
      value: olm-catalog/serverless-operator/index/Dockerfile
    - name: git-url
      value: '{{source_url}}'
    - name: output-image
      value: quay.io/redhat-user-workloads/ocp-serverless-tenant/serverless-operator-release-134/serverless-index:{{revision}}
    - name: revision
      value: '{{revision}}'
    - name: additional-tags
      value: [ latest, ]

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we're injecting parameters for the pipeline run and we have one pipeline run per event (push and PR separate)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah nice 👍

}
applications[appKey][dockerfileComponentKey(cfg.ComponentNameFunc, c.ReleaseBuildConfiguration, ib)] = r
}
}

Expand Down Expand Up @@ -348,6 +350,8 @@ type DockerfileApplicationConfig struct {
AdditionalTektonCELExpression string
Event PipelineEvent
Pipeline Pipeline

Tags []string
}

type PipelineEvent string
Expand Down
4 changes: 4 additions & 0 deletions pkg/konfluxgen/pipeline-run.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ spec:
{{{- end }}}
- name: revision
value: '{{revision}}'
{{{- if eq .Event "push" }}}
- name: additional-tags
value: [{{{ range $tag := .Tags }}} {{{ $tag }}}, {{{ end }}}]
{{{- end }}}
pipelineRef:
name: {{{ .Pipeline }}}
taskRunTemplate: {}
Expand Down
Loading