Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,34 @@ workflows:
branches:
only:
- main
- publish_helm_chart:
requires:
- run_unit_tests_python_client
- run_unit_tests_server
- build_image
filters:
branches:
only:
- main

jobs:
publish_helm_chart:
docker:
- image: cimg/aws:2023.09
resource_class: small
steps:
- checkout
- aws-cli/setup:
role-arn: ${CIRCLECI_ROLE_ARN}
aws-region: AWS_REGION
- run:
name: Install helm
command: |
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
- run:
name: Publish model-engine Helm chart to public ECR (idempotent)
command: |
./.circleci/scripts/publish-helm-chart.sh
run_unit_tests_python_client:
docker:
- image: python:3.13-bookworm
Expand Down
43 changes: 43 additions & 0 deletions .circleci/scripts/publish-helm-chart.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env bash
# Publish the model-engine Helm chart to the public ECR registry.
#
# Idempotent: reads the chart version from charts/model-engine/Chart.yaml and
# only packages + pushes when that version tag is not already published. So it
# is safe to run on every merge to main — an actual publish happens only when
# the chart version was bumped.
#
# Requires: helm, aws-cli, and AWS credentials for a principal in account
# 692474966980 with ecr-public publish permission on
# model-engine-helm-charts/model-engine (the CircleCI `circleci` OIDC role).
set -euo pipefail

CHART_DIR="charts/model-engine"
PUBLIC_ECR_REGISTRY="public.ecr.aws/b2z8n5q1"
CHART_REPO_PATH="model-engine-helm-charts" # helm appends the chart name (model-engine)
ECR_REPOSITORY_NAME="model-engine-helm-charts/model-engine"
ECR_PUBLIC_REGION="us-east-1" # ECR Public API only exists in us-east-1

VERSION="$(helm show chart "${CHART_DIR}" | awk '/^version:/ {print $2}')"
if [[ -z "${VERSION}" ]]; then
echo "ERROR: could not determine chart version from ${CHART_DIR}/Chart.yaml" >&2
exit 1
fi
echo "model-engine chart version: ${VERSION}"

if aws ecr-public describe-images \
--region "${ECR_PUBLIC_REGION}" \
--repository-name "${ECR_REPOSITORY_NAME}" \
--image-ids imageTag="${VERSION}" >/dev/null 2>&1; then
echo "Chart ${VERSION} is already published to ${PUBLIC_ECR_REGISTRY}/${ECR_REPOSITORY_NAME} — nothing to do."
exit 0
fi
Comment on lines +27 to +33

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Silent failure on non-404 errors in idempotency check

describe-images errors are fully suppressed (>/dev/null 2>&1), so any failure — permission denied, transient network error, throttling — is interpreted the same way as "image not found" and causes the script to proceed to publish. If the OIDC role gains push permission but is missing ecr-public:DescribeImages, the check is effectively bypassed on every run; publishing would succeed on new versions but produce a redundant push attempt on unchanged versions. Consider checking the exit code separately from error output so a non-404 failure can surface rather than silently proceeding.

Prompt To Fix With AI
This is a comment left during a code review.
Path: .circleci/scripts/publish-helm-chart.sh
Line: 27-33

Comment:
**Silent failure on non-404 errors in idempotency check**

`describe-images` errors are fully suppressed (`>/dev/null 2>&1`), so any failure — permission denied, transient network error, throttling — is interpreted the same way as "image not found" and causes the script to proceed to publish. If the OIDC role gains push permission but is missing `ecr-public:DescribeImages`, the check is effectively bypassed on every run; publishing would succeed on new versions but produce a redundant push attempt on unchanged versions. Consider checking the exit code separately from error output so a non-404 failure can surface rather than silently proceeding.

How can I resolve this? If you propose a fix, please make it concise.

Fix in Cursor Fix in Claude Code Fix in Codex


echo "Publishing model-engine chart ${VERSION}..."
aws ecr-public get-login-password --region "${ECR_PUBLIC_REGION}" \
| helm registry login --username AWS --password-stdin public.ecr.aws

PKG_DIR="$(mktemp -d)"
helm package "${CHART_DIR}" -d "${PKG_DIR}"
helm push "${PKG_DIR}/model-engine-${VERSION}.tgz" "oci://${PUBLIC_ECR_REGISTRY}/${CHART_REPO_PATH}"

echo "Published oci://${PUBLIC_ECR_REGISTRY}/${ECR_REPOSITORY_NAME}:${VERSION}"