@@ -21,36 +21,112 @@ spec:
2121 - name : credentials
2222 description : Docker config for retrieving the bundle image
2323 optional : true
24+ stepTemplate :
25+ env :
26+ - name : DOCKER_CONFIG
27+ value : " $(workspaces.output.path)/opm-docker-config"
28+ - name : DB_PATH
29+ value : /var/lib/iib/_hidden/do.not.edit.db
30+ - name : FBC_FILE
31+ value : fbc.txt
2432 steps :
33+ - name : inspect-base-index
34+ image : registry.redhat.io/rhel8/podman:8.5-13
35+ workingDir : $(workspaces.output.path)
36+ script : |
37+ #! /usr/bin/env bash
38+ set -exo pipefail
39+
40+ # Copy the default credentials to the "output" workspace so they can be
41+ # accessed without root access in other steps.
42+ mkdir -p $DOCKER_CONFIG
43+ cp $HOME/.docker/config.json $DOCKER_CONFIG/config.json
44+ chmod 644 $DOCKER_CONFIG/config.json
45+
46+ # Pull the index image from a pre-configured imagestream in the current namespace.
47+ # It may be possible to eliminate this once sqlite-based index images are no
48+ # longer supported.
49+ INDEX_IMG_STREAM=$(echo $(params.from_index) | rev | cut -f1 -d/ | rev)
50+ FROM_INDEX="$(params.internal_registry)/$(context.taskRun.namespace)/$INDEX_IMG_STREAM"
51+
52+ podman pull $FROM_INDEX
53+ podman image inspect $FROM_INDEX | tee podman-inspect.json
54+
55+ - name : determine-index-format
56+ image : " $(params.pipeline_image)"
57+ workingDir : $(workspaces.output.path)
58+ script : |
59+ #! /usr/bin/env bash
60+ set -x
61+
62+ # Create a special file in the workspace if this index uses file-based configs
63+ CONFIGS_QUERY='.[0].Labels."operators.operatorframework.io.index.configs.v1"'
64+ jq -e "$CONFIGS_QUERY" podman-inspect.json && touch $FBC_FILE
65+ exit 0
66+
67+ - name : extract-database
68+ image : " $(params.from_index)"
69+ workingDir : $(workspaces.output.path)
70+ script : |
71+ #! /usr/bin/env bash
72+ set -ex
73+
74+ if [ -f "$FBC_FILE" ]; then
75+ echo "This index image uses file based configs. Extracting the database."
76+ cp $DB_PATH index.db
77+ chmod 664 index.db
78+ else
79+ echo "This index image does not use file based configs. Skipping database extraction."
80+ fi
81+
2582 - name : generate
2683 image : " $(params.pipeline_image)"
2784 workingDir : $(workspaces.output.path)
2885 script : |
2986 #! /usr/bin/env bash
30- set -xe
87+ set -exo pipefail
3188
3289 if [[ "$(workspaces.credentials.bound)" == "true" ]]; then
33- # Setup registry credentials for OPM. Combine the default credentials
34- # with those found in the workspace to maintain access to the internal
35- # registry.
36- export DOCKER_CONFIG=/tmp/.docker
37- mkdir $DOCKER_CONFIG
90+ # Merge the default docker config and the extra creds
3891 jq -s '.[0] * .[1]' \
3992 $(workspaces.credentials.path)/.dockerconfigjson \
40- $HOME/.docker/config.json \
41- > $DOCKER_CONFIG/config.json
93+ $DOCKER_CONFIG/config.json \
94+ > temp-config.json
95+
96+ mv temp-config.json $DOCKER_CONFIG/config.json
97+ rm temp-config.json
4298 fi
4399
44- INDEX_IMG_STREAM=$(echo $(params.from_index) | rev | cut -f1 -d/ | rev)
45- FROM_INDEX="$(params.internal_registry)/$(context.taskRun.namespace)/$INDEX_IMG_STREAM"
100+ if [ -f "$FBC_FILE" ]; then
101+ # Add the bundle to the sqlite DB
102+ opm registry add \
103+ -b "$(params.bundle_image)" \
104+ -d index.db
105+
106+ # Migrate the sqlite DB to a file-based catalog in the "index" directory.
107+ # The Dockerfile will be named after this directory.
108+ opm migrate index.db index
46109
47- opm index add \
48- --from-index $FROM_INDEX \
49- --bundles "$(params.bundle_image)" \
50- --container-tool none \
51- --out-dockerfile Dockerfile.index \
52- --generate
110+ # Generate the index Dockerfile
111+ opm alpha generate dockerfile index
112+
113+ # Amend the Dockerfile with the addition of the sqlite DB for backwards compatibility
114+ echo -e "\nADD index.db $DB_PATH\n" >> index.Dockerfile
115+ else
116+ # Pull the index image from a pre-configured imagestream in the current namespace.
117+ # It may be possible to eliminate this once sqlite-based index images are no
118+ # longer supported.
119+ INDEX_IMG_STREAM=$(echo $(params.from_index) | rev | cut -f1 -d/ | rev)
120+ FROM_INDEX="$(params.internal_registry)/$(context.taskRun.namespace)/$INDEX_IMG_STREAM"
121+
122+ opm index add \
123+ --from-index "$FROM_INDEX" \
124+ --bundles "$(params.bundle_image)" \
125+ --container-tool none \
126+ --out-dockerfile index.Dockerfile \
127+ --generate
128+ fi
53129
54130 ls -lh
55- cat Dockerfile. index
56- echo -n Dockerfile. index | tee $(results.index_dockerfile.path)
131+ cat index.Dockerfile
132+ echo -n index.Dockerfile > $(results.index_dockerfile.path)
0 commit comments