Skip to content

Commit aa6c283

Browse files
committed
fix yq version and filter the charts for patching
1 parent e40ecd3 commit aa6c283

File tree

3 files changed

+78
-6
lines changed

3 files changed

+78
-6
lines changed

default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ rec {
6464
skopeo
6565
sops
6666
opentofu
67-
yq
67+
yq-go # Use yq-go (v4+) explicitly instead of python-yq for consistent YAML processing
6868
create-container-dump
6969
list-helm-containers
7070
mirror-apt-jammy

nix/scripts/list-helm-containers.sh

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ VALUES_DIR=""
1111
HELM_IMAGE_TREE_FILE=""
1212
VALUES_TYPE=""
1313

14+
# Extract images using yq-go (v4+) syntax
15+
# Note: This requires yq-go to be in PATH (see default.nix)
16+
extract_images() {
17+
yq eval '.. | select(has("image")) | .image' "$1" 2>/dev/null || true
18+
}
19+
1420
# Parse the arguments
1521
for arg in "$@"
1622
do
@@ -96,12 +102,24 @@ while IFS= read -r chart; do
96102
secrets_file="${VALUES_DIR}/$(basename "${chart}")/demo-secrets.example.yaml"
97103
fi
98104

99-
raw_images=$(helm template "${chart}" \
105+
# Separate helm stderr from stdout to avoid yq parsing errors
106+
# Save helm output to temp file to capture exit code
107+
temp_helm_output=$(mktemp)
108+
helm template "${chart}" \
100109
$( [[ -n "$values_file" ]] && echo "-f $values_file" ) \
101110
$( [[ -n "$secrets_file" ]] && echo "-f $secrets_file" ) \
102-
2>&1 | yq -r '..|.image?' | grep -v "^null$" | grep -v "^---$" | grep -v "^$" || true)
111+
> "$temp_helm_output" 2>&1
103112

104113
helm_exit_code=$?
114+
115+
# Extract images using version-appropriate yq syntax
116+
if [[ $helm_exit_code -eq 0 ]]; then
117+
raw_images=$(extract_images "$temp_helm_output" | grep -v "^null$" | grep -v "^---$" | grep -v "^$" || true)
118+
else
119+
raw_images=""
120+
fi
121+
122+
rm -f "$temp_helm_output"
105123
set -e # Re-enable exit on error
106124

107125
if [[ $helm_exit_code -ne 0 ]]; then

offline/tasks/patch-chart-images.sh

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,44 @@ if [[ -z "$CHARTS_DIR" ]]; then
1111
exit 1
1212
fi
1313

14+
# Charts maintained by Wire (should not contain bitnami refs)
15+
# These charts are excluded from patching to avoid masking potential issues
16+
PATCH_EXCLUDE_LIST=(
17+
"wire-server"
18+
"wire-server-enterprise"
19+
"backoffice"
20+
"ldap-scim-bridge"
21+
"account-pages"
22+
"webapp"
23+
"team-settings"
24+
"sftd"
25+
"calling-test"
26+
"migrate-features"
27+
"wire-utility"
28+
"fake-aws"
29+
"fake-aws-s3"
30+
"fake-aws-sqs"
31+
"demo-smtp"
32+
"inbucket"
33+
)
34+
1435
echo "Patching bitnami repository references in: $CHARTS_DIR"
36+
echo "Excluded charts: ${PATCH_EXCLUDE_LIST[*]}"
1537

1638
patched_count=0
1739
file_count=0
40+
skipped_count=0
41+
42+
# Function to check if chart should be excluded from patching
43+
is_excluded_chart() {
44+
local chart_name="$1"
45+
for excluded in "${PATCH_EXCLUDE_LIST[@]}"; do
46+
if [[ "$chart_name" == "$excluded" ]]; then
47+
return 0 # true - chart is excluded
48+
fi
49+
done
50+
return 1 # false - chart should be patched
51+
}
1852

1953
# Function to patch a single file
2054
patch_file() {
@@ -31,6 +65,12 @@ patch_file() {
3165
chart_name="unknown"
3266
fi
3367

68+
# Check if this chart should be excluded from patching
69+
if is_excluded_chart "$chart_name"; then
70+
rm "$temp_file"
71+
return 2 # Special return code for skipped charts
72+
fi
73+
3474
# Apply sed replacements for various image reference patterns
3575
sed -e 's|repository: bitnami/|repository: bitnamilegacy/|g' \
3676
-e 's|repository: docker\.io/bitnami/|repository: docker.io/bitnamilegacy/|g' \
@@ -73,31 +113,45 @@ echo "Scanning and patching files..."
73113
# Process values.yaml files
74114
while IFS= read -r -d '' file; do
75115
file_count=$((file_count + 1))
76-
if patch_file "$file"; then
116+
patch_file "$file"
117+
rc=$?
118+
if [[ $rc -eq 0 ]]; then
77119
patched_count=$((patched_count + 1))
120+
elif [[ $rc -eq 2 ]]; then
121+
skipped_count=$((skipped_count + 1))
78122
fi
79123
done < <(find "$CHARTS_DIR" -name "values.yaml" -print0)
80124

81125
# Process Chart.yaml files
82126
while IFS= read -r -d '' file; do
83127
file_count=$((file_count + 1))
84-
if patch_file "$file"; then
128+
patch_file "$file"
129+
rc=$?
130+
if [[ $rc -eq 0 ]]; then
85131
patched_count=$((patched_count + 1))
132+
elif [[ $rc -eq 2 ]]; then
133+
skipped_count=$((skipped_count + 1))
86134
fi
87135
done < <(find "$CHARTS_DIR" -name "Chart.yaml" -print0)
88136

89137
# Process template files (for direct image references)
90138
while IFS= read -r -d '' file; do
91139
file_count=$((file_count + 1))
92-
if patch_file "$file"; then
140+
patch_file "$file"
141+
rc=$?
142+
if [[ $rc -eq 0 ]]; then
93143
patched_count=$((patched_count + 1))
144+
elif [[ $rc -eq 2 ]]; then
145+
skipped_count=$((skipped_count + 1))
94146
fi
95147
done < <(find "$CHARTS_DIR" -path "*/templates/*.yaml" -print0)
96148

97149
echo
98150
echo "=== Patching Summary ==="
99151
echo "Files processed: $file_count"
152+
echo "Files skipped (excluded charts): $skipped_count"
100153
echo "Files modified: $patched_count"
154+
echo "Files unchanged: $((file_count - skipped_count - patched_count))"
101155

102156
if [[ $patched_count -gt 0 ]]; then
103157
echo

0 commit comments

Comments
 (0)