-
Notifications
You must be signed in to change notification settings - Fork 3
/
generate-fbc.sh
executable file
·201 lines (186 loc) · 6.86 KB
/
generate-fbc.sh
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#!/usr/bin/env bash
set -e
SKOPEO_CMD=${SKOPEO_CMD:-skopeo}
OPM_CMD=${OPM_CMD:-opm}
AUTH_FILE=${AUTH_FILE:-}
package_name="orchestrator-operator"
helpFunction()
{
echo -e "Usage: $0\n"
echo -e "\t--help: see all commands of this script\n"
echo -e "\t--init-basic <OCP_minor> <yq|jq>: initialize a new composite fragment\n\t example: $0 --init-basic v4.13 yq\n"
echo -e "\t--init-basic-all: initialize all the fragments from production\n\t example: $0 --init-basic-all\n"
echo -e "\t--comment-graph <OCP_minor>: add human readable bundle tags as comments to graph generated by --init-basic\n\t example: $0 --comment-graph v4.13\n"
echo -e "\t--render <OCP_minor> <brew>: render one FBC fragment\n\t\"brew\" optional parameter will made it consuming bundle images from the brew registry\n\t example: $0 --render v4.13 brew\n"
echo -e "\t--render-all <brew>: render all the FBC fragments\n\t\"brew\" optional parameter will made it consuming bundle images from the brew registry\n\t example: $0 --render-all brew\n"
exit 1
}
devfile()
{
cat <<EOT > "$1"/devfile.yaml
schemaVersion: 2.2.0
metadata:
name: fbc-$1
displayName: FBC $1
description: 'File based catalog'
language: fbc
provider: Red Hat
components:
- name: image-build
image:
imageName: ""
dockerfile:
uri: catalog.Dockerfile
buildContext: ""
- name: kubernetes
kubernetes:
inlined: placeholder
attributes:
deployment/container-port: 50051
deployment/cpuRequest: "100m"
deployment/memoryRequest: 512Mi
deployment/replicas: 1
deployment/storageRequest: "0"
commands:
- id: build-image
apply:
component: image-build
EOT
}
dockerfile()
{
cat <<EOT > "$1"/catalog.Dockerfile
# The base image is expected to contain
# /bin/opm (with a serve subcommand) and /bin/grpc_health_probe
FROM registry.redhat.io/openshift4/ose-operator-registry:$1
ENTRYPOINT ["/bin/opm"]
CMD ["serve", "/configs", "--cache-dir=/tmp/cache"]
ADD catalog /configs
RUN ["/bin/opm", "serve", "/configs", "--cache-dir=/tmp/cache", "--cache-only"]
# Core bundle labels.
LABEL operators.operatorframework.io.bundle.mediatype.v1=registry+v1
LABEL operators.operatorframework.io.bundle.manifests.v1=manifests/
LABEL operators.operatorframework.io.bundle.metadata.v1=metadata/
LABEL operators.operatorframework.io.bundle.package.v1=orchestrator-operator
LABEL operators.operatorframework.io.bundle.channels.v1=alpha
LABEL operators.operatorframework.io.metrics.builder=operator-sdk-v1.32.0
LABEL operators.operatorframework.io.metrics.mediatype.v1=metrics+v1
LABEL operators.operatorframework.io.metrics.project_layout=go.kubebuilder.io/v3
LABEL operators.operatorframework.io.index.configs.v1=/configs
EOT
}
setBrew()
{
if [[ "$2" == "brew" ]]; then
sed -i 's|image: registry.redhat.io/rhtas-tech-preview/orchestrator-operator|image: registry.redhat.io/rhtas-tech-preview/orchestrator-operator|g' "${frag}"/graph.yaml
fi
}
unsetBrew()
{
if [[ "$2" == "brew" ]]; then
sed -i 's|image: brew.registry.redhat.io/rhtas-tech-preview/orchestrator-operator|image: registry.redhat.io/rhtas-tech-preview/orchestrator-operator|g' "${frag}"/graph.yaml
sed -i 's|brew.registry.redhat.io/rhtas-tech-preview/orchestrator-operator|registry.redhat.io/rhtas-tech-preview/orchestrator-operator|g' "${frag}"/catalog/orchestrator-operator/catalog.json
fi
}
cmd="$1"
case $cmd in
"--help")
helpFunction
;;
"--init-basic")
frag=$2
if [ -z "$frag" ]
then
echo "Please specify OCP minor, eg: v4.12"
exit 1
fi
FROMV=$(grep FROM "${frag}"/catalog.Dockerfile)
OCPV=${FROMV##*:}
from=registry.redhat.io/redhat/redhat-operator-index:${OCPV}
yqOrjq=$3
mkdir -p "${frag}/catalog/orchestrator-operator/" "${frag}/${frag}"
touch "${frag}/${frag}/.empty"
case $yqOrjq in
"yq")
touch "${frag}"/graph.yaml
"${OPM_CMD}" render "$from" -o yaml | yq "select( .package == \"$package_name\" or .name == \"$package_name\")" | yq 'select(.schema == "olm.bundle") = {"schema": .schema, "image": .image}' | yq 'select(.schema == "olm.package") = {"schema": .schema, "name": .name, "defaultChannel": .defaultChannel}' > "${frag}"/graph.yaml
;;
"jq")
"${OPM_CMD}" render "$from" | jq "select( .package == \"$package_name\" or .name == \"$package_name\")" | jq 'if (.schema == "olm.bundle") then {schema: .schema, image: .image} else (if (.schema == "olm.package") then {schema: .schema, name: .name, defaultChannel: .defaultChannel} else . end) end' > "${frag}"/graph.json
;;
*)
echo "please specify if yq or jq"
exit 1
;;
esac
devfile "$frag"
dockerfile "$frag"
;;
"--init-basic-all")
for f in ./"v4."*; do
frag=${f#./}
$0 --init-basic "${frag}" yq
$0 --comment-graph "${frag}"
done
;;
"--render")
frag=$2
if [ -z "$frag" ]
then
echo "Please specify OCP minor, eg: v4.12"
exit 1
fi
setBrew "${frag}" "$3"
"${OPM_CMD}" alpha render-template basic "${frag}"/graph.yaml -oyaml > "${frag}"/catalog/orchestrator-operator/catalog.yaml
unsetBrew "${frag}" "$3"
;;
"--render-all")
for f in ./"v4."*; do
frag=${f#./}
setBrew "${frag}" "$2"
"${OPM_CMD}" alpha render-template basic "${frag}"/graph.yaml -oyaml > "${frag}"/catalog/orchestrator-operator/catalog.yaml
unsetBrew "${frag}" "$2"
done
;;
"--comment-graph")
frag=$2
if [ -z "$frag" ]
then
echo "Please specify OCP minor, eg: v4.12"
exit 1
fi
setBrew "${frag}" "$3"
sed -i "/# orchestrator-bundle-registry v4\./d" "$frag"/graph.yaml
grep -E "^image: [brew\.]*registry.redhat.io/rhtas-tech-preview/orchestrator-operator[-rhel9]*@sha256" "$frag"/graph.yaml | while read -r line ; do
image=${line/image: /}
echo "Processing $image"
# shellcheck disable=SC2086
url=$(${SKOPEO_CMD} inspect --no-tags ${AUTH_FILE} docker://"$image" | grep "\"url\": ")
tag1=${url/*\/images\/}
tag=${tag1/\",/}
sed -i "s|$image|$image\n# hco-bundle-registry $tag|g" "$frag"/graph.yaml
done
unsetBrew "${frag}" "$3"
;;
"--comment-graph-all")
for f in ./"v4."*; do
frag=${f#./}
setBrew "${frag}" "$2"
sed -i "/# hco-bundle-registry v4\./d" "$frag"/graph.yaml
grep -E "^image: [brew\.]*registry.redhat.io/rhtas-tech-preview/orchestrator-operator[-rhel9]*@sha256" "$frag"/graph.yaml | while read -r line ; do
image=${line/image: /}
echo "Processing $image"
# shellcheck disable=SC2086
url=$(${SKOPEO_CMD} inspect --no-tags ${AUTH_FILE} docker://"$image" | grep "\"url\": ")
tag1=${url/*\/images\/}
tag=${tag1/\",/}
sed -i "s|$image|$image\n# orchestrator-bundle-registry $tag|g" "$frag"/graph.yaml
done
unsetBrew "${frag}" "$2"
done
;;
*)
echo "$cmd not one of the allowed flags"
helpFunction
;;
esac