Skip to content

Commit dc87840

Browse files
committed
Add support for RHEL 9 base images
1 parent 223dafc commit dc87840

11 files changed

Lines changed: 455 additions & 18 deletions

.github/workflows/release-discover-branches.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@ jobs:
7474
localhost/rpm-lockfile-prototype:latest \
7575
--outfile=${container_dir}/pkg/dockerfilegen/ubi8.rpms.lock.yaml \
7676
${container_dir}/pkg/dockerfilegen/ubi8.rpms.in.yaml || exit $?
77+
78+
podman run --privileged \
79+
--rm \
80+
-v ${PWD}:${container_dir} \
81+
localhost/rpm-lockfile-prototype:latest \
82+
--outfile=${container_dir}/pkg/dockerfilegen/ubi9.rpms.lock.yaml \
83+
${container_dir}/pkg/dockerfilegen/ubi9.rpms.in.yaml || exit $?
7784
7885
- name: Create Discovery Pull Request
7986
if: (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && github.ref_name == 'main'
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# DO NOT EDIT! Generated Dockerfile.
2+
3+
FROM registry.ci.openshift.org/ocp/4.19:cli-artifacts as tools
4+
5+
# Dockerfile to bootstrap build and test in openshift-ci
6+
FROM {{.builder}} as builder
7+
8+
ARG TARGETARCH
9+
10+
COPY --from=tools /usr/share/openshift/linux_$TARGETARCH/oc.rhel9 /usr/bin/oc
11+
12+
RUN ln -s /usr/bin/oc /usr/bin/kubectl
13+
14+
RUN dnf install -y httpd-tools
15+
16+
RUN wget https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 && \
17+
chmod 700 ./get-helm-3
18+
19+
RUN ./get-helm-3 --version v3.11.3 --no-sudo && helm version
20+
21+
RUN GOFLAGS='' go install github.com/mikefarah/yq/v3@latest
22+
RUN GOFLAGS='' go install -tags="exclude_graphdriver_btrfs containers_image_openpgp" github.com/containers/skopeo/cmd/skopeo@v1.17.0
23+
24+
# go install creates $GOPATH/.cache with root permissions, we delete it here
25+
# to avoid permission issues with the runtime users
26+
RUN rm -rf $GOPATH/.cache
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# DO NOT EDIT! Generated Dockerfile for {{.main}}.
2+
ARG GO_BUILDER={{.builder}}
3+
ARG GO_RUNTIME=registry.access.redhat.com/ubi9/ubi-minimal
4+
5+
FROM $GO_BUILDER as builder
6+
7+
WORKDIR /workspace
8+
COPY . .
9+
{{ range $c := .build_env_vars}}
10+
ENV {{ $c }}
11+
{{- end }}
12+
13+
RUN go build -tags strictfipsruntime -o /usr/bin/main ./{{.main}}
14+
15+
FROM $GO_RUNTIME
16+
17+
ARG VERSION={{.version}}
18+
19+
{{- range $c := .additional_instructions }}
20+
{{ $c }}
21+
{{- end }}
22+
23+
COPY --from=builder /usr/bin/main {{.app_file}}
24+
COPY LICENSE /licenses/
25+
26+
USER 65532
27+
28+
LABEL \
29+
com.redhat.component="openshift-serverless-1-{{.project_dashcase}}{{.component_dashcase}}-rhel9-container" \
30+
name="openshift-serverless-1/{{.project_dashcase}}{{.component_dashcase}}-rhel8" \
31+
version=$VERSION \
32+
summary="Red Hat OpenShift Serverless 1 {{.project}}{{.component}}" \
33+
maintainer="serverless-support@redhat.com" \
34+
description="Red Hat OpenShift Serverless 1 {{.project}}{{.component}}" \
35+
io.k8s.display-name="Red Hat OpenShift Serverless 1 {{.project}}{{.component}}" \
36+
io.k8s.description="Red Hat OpenShift Serverless {{.project}}{{.component}}" \
37+
io.openshift.tags="{{.component_dashcase}}"
38+
39+
ENTRYPOINT ["{{.app_file}}"]
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# DO NOT EDIT! Generated Dockerfile for {{.main}}.
2+
ARG GO_BUILDER={{.builder}}
3+
ARG GO_RUNTIME=registry.access.redhat.com/ubi9/ubi-minimal
4+
5+
FROM $GO_BUILDER as builder
6+
7+
WORKDIR /workspace
8+
COPY . .
9+
10+
ENV CGO_ENABLED=1
11+
ENV GOEXPERIMENT=strictfipsruntime
12+
ENV GOFLAGS=''
13+
14+
RUN go build -tags strictfipsruntime,exclude_graphdriver_btrfs -o /usr/bin/main ./{{.main}}
15+
16+
FROM $GO_RUNTIME
17+
18+
ARG VERSION={{.version}}
19+
20+
RUN microdnf install socat tar
21+
{{- range $c := .additional_instructions }}
22+
{{ $c }}
23+
{{- end }}
24+
25+
COPY --from=builder /usr/bin/main {{.app_file}}
26+
COPY LICENSE /licenses/
27+
28+
RUN ln -s {{.app_file}} /usr/local/bin/deploy && \
29+
ln -s {{.app_file}} /usr/local/bin/scaffold && \
30+
ln -s {{.app_file}} /usr/local/bin/s2i && \
31+
ln -s {{.app_file}} /usr/local/bin/s2i-generate
32+
33+
USER 65532
34+
35+
LABEL \
36+
com.redhat.component="openshift-serverless-1-{{.project_dashcase}}{{.component_dashcase}}-rhel9-container" \
37+
name="openshift-serverless-1/{{.project_dashcase}}{{.component_dashcase}}-rhel8" \
38+
version=$VERSION \
39+
summary="Red Hat OpenShift Serverless 1 {{.project}}{{.component}}" \
40+
maintainer="serverless-support@redhat.com" \
41+
description="Red Hat OpenShift Serverless 1 {{.project}}{{.component}}" \
42+
io.k8s.display-name="Red Hat OpenShift Serverless 1 {{.project}}{{.component}}" \
43+
io.k8s.description="Red Hat OpenShift Serverless {{.project}}{{.component}}" \
44+
io.openshift.tags="{{.component_dashcase}}"
45+
46+
ENTRYPOINT ["/usr/bin/bash"]
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# DO NOT EDIT! Generated Dockerfile for {{.main}}.
2+
ARG CLI_ARTIFACTS={{ .oc_cli_artifacts }}
3+
ARG RUNTIME=registry.access.redhat.com/ubi9/ubi-minimal
4+
FROM $CLI_ARTIFACTS AS cli-artifacts
5+
6+
FROM $RUNTIME
7+
8+
ARG TARGETARCH
9+
10+
COPY --from=cli-artifacts /usr/share/openshift/linux_$TARGETARCH/{{ .oc_binary_name }} /usr/bin/oc
11+
12+
# Copy all collection scripts to /usr/bin
13+
COPY must-gather/bin/* /usr/bin/
14+
COPY LICENSE /licenses/
15+
16+
RUN microdnf install -y rsync tar
17+
18+
ENV LOGS_DIR="/must-gather"
19+
RUN mkdir -p $LOGS_DIR && \
20+
chown -R 65532:65532 $LOGS_DIR
21+
22+
USER 65532
23+
24+
LABEL \
25+
com.redhat.component="openshift-serverless-1-{{.project_dashcase}}rhel9-container" \
26+
name="openshift-serverless-1/svls-{{.project_dashcase}}rhel8" \
27+
version={{.version}} \
28+
summary="Red Hat OpenShift Serverless 1 {{.project}}" \
29+
maintainer="serverless-support@redhat.com" \
30+
description="Red Hat OpenShift Serverless 1 {{.project}}" \
31+
io.k8s.display-name="Red Hat OpenShift Serverless 1 {{.project}}" \
32+
io.k8s.description="Red Hat OpenShift Serverless {{.project}}" \
33+
io.openshift.tags="{{.main}}"
34+
35+
ENTRYPOINT /usr/bin/gather
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# DO NOT EDIT! Generated Dockerfile.
2+
3+
FROM src
4+
5+
RUN chmod +x vendor/k8s.io/code-generator/generate-groups.sh || true
6+
RUN chmod +x vendor/knative.dev/pkg/hack/generate-knative.sh || true
7+
RUN chmod +x vendor/k8s.io/code-generator/generate-internal-groups.sh || true

pkg/dockerfilegen/generator.go

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,27 @@ func generateDockerfile(params Params, mainPackagesPaths sets.Set[string]) error
152152
goVersion = strings.Join(strings.Split(goVersion, ".")[0:2], ".")
153153
}
154154

155+
metadata, err := project.ReadMetadataFile(params.ProjectFilePath)
156+
if err != nil {
157+
if !errors.Is(err, os.ErrNotExist) {
158+
return fmt.Errorf("%w: Failed to read project metadata file: %w",
159+
ErrBadConf, errors.WithStack(err))
160+
}
161+
log.Println("File not found:", params.ProjectFilePath, "(Using defaults)")
162+
metadata = project.DefaultMetadata()
163+
}
164+
165+
rhelVersion := "rhel-8"
166+
minorVersion, err := strconv.Atoi(strings.Replace(metadata.Project.Tag, "knative-v1.", "", 1))
167+
if err != nil {
168+
if minorVersion >= 17 {
169+
rhelVersion = "rhel-9"
170+
}
171+
}
172+
155173
builderImage := params.DockerfileImageBuilderFmt
156174
if builderImage == "" {
157-
builderImage = builderImageForGoVersion(goVersion)
175+
builderImage = builderImageForGoVersion(goVersion, rhelVersion)
158176
} else {
159177
// Builder image might be provided without formatting '%s' string as plain value
160178
if strings.Count(params.DockerfileImageBuilderFmt, "%s") == 1 {
@@ -164,16 +182,6 @@ func generateDockerfile(params Params, mainPackagesPaths sets.Set[string]) error
164182

165183
goPackageToImageMapping := map[string]string{}
166184

167-
metadata, err := project.ReadMetadataFile(params.ProjectFilePath)
168-
if err != nil {
169-
if !errors.Is(err, os.ErrNotExist) {
170-
return fmt.Errorf("%w: Failed to read project metadata file: %w",
171-
ErrBadConf, errors.WithStack(err))
172-
}
173-
log.Println("File not found:", params.ProjectFilePath, "(Using defaults)")
174-
metadata = project.DefaultMetadata()
175-
}
176-
177185
d := map[string]interface{}{
178186
"builder": builderImage,
179187
}
@@ -261,7 +269,11 @@ func generateDockerfile(params Params, mainPackagesPaths sets.Set[string]) error
261269
ErrBadConf, params.TemplateName)
262270
}
263271

264-
t, err := template.ParseFS(dockerfileTemplate, "dockerfile-templates/*.tmpl")
272+
templateFiles := "dockerfile-templates/*.tmpl"
273+
if rhelVersion == "rhel-9" {
274+
templateFiles = "dockerfile-templates/rhel-9/*.tmpl"
275+
}
276+
t, err := template.ParseFS(dockerfileTemplate, templateFiles)
265277
if err != nil {
266278
return fmt.Errorf("%w: Parsing failed: %w",
267279
ErrBadTemplate, errors.WithStack(err))
@@ -573,19 +585,22 @@ func writeRPMLockFile(rpmsLockTemplate fs.FS, rootDir string) error {
573585
return nil
574586
}
575587

576-
func builderImageForGoVersion(goVersion string) string {
577-
builderImageFmt := "registry.ci.openshift.org/openshift/release:rhel-8-release-golang-%s-openshift-%s"
588+
func builderImageForGoVersion(goVersion, rhelVersion string) string {
589+
if rhelVersion == "" {
590+
rhelVersion = "rhel-8"
591+
}
592+
builderImageFmt := "registry.ci.openshift.org/openshift/release:%s-release-golang-%s-openshift-%s"
578593

579594
switch goVersion {
580595
case "1.21":
581-
return fmt.Sprintf(builderImageFmt, goVersion, "4.16")
596+
return fmt.Sprintf(builderImageFmt, rhelVersion, goVersion, "4.16")
582597
case "1.22":
583-
return fmt.Sprintf(builderImageFmt, goVersion, "4.17")
598+
return fmt.Sprintf(builderImageFmt, rhelVersion, goVersion, "4.17")
584599
case "1.23":
585-
return fmt.Sprintf(builderImageFmt, goVersion, "4.19")
600+
return fmt.Sprintf(builderImageFmt, rhelVersion, goVersion, "4.19")
586601
case "1.24":
587602
fallthrough
588603
default:
589-
return fmt.Sprintf(builderImageFmt, goVersion, "4.20")
604+
return fmt.Sprintf(builderImageFmt, rhelVersion, goVersion, "4.20")
590605
}
591606
}

pkg/dockerfilegen/templates.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,6 @@ var DockerfileMustGatherTemplate embed.FS
1919

2020
//go:embed ubi8.rpms.lock.yaml
2121
var RPMsLockTemplateUbi8 embed.FS
22+
23+
//go:embed ubi9.rpms.lock.yaml
24+
var RPMsLockTemplateUbi9 embed.FS
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
FROM registry.access.redhat.com/ubi9/ubi-minimal
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
contentOrigin:
2+
# Define at least one source of packages, but you can have as many as you want.
3+
repofiles:
4+
# Either local path or url pointing to .repo file
5+
- 'https://raw.githubusercontent.com/konflux-ci/bazel-builder/refs/heads/bazel8-ubi9/ubi9.repo'
6+
packages:
7+
# list of rpm names to resolve
8+
- socat
9+
- tar
10+
- rsync
11+
12+
reinstallPackages:
13+
- tzdata
14+
15+
upgradePackages:
16+
- tzdata
17+
18+
arches:
19+
# The list of architectures can be set in the config file. Any `--arch` option set
20+
# on the command line will override this list.
21+
- x86_64
22+
- aarch64
23+
- s390x
24+
- ppc64le
25+
26+
context:
27+
# Alternative to setting command line options. Usually you will only want
28+
# to include one of these options, with the exception of `flatpak` that
29+
# can be combined with `image` and `containerfile`
30+
containerfile: ubi9.Containerfile

0 commit comments

Comments
 (0)