-
Notifications
You must be signed in to change notification settings - Fork 133
Expand file tree
/
Copy pathmocks.sh
More file actions
183 lines (167 loc) · 7.29 KB
/
Copy pathmocks.sh
File metadata and controls
183 lines (167 loc) · 7.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/usr/bin/env bash
set -eux
# mocks to be injected into task step scripts
function date() {
echo $* >> $(params.dataDir)/mock_date.txt
case "$*" in
*"2024-07-29T02:17:29 +%Y-%m-%d")
echo "2024-07-29"
;;
*"+%Y%m%d %T")
echo "19800101 00:00:00"
;;
*"+%s")
echo "315550800"
;;
*"+%Y-%m-%d")
echo "1980-01-01"
;;
*"+%Y-%m")
echo "1980-01"
;;
*"+%Y.%m.%d")
echo "2024.07.29"
;;
"*")
echo Error: Unexpected call
exit 1
;;
esac
}
function skopeo() {
echo Mock skopeo called with: $* >&2
echo $* >> $(params.dataDir)/mock_skopeo.txt
if [[ "$*" =~ list-tags\ --retry-times\ 3\ docker://repo1 ]]; then
echo '{"Tags": ["v2.0.0-4", "v2.0.0-3", "v2.0.0-2"]}'
return
fi
if [[ "$*" =~ list-tags\ --retry-times\ 3\ docker://(repoa|repo2) ]]; then
echo '{"Tags": []}'
return
fi
# mixed timestamp and incrementer tags: timestamps ignored, increments from 135
if [[ "$*" =~ list-tags\ --retry-times\ 3\ docker://repo-timestamp-mixed ]]; then
echo '{"Tags": ["1.2.1", "1.2.1-26", "1.2.1-67", "1.2.1-135", "1.2.1-1737653481", "1.2.1-1740048934", "1.2.1-1745398585"]}'
return
fi
# component-incrementer test repos: repo-ci-a has max 3, repo-ci-b has max 5 → global max 5 → next 6
if [[ "$*" =~ list-tags\ --retry-times\ 3\ docker://repo-ci-a ]]; then
echo '{"Tags": ["v1.0.0-1", "v1.0.0-2", "v1.0.0-3"]}'
return
fi
if [[ "$*" =~ list-tags\ --retry-times\ 3\ docker://repo-ci-b ]]; then
echo '{"Tags": ["v1.0.0-1", "v1.0.0-2", "v1.0.0-3", "v1.0.0-4", "v1.0.0-5"]}'
return
fi
# component-incrementer single-repo test: repo-ci-c has max 3 → next 4
if [[ "$*" =~ list-tags\ --retry-times\ 3\ docker://repo-ci-c ]]; then
echo '{"Tags": ["v2.0.0-1", "v2.0.0-2", "v2.0.0-3"]}'
return
fi
# 7 digit tags: ignored by {1,6} regex, incrementer starts at 1
if [[ "$*" =~ list-tags\ --retry-times\ 3\ docker://repo-leadingzero ]]; then
echo '{"Tags": ["v0.7.0-0760387", "v0.7.0-0760386"]}'
return
fi
# Leading 0 with invalid octal digit: 10# fix prevents octal error
if [[ "$*" =~ list-tags\ --retry-times\ 3\ docker://repo-octal ]]; then
echo '{"Tags": ["v1.0.0-08", "v1.0.0-07"]}'
return
fi
# Existing repo that transiently returns empty tags (simulates the bug scenario)
if [[ "$*" =~ list-tags\ --retry-times\ 3\ docker://repo-empty-tags-existing ]]; then
echo '{"Tags": []}'
return
fi
# Raw manifest inspections (for annotations and config.mediaType) - these use the digest from get-image-architectures
if [[ "$*" == "inspect --retry-times 3 --no-tags --raw docker://quay.io/myorg/helm-chart"* ]]
then
# Helm chart - has helm config mediaType, not a standard container image
echo '{"config": {"mediaType": "application/vnd.cncf.helm.config.v1+json"}, "annotations": {"org.opencontainers.image.version": "2.0.1+alpha", "org.opencontainers.image.created": "2024-07-29T02:17:29Z"}}'
return
elif [[ "$*" == "inspect --retry-times 3 --no-tags --raw docker://quay.io/myorg/web-app"* ]]
then
echo '{"config": {"mediaType": "application/vnd.oci.image.config.v1+json"}, "annotations": {"org.opencontainers.image.version": "1.2.3-beta", "org.opencontainers.image.created": "2024-07-29T02:17:29Z"}}'
return
elif [[ "$*" == "inspect --retry-times 3 --no-tags --raw docker://registry.io/metadata"* ]]
then
echo '{"config": {"mediaType": "application/vnd.oci.image.config.v1+json"}, "annotations": {"org.opencontainers.image.created": "2024-07-29T02:17:29Z"}}'
return
elif [[ "$*" == "inspect --retry-times 3 --no-tags --raw docker://repo-empty-tags-existing"* ]]
then
# Existing repo that transiently returns empty tags - inspect succeeds
echo '{"config": {"mediaType": "application/vnd.oci.image.config.v1+json"}, "annotations": {}}'
return
elif [[ "$*" == "inspect --retry-times 3 --no-tags --raw docker://repoa"* ]] || \
[[ "$*" == "inspect --retry-times 3 --no-tags --raw docker://repo2"* ]]
then
# Genuinely new repos (no manifests yet) - inspect fails
echo "Error: repository not found" >&2
return 1
elif [[ "$*" == "inspect --retry-times 3 --no-tags --raw docker://"* ]]
then
# Default: standard OCI container image config
echo '{"config": {"mediaType": "application/vnd.oci.image.config.v1+json"}, "annotations": {}}'
return
fi
# Standard inspections (for labels, env, etc.)
if [[ "$*" == "inspect --retry-times 3 --no-tags --override-os linux --override-arch amd64 docker://registry.io/badimage"* ]]
then
echo '{"Labels": {"not-a-build-date": "2024-07-29T02:17:29"}}'
return
elif [[ "$*" == "inspect --retry-times 3 --no-tags --override-os linux --override-arch amd64 docker://registry.io/labels"* ]]
then
echo '{"Labels": {"build-date": "2024-07-29T02:17:29", "Goodlabel": "labelvalue", "Goodlabel.with-dash": "labelvalue-with-dash", "Badlabel": "label with space"}}'
return
elif [[ "$*" == "inspect --retry-times 3 --no-tags --override-os linux --override-arch amd64 docker://registry.io/onlycreated"* ]]
then
echo '{"Labels": {"not-a-build-date": "2024-07-29T02:17:29"}, "Created": "2024-07-29T02:17:29"}'
return
elif [[ "$*" == "inspect --retry-times 3 --no-tags --override-os linux --override-arch amd64 docker://quay.io/myorg/web-app"* ]]
then
echo '{"Labels": {"build-date": "2024-07-29T02:17:29"}}'
return
elif [[ "$*" == "inspect --retry-times 3 --no-tags --override-os linux --override-arch amd64 docker://registry.io/metadata"* ]]
then
echo '{"Labels": {"build-date": "2024-07-29T02:17:29", "com.redhat.component": "app01", "description": "it is some app"},
"Env": ["container=oci", "PATH=usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"]}'
return
elif [[ "$*" == "inspect --retry-times 3 --no-tags --override-os linux --override-arch amd64 docker://quay.io/myorg/api-service"* ]]
then
echo '{"Labels": {"build-date": "2024-07-29T02:17:29"}}'
return
elif [[ "$*" == "inspect --retry-times 3 --no-tags --override-os linux --override-arch amd64 docker://quay.io/myorg/helm-chart"* ]]
then
echo '{"Labels": {}}'
return
elif [[ "$*" == "inspect --retry-times 3 --no-tags --override-os linux --override-arch amd64 docker://"* ]]
then
echo '{"Labels": {"build-date": "2024-07-29T02:17:29", "org.opencontainers.image.version": "2.0.1+alpha"}}'
return
fi
echo Error: Unexpected call
exit 1
}
function get-image-architectures() {
if [[ "$1" == *"helm-chart"* ]]; then
# Return Helm chart format (single arch) with configMediaType
jq -nc '{
"platform": {"architecture": "amd64", "os": "linux"},
"digest": "sha256:789abcdef123456",
"multiarch": false,
"configMediaType": "application/vnd.cncf.helm.config.v1+json"
}'
else
# Return regular container image format (multi-arch)
jq -nc '{
"platform": {"architecture": "amd64", "os": "linux"},
"digest": "abcdefg",
"multiarch": false
}'
jq -nc '{
"platform": {"architecture": "ppc64le", "os": "linux"},
"digest": "deadbeef",
"multiarch": false
}'
fi
}