Skip to content

Commit 8152526

Browse files
authored
feat: parallelize helm-publish-prerelease-dual job (IN-3739) (#378)
## Description Replace sequential S3 + ECR publish steps with a single two-phase script that packages all charts in parallel, then pushes to S3 sequentially while overlapping ECR pushes in the background. Per-chart logs are stored as CircleCI artifacts for debuggability. Speedup: ~12 minutes -> ~7 minutes
1 parent 67ff2a8 commit 8152526

3 files changed

Lines changed: 136 additions & 6 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
executor: build-executor
2+
parameters:
3+
working_directory:
4+
description: Directory containing chart directories
5+
type: string
6+
default: "./"
7+
prepublish_steps:
8+
description: Steps to run on repo before publishing charts
9+
type: steps
10+
default: []
11+
steps:
12+
- checkout_clone
13+
- set-beta-version:
14+
working_directory: << parameters.working_directory >>
15+
- steps: << parameters.prepublish_steps >>
16+
- helm-add-repos
17+
- run:
18+
name: Package and publish prerelease charts
19+
working_directory: << parameters.working_directory >>
20+
command: <<include(scripts/helm/publish-prerelease-dual.sh)>>
21+
- store_artifacts:
22+
path: /tmp/helm-publish-logs
23+
destination: helm-publish-logs

src/jobs/helm/helm-publish-prerelease-dual.yaml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@ steps:
1515
- steps: << parameters.prepublish_steps >>
1616
- helm-add-repos
1717
- run:
18-
name: Package and publish prerelease charts to S3
18+
name: Package and publish prerelease charts
1919
working_directory: << parameters.working_directory >>
20-
command: <<include(scripts/helm/publish-prerelease.sh)>>
21-
- run:
22-
name: Package and publish prerelease charts to ECR
23-
working_directory: << parameters.working_directory >>
24-
command: <<include(scripts/helm/publish-prerelease-ecr.sh)>>
20+
command: <<include(scripts/helm/publish-prerelease-dual.sh)>>
21+
- store_artifacts:
22+
path: /tmp/helm-publish-logs
23+
destination: helm-publish-logs
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
echo "BETA_VERSION: ${BETA_VERSION:?}"
5+
echo "AWS_REGION: ${AWS_REGION:?}"
6+
7+
ECR_REPOSITORY_URI=${ECR_REPOSITORY_URI:-"168387678261.dkr.ecr.us-east-1.amazonaws.com"}
8+
echo "ECR_REPOSITORY_URI: ${ECR_REPOSITORY_URI}"
9+
10+
export HELM_EXPERIMENTAL_OCI=1
11+
12+
LOG_DIR="/tmp/helm-publish-logs"
13+
mkdir -p "$LOG_DIR"
14+
15+
MAX_PARALLEL=2
16+
17+
# Login to ECR once upfront
18+
aws ecr get-login-password --region "$AWS_REGION" | \
19+
helm registry login --username AWS --password-stdin "$ECR_REPOSITORY_URI"
20+
21+
# Discover charts
22+
CHARTS=()
23+
for file in *; do
24+
if [[ -d "$file" && -f "$file/$file/Chart.yaml" ]]; then
25+
CHARTS+=("$file")
26+
fi
27+
done
28+
29+
if [ ${#CHARTS[@]} -eq 0 ]; then
30+
echo "No charts found"
31+
exit 0
32+
fi
33+
34+
echo "Found ${#CHARTS[@]} charts: ${CHARTS[*]}"
35+
36+
# ── Phase 1: Package charts in parallel (max $MAX_PARALLEL at a time) ──
37+
cat > /tmp/package-chart.sh <<HELPER
38+
#!/bin/bash
39+
file="\$1"
40+
if ! (
41+
set -euo pipefail
42+
cd "\$file"
43+
helm dep update "\$file"
44+
helm package "\$file" --version "$BETA_VERSION"
45+
CHART="\$file-${BETA_VERSION}.tgz"
46+
if [ ! -f "\$CHART" ]; then
47+
echo "ERROR: Packaged chart does not have expected name \$CHART"
48+
exit 3
49+
fi
50+
) > "$LOG_DIR/\$file-package.log" 2>&1; then
51+
echo "FAILED: packaging \$file"
52+
cat "$LOG_DIR/\$file-package.log"
53+
exit 1
54+
fi
55+
echo "Packaged \$file"
56+
HELPER
57+
chmod +x /tmp/package-chart.sh
58+
59+
printf '%s\0' "${CHARTS[@]}" | xargs -0 -n1 -P"$MAX_PARALLEL" /tmp/package-chart.sh
60+
61+
echo "All ${#CHARTS[@]} charts packaged, starting pushes..."
62+
63+
# ── Phase 2: Push to S3 (sequential) and ECR (parallel, max $MAX_PARALLEL) ──
64+
cat > /tmp/push-ecr.sh <<HELPER
65+
#!/bin/bash
66+
file="\$1"
67+
CHART="\$file/\$file-${BETA_VERSION}.tgz"
68+
if ! helm push "\$CHART" "oci://${ECR_REPOSITORY_URI}/voiceflow-charts-beta" \
69+
> "$LOG_DIR/\$file-push-ecr.log" 2>&1; then
70+
echo "FAILED: ECR push for \$file"
71+
cat "$LOG_DIR/\$file-push-ecr.log"
72+
exit 1
73+
fi
74+
echo "Pushed \$file to ECR"
75+
HELPER
76+
chmod +x /tmp/push-ecr.sh
77+
78+
# Start ECR pushes in background (parallel, limited to $MAX_PARALLEL)
79+
printf '%s\0' "${CHARTS[@]}" | xargs -0 -n1 -P"$MAX_PARALLEL" /tmp/push-ecr.sh &
80+
ECR_PID=$!
81+
82+
# Push to S3 sequentially in foreground (protects shared bucket index)
83+
S3_FAILED=0
84+
for file in "${CHARTS[@]}"; do
85+
CHART="$file/$file-${BETA_VERSION}.tgz"
86+
echo "Pushing $file to S3..."
87+
if ! helm s3 push --force "$CHART" voiceflow-charts-s3-beta \
88+
> "$LOG_DIR/$file-push-s3.log" 2>&1; then
89+
echo "FAILED: S3 push for $file"
90+
cat "$LOG_DIR/$file-push-s3.log"
91+
S3_FAILED=1
92+
else
93+
echo "Pushed $file to S3"
94+
fi
95+
done
96+
97+
# Wait for ECR pushes to finish
98+
ECR_FAILED=0
99+
if ! wait "$ECR_PID"; then
100+
ECR_FAILED=1
101+
fi
102+
103+
if [ "$S3_FAILED" -ne 0 ] || [ "$ECR_FAILED" -ne 0 ]; then
104+
echo "One or more pushes failed. See logs in $LOG_DIR"
105+
exit 1
106+
fi
107+
108+
echo "All charts published to S3 and ECR"

0 commit comments

Comments
 (0)