-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathDockerfile.catalog-sync
More file actions
125 lines (119 loc) · 7.15 KB
/
Copy pathDockerfile.catalog-sync
File metadata and controls
125 lines (119 loc) · 7.15 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
# Dockerfile.catalog-sync
#
# Multi-stage build that pulls operator catalog index images from
# registry.redhat.io via FROM instructions (uses node-level CRI-O
# credentials in CI, bypassing the need for explicit auth files).
#
# Extracts /configs/ from each image, processes them with
# catalog_metadata.py to generate operators.json, dependencies.json,
# catalog-info.json, and assembles catalog-index.json.
#
# This Dockerfile is used by ci-operator in the catalog-sync variant.
# The output image provides catalog-data/ which is injected into the
# main mirror-gui image build via inputs.paths.
#
# For local development, use the regular Dockerfile instead.
# --- Stage 1: Pull all 18 catalog index images ---
FROM registry.redhat.io/redhat/redhat-operator-index:v4.16 AS redhat-4-16
FROM registry.redhat.io/redhat/redhat-operator-index:v4.17 AS redhat-4-17
FROM registry.redhat.io/redhat/redhat-operator-index:v4.18 AS redhat-4-18
FROM registry.redhat.io/redhat/redhat-operator-index:v4.19 AS redhat-4-19
FROM registry.redhat.io/redhat/redhat-operator-index:v4.20 AS redhat-4-20
FROM registry.redhat.io/redhat/redhat-operator-index:v4.21 AS redhat-4-21
FROM registry.redhat.io/redhat/certified-operator-index:v4.16 AS certified-4-16
FROM registry.redhat.io/redhat/certified-operator-index:v4.17 AS certified-4-17
FROM registry.redhat.io/redhat/certified-operator-index:v4.18 AS certified-4-18
FROM registry.redhat.io/redhat/certified-operator-index:v4.19 AS certified-4-19
FROM registry.redhat.io/redhat/certified-operator-index:v4.20 AS certified-4-20
FROM registry.redhat.io/redhat/certified-operator-index:v4.21 AS certified-4-21
FROM registry.redhat.io/redhat/community-operator-index:v4.16 AS community-4-16
FROM registry.redhat.io/redhat/community-operator-index:v4.17 AS community-4-17
FROM registry.redhat.io/redhat/community-operator-index:v4.18 AS community-4-18
FROM registry.redhat.io/redhat/community-operator-index:v4.19 AS community-4-19
FROM registry.redhat.io/redhat/community-operator-index:v4.20 AS community-4-20
FROM registry.redhat.io/redhat/community-operator-index:v4.21 AS community-4-21
# --- Stage 2: Extract and process catalog data ---
FROM node:22-slim AS processor
WORKDIR /app
RUN apt-get update && \
apt-get install -y --no-install-recommends jq python3 python3-yaml && \
rm -rf /var/lib/apt/lists/*
COPY scripts/catalog_metadata.py ./scripts/catalog_metadata.py
COPY --from=redhat-4-16 /configs catalog-data-synced/redhat-operator-index/v4.16/configs/
COPY --from=redhat-4-17 /configs catalog-data-synced/redhat-operator-index/v4.17/configs/
COPY --from=redhat-4-18 /configs catalog-data-synced/redhat-operator-index/v4.18/configs/
COPY --from=redhat-4-19 /configs catalog-data-synced/redhat-operator-index/v4.19/configs/
COPY --from=redhat-4-20 /configs catalog-data-synced/redhat-operator-index/v4.20/configs/
COPY --from=redhat-4-21 /configs catalog-data-synced/redhat-operator-index/v4.21/configs/
COPY --from=certified-4-16 /configs catalog-data-synced/certified-operator-index/v4.16/configs/
COPY --from=certified-4-17 /configs catalog-data-synced/certified-operator-index/v4.17/configs/
COPY --from=certified-4-18 /configs catalog-data-synced/certified-operator-index/v4.18/configs/
COPY --from=certified-4-19 /configs catalog-data-synced/certified-operator-index/v4.19/configs/
COPY --from=certified-4-20 /configs catalog-data-synced/certified-operator-index/v4.20/configs/
COPY --from=certified-4-21 /configs catalog-data-synced/certified-operator-index/v4.21/configs/
COPY --from=community-4-16 /configs catalog-data-synced/community-operator-index/v4.16/configs/
COPY --from=community-4-17 /configs catalog-data-synced/community-operator-index/v4.17/configs/
COPY --from=community-4-18 /configs catalog-data-synced/community-operator-index/v4.18/configs/
COPY --from=community-4-19 /configs catalog-data-synced/community-operator-index/v4.19/configs/
COPY --from=community-4-20 /configs catalog-data-synced/community-operator-index/v4.20/configs/
COPY --from=community-4-21 /configs catalog-data-synced/community-operator-index/v4.21/configs/
SHELL ["/bin/bash", "-c"]
RUN set -euo pipefail && \
CATALOG_DATA_DIR=./catalog-data-synced && \
OCP_VERSIONS="4.16 4.17 4.18 4.19 4.20 4.21" && \
CATALOG_TYPES="redhat-operator-index certified-operator-index community-operator-index" && \
TOTAL=0 && SUCCESS=0 && FAILED=0 && \
for ocp_version in $OCP_VERSIONS; do \
for catalog_type in $CATALOG_TYPES; do \
TOTAL=$((TOTAL + 1)); \
catalog_dir="${CATALOG_DATA_DIR}/${catalog_type}/v${ocp_version}"; \
if [ ! -d "${catalog_dir}/configs" ]; then \
echo "WARN: No configs for ${catalog_type} v${ocp_version}, skipping"; \
FAILED=$((FAILED + 1)); \
continue; \
fi; \
operators_file="${catalog_dir}/operators.json"; \
dependencies_file="${catalog_dir}/dependencies.json"; \
if python3 ./scripts/catalog_metadata.py generate \
--catalog-dir "$catalog_dir" \
--catalog-type "$catalog_type" \
--ocp-version "v${ocp_version}" \
--operators-file "$operators_file" \
--dependencies-file "$dependencies_file"; then \
operator_count=$(jq '. | length' "$operators_file" 2>/dev/null || echo "0"); \
synced_at=$(date -u +"%Y-%m-%dT%H:%M:%SZ"); \
printf '{"catalog_type":"%s","ocp_version":"v%s","catalog_url":"registry.redhat.io/redhat/%s:v%s","operator_count":%s,"digest":"from-build","synced_at":"%s"}\n' \
"$catalog_type" "$ocp_version" "$catalog_type" "$ocp_version" "$operator_count" "$synced_at" \
> "${catalog_dir}/catalog-info.json"; \
rm -rf "${catalog_dir}/configs"; \
SUCCESS=$((SUCCESS + 1)); \
else \
echo "ERROR: Failed to process ${catalog_type} v${ocp_version}"; \
rm -rf "${catalog_dir}/configs" 2>/dev/null; \
FAILED=$((FAILED + 1)); \
fi; \
done; \
done && \
if [ "$FAILED" -gt 0 ]; then \
echo "ERROR: ${FAILED}/${TOTAL} catalogs failed to process"; \
exit 1; \
fi && \
OCP_JSON=$(echo $OCP_VERSIONS | tr ' ' '\n' | sed 's/.*/"&"/' | paste -sd,) && \
CAT_JSON=$(echo $CATALOG_TYPES | tr ' ' '\n' | sed 's/.*/"&"/' | paste -sd,) && \
printf '{"ocp_versions":[%s],"catalog_types":[%s],"catalogs":[]}\n' "$OCP_JSON" "$CAT_JSON" \
> "${CATALOG_DATA_DIR}/catalog-index.json" && \
for ocp_version in $OCP_VERSIONS; do \
for catalog_type in $CATALOG_TYPES; do \
info="${CATALOG_DATA_DIR}/${catalog_type}/v${ocp_version}/catalog-info.json"; \
if [ -f "$info" ]; then \
jq --argjson entry "$(cat "$info")" '.catalogs += [$entry]' \
"${CATALOG_DATA_DIR}/catalog-index.json" > "${CATALOG_DATA_DIR}/catalog-index.json.tmp" && \
mv "${CATALOG_DATA_DIR}/catalog-index.json.tmp" "${CATALOG_DATA_DIR}/catalog-index.json"; \
fi; \
done; \
done && \
find "${CATALOG_DATA_DIR}" -type d -name configs -exec rm -rf {} + 2>/dev/null; \
echo "Completed: ${SUCCESS}/${TOTAL} catalogs successful, ${FAILED} failed" && \
echo "--- catalog-data contents ---" && \
find "${CATALOG_DATA_DIR}" -type f && \
cat "${CATALOG_DATA_DIR}/catalog-index.json"