-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgenerate-fbc.sh
executable file
·170 lines (153 loc) · 7 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
#!/usr/bin/env bash
set -e
SKOPEO_CMD=${SKOPEO_CMD:-skopeo}
OPM_CMD=${OPM_CMD:-opm}
AUTH_FILE=${AUTH_FILE:-}
# shellcheck source=opm_utils.sh
source opm_utils.sh
download_opm_client
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
}
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
# shellcheck disable=SC2086
./opm render $(opm_alpha_params "${frag}") "$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}' | \
yq '[.]' | \
yq '{"schema": "olm.template.basic", "name": "orchestrator-operator", "entries":.}' | \
sed 's|^ #| #|g' > "${frag}/graph.yaml" ;;
"jq")
./opm render $(opm_alpha_params "${frag}") "$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
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 alpha render-template basic $(opm_alpha_params "${frag}") "${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 alpha render-template basic $(opm_alpha_params "${frag}") "${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
sed -i "/# orchestrator-bundle-registry v4\./d" "$frag"/graph.yaml
grep -E "^\s\s\s\simage: registry.redhat.io/rhdh-orchestrator-dev-preview-beta/orchestrator-operator-bundle@sha256" "$frag"/graph.yaml | while read -r line ; do
image=${line/image: /}
echo "Processing $image"
# shellcheck disable=SC2086
release=$(${SKOPEO_CMD} inspect --format "{{.Labels.release}}" --no-tags ${AUTH_FILE} docker://"$image")
sed -i -E "s|^( *)(image: )$image|\1\2$image\n\1# orchestrator-bundle-registry $release|" "$frag"/graph.yaml
done
;;
"--comment-graph-all")
for f in ./"v4."*; do
frag=${f#./}
sed -i "/# orchestrator-bundle-registry v4\./d" "$frag"/graph.yaml
grep -E "^\s\s\s\simage: registry.redhat.io/rhdh-orchestrator-dev-preview-beta/orchestrator-operator-bundle@sha256" "$frag"/graph.yaml | while read -r line ; do
image=${line/image: /}
echo "Processing $image"
# shellcheck disable=SC2086
release=$(${SKOPEO_CMD} inspect --format "{{.Labels.release}}" --no-tags ${AUTH_FILE} docker://"$image")
sed -i -E "s|^( *)(image: )$image|\1\2$image\n\1# orchestrator-bundle-registry $release|" "$frag"/graph.yaml
done
done
;;
*)
echo "$cmd not one of the allowed flags"
helpFunction
;;
esac