-
Notifications
You must be signed in to change notification settings - Fork 24
Add support for RHEL 9 base images #790
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
Merged
openshift-merge-bot
merged 9 commits into
openshift-knative:main
from
dsimansk:pr/add-rhel-9-generator
Oct 7, 2025
Merged
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
dc87840
Add support for RHEL 9 base images
dsimansk 044e5e3
Use dnf in func image
dsimansk 8aec927
Switch default to rhel 9
dsimansk 051ce1f
Parse more version variatns
dsimansk 933e897
Improve version conditionals
dsimansk 1a9a209
Bump version to RHEL 9 in s-o config
dsimansk 81e9ce0
Free some diskspace
dsimansk f416cd3
Add disk cleanup to template
dsimansk 2fdd092
Fix gh action formatting
dsimansk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
pkg/dockerfilegen/dockerfile-templates/rhel-9/BuildImage.dockerfile.tmpl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| # DO NOT EDIT! Generated Dockerfile. | ||
|
|
||
| FROM registry.ci.openshift.org/ocp/4.19:cli-artifacts as tools | ||
|
|
||
| # Dockerfile to bootstrap build and test in openshift-ci | ||
| FROM {{.builder}} as builder | ||
|
|
||
| ARG TARGETARCH | ||
|
|
||
| COPY --from=tools /usr/share/openshift/linux_$TARGETARCH/oc.rhel9 /usr/bin/oc | ||
|
|
||
| RUN ln -s /usr/bin/oc /usr/bin/kubectl | ||
|
|
||
| RUN dnf install -y httpd-tools | ||
|
|
||
| RUN wget https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 && \ | ||
| chmod 700 ./get-helm-3 | ||
|
|
||
| RUN ./get-helm-3 --version v3.11.3 --no-sudo && helm version | ||
|
|
||
| RUN GOFLAGS='' go install github.com/mikefarah/yq/v3@latest | ||
| RUN GOFLAGS='' go install -tags="exclude_graphdriver_btrfs containers_image_openpgp" github.com/containers/skopeo/cmd/skopeo@v1.17.0 | ||
|
|
||
| # go install creates $GOPATH/.cache with root permissions, we delete it here | ||
| # to avoid permission issues with the runtime users | ||
| RUN rm -rf $GOPATH/.cache |
39 changes: 39 additions & 0 deletions
39
pkg/dockerfilegen/dockerfile-templates/rhel-9/Default.dockerfile.tmpl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| # DO NOT EDIT! Generated Dockerfile for {{.main}}. | ||
| ARG GO_BUILDER={{.builder}} | ||
| ARG GO_RUNTIME=registry.access.redhat.com/ubi9/ubi-minimal | ||
|
|
||
| FROM $GO_BUILDER as builder | ||
|
|
||
| WORKDIR /workspace | ||
| COPY . . | ||
| {{ range $c := .build_env_vars}} | ||
| ENV {{ $c }} | ||
| {{- end }} | ||
|
|
||
| RUN go build -tags strictfipsruntime -o /usr/bin/main ./{{.main}} | ||
|
|
||
| FROM $GO_RUNTIME | ||
|
|
||
| ARG VERSION={{.version}} | ||
|
|
||
| {{- range $c := .additional_instructions }} | ||
| {{ $c }} | ||
| {{- end }} | ||
|
|
||
| COPY --from=builder /usr/bin/main {{.app_file}} | ||
| COPY LICENSE /licenses/ | ||
|
|
||
| USER 65532 | ||
|
|
||
| LABEL \ | ||
| com.redhat.component="openshift-serverless-1-{{.project_dashcase}}{{.component_dashcase}}-rhel9-container" \ | ||
| name="openshift-serverless-1/{{.project_dashcase}}{{.component_dashcase}}-rhel8" \ | ||
| version=$VERSION \ | ||
| summary="Red Hat OpenShift Serverless 1 {{.project}}{{.component}}" \ | ||
| maintainer="serverless-support@redhat.com" \ | ||
| description="Red Hat OpenShift Serverless 1 {{.project}}{{.component}}" \ | ||
| io.k8s.display-name="Red Hat OpenShift Serverless 1 {{.project}}{{.component}}" \ | ||
| io.k8s.description="Red Hat OpenShift Serverless {{.project}}{{.component}}" \ | ||
| io.openshift.tags="{{.component_dashcase}}" | ||
|
|
||
| ENTRYPOINT ["{{.app_file}}"] |
46 changes: 46 additions & 0 deletions
46
pkg/dockerfilegen/dockerfile-templates/rhel-9/FuncUtil.dockerfile.tmpl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| # DO NOT EDIT! Generated Dockerfile for {{.main}}. | ||
| ARG GO_BUILDER={{.builder}} | ||
| ARG GO_RUNTIME=registry.access.redhat.com/ubi9/ubi-minimal | ||
|
|
||
| FROM $GO_BUILDER as builder | ||
|
|
||
| WORKDIR /workspace | ||
| COPY . . | ||
|
|
||
| ENV CGO_ENABLED=1 | ||
| ENV GOEXPERIMENT=strictfipsruntime | ||
| ENV GOFLAGS='' | ||
|
|
||
| RUN go build -tags strictfipsruntime,exclude_graphdriver_btrfs -o /usr/bin/main ./{{.main}} | ||
|
|
||
| FROM $GO_RUNTIME | ||
|
|
||
| ARG VERSION={{.version}} | ||
|
|
||
| RUN dnf install socat tar | ||
| {{- range $c := .additional_instructions }} | ||
| {{ $c }} | ||
| {{- end }} | ||
|
|
||
| COPY --from=builder /usr/bin/main {{.app_file}} | ||
| COPY LICENSE /licenses/ | ||
|
|
||
| RUN ln -s {{.app_file}} /usr/local/bin/deploy && \ | ||
| ln -s {{.app_file}} /usr/local/bin/scaffold && \ | ||
| ln -s {{.app_file}} /usr/local/bin/s2i && \ | ||
| ln -s {{.app_file}} /usr/local/bin/s2i-generate | ||
|
|
||
| USER 65532 | ||
|
|
||
| LABEL \ | ||
| com.redhat.component="openshift-serverless-1-{{.project_dashcase}}{{.component_dashcase}}-rhel9-container" \ | ||
| name="openshift-serverless-1/{{.project_dashcase}}{{.component_dashcase}}-rhel8" \ | ||
| version=$VERSION \ | ||
| summary="Red Hat OpenShift Serverless 1 {{.project}}{{.component}}" \ | ||
| maintainer="serverless-support@redhat.com" \ | ||
| description="Red Hat OpenShift Serverless 1 {{.project}}{{.component}}" \ | ||
| io.k8s.display-name="Red Hat OpenShift Serverless 1 {{.project}}{{.component}}" \ | ||
| io.k8s.description="Red Hat OpenShift Serverless {{.project}}{{.component}}" \ | ||
| io.openshift.tags="{{.component_dashcase}}" | ||
|
|
||
| ENTRYPOINT ["/usr/bin/bash"] |
35 changes: 35 additions & 0 deletions
35
pkg/dockerfilegen/dockerfile-templates/rhel-9/MustGather.dockerfile.tmpl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| # DO NOT EDIT! Generated Dockerfile for {{.main}}. | ||
| ARG CLI_ARTIFACTS={{ .oc_cli_artifacts }} | ||
| ARG RUNTIME=registry.access.redhat.com/ubi9/ubi-minimal | ||
| FROM $CLI_ARTIFACTS AS cli-artifacts | ||
|
|
||
| FROM $RUNTIME | ||
|
|
||
| ARG TARGETARCH | ||
|
|
||
| COPY --from=cli-artifacts /usr/share/openshift/linux_$TARGETARCH/{{ .oc_binary_name }} /usr/bin/oc | ||
|
|
||
| # Copy all collection scripts to /usr/bin | ||
| COPY must-gather/bin/* /usr/bin/ | ||
| COPY LICENSE /licenses/ | ||
|
|
||
| RUN microdnf install -y rsync tar | ||
|
|
||
| ENV LOGS_DIR="/must-gather" | ||
| RUN mkdir -p $LOGS_DIR && \ | ||
| chown -R 65532:65532 $LOGS_DIR | ||
|
|
||
| USER 65532 | ||
|
|
||
| LABEL \ | ||
| com.redhat.component="openshift-serverless-1-{{.project_dashcase}}rhel9-container" \ | ||
| name="openshift-serverless-1/svls-{{.project_dashcase}}rhel8" \ | ||
| version={{.version}} \ | ||
| summary="Red Hat OpenShift Serverless 1 {{.project}}" \ | ||
| maintainer="serverless-support@redhat.com" \ | ||
| description="Red Hat OpenShift Serverless 1 {{.project}}" \ | ||
| io.k8s.display-name="Red Hat OpenShift Serverless 1 {{.project}}" \ | ||
| io.k8s.description="Red Hat OpenShift Serverless {{.project}}" \ | ||
| io.openshift.tags="{{.main}}" | ||
|
|
||
| ENTRYPOINT /usr/bin/gather |
7 changes: 7 additions & 0 deletions
7
pkg/dockerfilegen/dockerfile-templates/rhel-9/SourceImage.dockerfile.tmpl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # DO NOT EDIT! Generated Dockerfile. | ||
|
|
||
| FROM src | ||
|
|
||
| RUN chmod +x vendor/k8s.io/code-generator/generate-groups.sh || true | ||
| RUN chmod +x vendor/knative.dev/pkg/hack/generate-knative.sh || true | ||
| RUN chmod +x vendor/k8s.io/code-generator/generate-internal-groups.sh || true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -152,9 +152,35 @@ func generateDockerfile(params Params, mainPackagesPaths sets.Set[string]) error | |
| goVersion = strings.Join(strings.Split(goVersion, ".")[0:2], ".") | ||
| } | ||
|
|
||
| metadata, err := project.ReadMetadataFile(params.ProjectFilePath) | ||
| if err != nil { | ||
| if !errors.Is(err, os.ErrNotExist) { | ||
| return fmt.Errorf("%w: Failed to read project metadata file: %w", | ||
| ErrBadConf, errors.WithStack(err)) | ||
| } | ||
| log.Println("File not found:", params.ProjectFilePath, "(Using defaults)") | ||
| metadata = project.DefaultMetadata() | ||
| } | ||
|
|
||
| rhelVersion := "rhel-9" | ||
| if metadata.Project.Tag != "" { | ||
| // tag before knative-v1.17 | ||
| minorVersion, err := strconv.Atoi(strings.Replace(metadata.Project.Tag, "knative-v1.", "", 1)) | ||
| if err != nil { | ||
| if minorVersion < 17 { | ||
| rhelVersion = "rhel-8" | ||
| } | ||
| } | ||
| } else { | ||
| // version before 1.37+ | ||
| if metadata.Project.Version == "1.36.1" || metadata.Project.Version == "1.35.1" { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we can use just the safer side if we do a patch release 1.36.2 or newer
|
||
| rhelVersion = "rhel-8" | ||
| } | ||
| } | ||
|
|
||
| builderImage := params.DockerfileImageBuilderFmt | ||
| if builderImage == "" { | ||
| builderImage = builderImageForGoVersion(goVersion) | ||
| builderImage = builderImageForGoVersion(goVersion, rhelVersion) | ||
| } else { | ||
| // Builder image might be provided without formatting '%s' string as plain value | ||
| if strings.Count(params.DockerfileImageBuilderFmt, "%s") == 1 { | ||
|
|
@@ -164,16 +190,6 @@ func generateDockerfile(params Params, mainPackagesPaths sets.Set[string]) error | |
|
|
||
| goPackageToImageMapping := map[string]string{} | ||
|
|
||
| metadata, err := project.ReadMetadataFile(params.ProjectFilePath) | ||
| if err != nil { | ||
| if !errors.Is(err, os.ErrNotExist) { | ||
| return fmt.Errorf("%w: Failed to read project metadata file: %w", | ||
| ErrBadConf, errors.WithStack(err)) | ||
| } | ||
| log.Println("File not found:", params.ProjectFilePath, "(Using defaults)") | ||
| metadata = project.DefaultMetadata() | ||
| } | ||
|
|
||
| d := map[string]interface{}{ | ||
| "builder": builderImage, | ||
| } | ||
|
|
@@ -248,20 +264,32 @@ func generateDockerfile(params Params, mainPackagesPaths sets.Set[string]) error | |
| var dockerfileTemplate embed.FS | ||
| var rpmsLockTemplate *embed.FS | ||
| if params.RpmsLockFileEnabled { | ||
| rpmsLockTemplate = &RPMsLockTemplateUbi8 | ||
| if rhelVersion == "rhel-8" { | ||
|
dsimansk marked this conversation as resolved.
Outdated
|
||
| rpmsLockTemplate = &RPMsLockTemplateUbi8 | ||
| } else { | ||
| rpmsLockTemplate = &RPMsLockTemplateUbi9 | ||
| } | ||
| } | ||
| switch params.TemplateName { | ||
| case DefaultDockerfileTemplateName: | ||
| dockerfileTemplate = DockerfileDefaultTemplate | ||
| case FuncUtilDockerfileTemplateName: | ||
| dockerfileTemplate = DockerfileFuncUtilTemplate | ||
| rpmsLockTemplate = &RPMsLockTemplateUbi8 | ||
| if rhelVersion == "rhel-8" { | ||
| rpmsLockTemplate = &RPMsLockTemplateUbi8 | ||
| } else { | ||
| rpmsLockTemplate = &RPMsLockTemplateUbi9 | ||
| } | ||
| default: | ||
| return fmt.Errorf("%w: Unknown template name: %s", | ||
| ErrBadConf, params.TemplateName) | ||
| } | ||
|
|
||
| t, err := template.ParseFS(dockerfileTemplate, "dockerfile-templates/*.tmpl") | ||
| templateFiles := "dockerfile-templates/*.tmpl" | ||
| if rhelVersion == "rhel-9" { | ||
| templateFiles = "dockerfile-templates/rhel-9/*.tmpl" | ||
| } | ||
| t, err := template.ParseFS(dockerfileTemplate, templateFiles) | ||
| if err != nil { | ||
| return fmt.Errorf("%w: Parsing failed: %w", | ||
| ErrBadTemplate, errors.WithStack(err)) | ||
|
|
@@ -573,19 +601,22 @@ func writeRPMLockFile(rpmsLockTemplate fs.FS, rootDir string) error { | |
| return nil | ||
| } | ||
|
|
||
| func builderImageForGoVersion(goVersion string) string { | ||
| builderImageFmt := "registry.ci.openshift.org/openshift/release:rhel-8-release-golang-%s-openshift-%s" | ||
| func builderImageForGoVersion(goVersion, rhelVersion string) string { | ||
| if rhelVersion == "" { | ||
| rhelVersion = "rhel-8" | ||
| } | ||
| builderImageFmt := "registry.ci.openshift.org/openshift/release:%s-release-golang-%s-openshift-%s" | ||
|
|
||
| switch goVersion { | ||
| case "1.21": | ||
| return fmt.Sprintf(builderImageFmt, goVersion, "4.16") | ||
| return fmt.Sprintf(builderImageFmt, rhelVersion, goVersion, "4.16") | ||
| case "1.22": | ||
| return fmt.Sprintf(builderImageFmt, goVersion, "4.17") | ||
| return fmt.Sprintf(builderImageFmt, rhelVersion, goVersion, "4.17") | ||
| case "1.23": | ||
| return fmt.Sprintf(builderImageFmt, goVersion, "4.19") | ||
| return fmt.Sprintf(builderImageFmt, rhelVersion, goVersion, "4.19") | ||
| case "1.24": | ||
| fallthrough | ||
| default: | ||
| return fmt.Sprintf(builderImageFmt, goVersion, "4.20") | ||
| return fmt.Sprintf(builderImageFmt, rhelVersion, goVersion, "4.20") | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| FROM registry.access.redhat.com/ubi9/ubi-minimal |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| contentOrigin: | ||
| # Define at least one source of packages, but you can have as many as you want. | ||
| repofiles: | ||
| # Either local path or url pointing to .repo file | ||
| - 'https://raw.githubusercontent.com/konflux-ci/bazel-builder/refs/heads/bazel8-ubi9/ubi9.repo' | ||
| packages: | ||
| # list of rpm names to resolve | ||
| - socat | ||
| - tar | ||
| - rsync | ||
|
|
||
| reinstallPackages: | ||
| - tzdata | ||
|
|
||
| upgradePackages: | ||
| - tzdata | ||
|
|
||
| arches: | ||
| # The list of architectures can be set in the config file. Any `--arch` option set | ||
| # on the command line will override this list. | ||
| - x86_64 | ||
| - aarch64 | ||
| - s390x | ||
| - ppc64le | ||
|
|
||
| context: | ||
| # Alternative to setting command line options. Usually you will only want | ||
| # to include one of these options, with the exception of `flatpak` that | ||
| # can be combined with `image` and `containerfile` | ||
| containerfile: ubi9.Containerfile |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we could also add the supposed RHEL version in the project.yaml file (maybe also easier for a potential RHEL 10 switch). In case the field would be empty (like in older SO versions), we could default to RHEL 8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could also be helpful on parts like
hack/pkg/dockerfilegen/generator.go
Lines 439 to 447 in 051ce1f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, it seemed quicker to hard code a few hacks in the current generator. But for the future and maintainability we should revisit it.