Skip to content

Commit b1d622c

Browse files
committed
test/e2e: add dockerfile-inputs
1 parent 020a23b commit b1d622c

File tree

8 files changed

+145
-0
lines changed

8 files changed

+145
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
base_images:
2+
os:
3+
name: ubi-minimal
4+
namespace: ocp
5+
tag: '9'
6+
build_root:
7+
image_stream_tag:
8+
namespace: ocp
9+
name: ubi-minimal
10+
tag: '9'
11+
resources:
12+
'*':
13+
requests:
14+
cpu: 10m
15+
images:
16+
- dockerfile_path: testdata/Dockerfile.single
17+
to: auto-detect-single
18+
- dockerfile_path: testdata/Dockerfile.multiple
19+
to: auto-detect-multiple
20+
- dockerfile_path: testdata/Dockerfile.quay-proxy
21+
to: auto-detect-quay-proxy
22+
- dockerfile_path: testdata/Dockerfile.manual
23+
inputs:
24+
os:
25+
as:
26+
- registry.ci.openshift.org/ocp/4.19:base
27+
to: manual-inputs
28+
- dockerfile_path: testdata/Dockerfile.copy-from
29+
to: auto-detect-copy-from
30+
- dockerfile_path: testdata/Dockerfile.no-refs
31+
to: no-registry-refs
32+
zz_generated_metadata:
33+
branch: main
34+
org: openshift
35+
repo: konflux-tasks
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
//go:build e2e
2+
// +build e2e
3+
4+
package dockerfile_inputs
5+
6+
import (
7+
"testing"
8+
9+
"github.com/openshift/ci-tools/test/e2e/framework"
10+
)
11+
12+
func TestDockerfileInputs(t *testing.T) {
13+
const defaultJobSpec = `{"type":"postsubmit","job":"branch-ci-test-test-master-dockerfile-inputs","buildid":"0","prowjobid":"uuid","refs":{"org":"test","repo":"test","base_ref":"master","base_sha":"6d231cc37652e85e0f0e25c21088b73d644d89ad","pulls":[]},"decoration_config":{"timeout":"4h0m0s","grace_period":"30m0s","utility_images":{"clonerefs":"quay-proxy.ci.openshift.org/openshift/ci:ci_clonerefs_latest","initupload":"quay-proxy.ci.openshift.org/openshift/ci:ci_initupload_latest","entrypoint":"quay-proxy.ci.openshift.org/openshift/ci:ci_entrypoint_latest","sidecar":"quay-proxy.ci.openshift.org/openshift/ci:ci_sidecar_latest"},"resources":{"clonerefs":{"limits":{"memory":"3Gi"},"requests":{"cpu":"100m","memory":"500Mi"}},"initupload":{"limits":{"memory":"200Mi"},"requests":{"cpu":"100m","memory":"50Mi"}},"place_entrypoint":{"limits":{"memory":"100Mi"},"requests":{"cpu":"100m","memory":"25Mi"}},"sidecar":{"limits":{"memory":"2Gi"},"requests":{"cpu":"100m","memory":"250Mi"}}},"gcs_configuration":{"bucket":"test-platform-results","path_strategy":"single","default_org":"openshift","default_repo":"origin","mediaTypes":{"log":"text/plain"}},"gcs_credentials_secret":"gce-sa-credentials-gcs-publisher"}}`
14+
15+
var testCases = []struct {
16+
name string
17+
args []string
18+
success bool
19+
output []string
20+
}{
21+
{
22+
name: "auto-detect single registry.ci.openshift.org reference",
23+
args: []string{"--target=auto-detect-single"},
24+
success: true,
25+
output: []string{
26+
"Dockerfile-inputs: Detected registry reference",
27+
"registry.ci.openshift.org/ocp/4.19:base",
28+
},
29+
},
30+
{
31+
name: "auto-detect multiple registry references",
32+
args: []string{"--target=auto-detect-multiple"},
33+
success: true,
34+
output: []string{
35+
"Dockerfile-inputs: Detected registry reference",
36+
"registry.ci.openshift.org/ocp/4.19:base",
37+
"registry.ci.openshift.org/ocp/builder:rhel-9-golang-1.22-openshift-4.19",
38+
},
39+
},
40+
{
41+
name: "auto-detect with quay-proxy reference",
42+
args: []string{"--target=auto-detect-quay-proxy"},
43+
success: true,
44+
output: []string{
45+
"Dockerfile-inputs: Detected registry reference",
46+
"quay-proxy.ci.openshift.org/openshift/ci:ocp_builder_rhel-9-golang-1.22-openshift-4.19",
47+
},
48+
},
49+
{
50+
name: "skip auto-detect when manual inputs.as defined",
51+
args: []string{"--target=manual-inputs"},
52+
success: true,
53+
output: []string{
54+
"Skipping Dockerfile inputs detection: manual inputs defined",
55+
"registry.ci.openshift.org/ocp/4.19:base",
56+
},
57+
},
58+
{
59+
name: "auto-detect with COPY --from reference",
60+
args: []string{"--target=auto-detect-copy-from"},
61+
success: true,
62+
output: []string{
63+
"Dockerfile-inputs: Detected registry reference",
64+
"registry.ci.openshift.org/ocp/4.19:base",
65+
},
66+
},
67+
{
68+
name: "no auto-detect when no registry references",
69+
args: []string{"--target=no-registry-refs"},
70+
success: true,
71+
output: []string{},
72+
},
73+
}
74+
75+
for _, testCase := range testCases {
76+
testCase := testCase
77+
framework.Run(t, testCase.name, func(t *framework.T, cmd *framework.CiOperatorCommand) {
78+
cmd.AddArgs(framework.LocalPullSecretFlag(t), framework.RemotePullSecretFlag(t))
79+
cmd.AddArgs(append(testCase.args, "--config=config.yaml")...)
80+
cmd.AddEnv("JOB_SPEC=" + defaultJobSpec)
81+
output, err := cmd.Run()
82+
if testCase.success != (err == nil) {
83+
t.Fatalf("%s: didn't expect an error from ci-operator: %v; output:\n%v", testCase.name, err, string(output))
84+
}
85+
if len(testCase.output) > 0 {
86+
cmd.VerboseOutputContains(t, testCase.name, testCase.output...)
87+
}
88+
})
89+
}
90+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM alpine:latest AS stage1
2+
RUN echo "First stage"
3+
4+
FROM registry.ci.openshift.org/ocp/4.19:base
5+
COPY --from=stage1 /etc/os-release /tmp/
6+
RUN echo "Testing COPY --from"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
FROM registry.ci.openshift.org/ocp/4.19:base
2+
RUN echo "This has manual inputs.as defined, should skip auto-detect"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM registry.ci.openshift.org/ocp/builder:rhel-9-golang-1.22-openshift-4.19 AS builder
2+
RUN echo "Build stage"
3+
4+
FROM registry.ci.openshift.org/ocp/4.19:base
5+
COPY --from=builder /app /app
6+
RUN echo "Final stage"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
FROM alpine:latest
2+
RUN echo "No registry.ci.openshift.org references here"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
FROM quay-proxy.ci.openshift.org/openshift/ci:ocp_builder_rhel-9-golang-1.22-openshift-4.19
2+
RUN echo "Testing quay-proxy auto-detect"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
FROM registry.ci.openshift.org/ocp/4.19:base
2+
RUN echo "Testing single auto-detect"

0 commit comments

Comments
 (0)