-
Notifications
You must be signed in to change notification settings - Fork 23
feat(ci): auto-build DocumentDB images on new upstream release #410
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Ritvik-Jayaswal
wants to merge
10
commits into
documentdb:main
Choose a base branch
from
Ritvik-Jayaswal:developer/auto-build-documentdb-images
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
93c28bc
feat(ci): auto-build DocumentDB images on new upstream release
rjayaswal 48bad40
refactor(ci): build DocumentDB extension from official APT repo + web…
rjayaswal c78eee1
Merge remote-tracking branch 'origin/main' into developer/auto-build-…
rjayaswal 90d90cd
fix(ci): pin DocumentDB APT package with dashed Debian version
rjayaswal ba17048
ci: exercise Dockerfile_extension in e2e build mode with local deb
rjayaswal 80d0f0a
fix(ci): parse APT Packages index by stanza in documentdb verify
rjayaswal 6d18ca9
fix(ci): lowercase GHCR repository in documentdb image refs
rjayaswal b868660
fix(ci): guard optional ARGs under set -u in Dockerfile_extension
rjayaswal 5f7c17f
fix(ci): stop editing workflow files in version-bump PR
rjayaswal ec9dbe8
fix(ci): harden watch workflow and anchor release sed substitutions
rjayaswal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,166 @@ | ||
| name: WATCH - DocumentDB Releases | ||
|
|
||
| # Polls the upstream documentdb/documentdb repository for new releases and, when a | ||
| # newer version than the operator's current default is published, automatically: | ||
| # 1. Builds candidate documentdb + gateway images (build_documentdb_images.yml) | ||
| # 2. Promotes them to release tags and opens a "chore: bump DocumentDB images" PR | ||
| # (release_documentdb_images.yml) | ||
| # | ||
| # The version-bump PR is the human gate: a maintainer reviews and merges it, which | ||
| # is what actually makes the new version the default for new installs. | ||
| # | ||
| # Only handles the DATABASE version track (documentDbVersion). Operator/sidecar | ||
| # images follow a separate track (build_operator_images.yml / release_operator.yml). | ||
|
|
||
| on: | ||
| schedule: | ||
| # Every 6 hours. GitHub's releases/latest excludes drafts and pre-releases, | ||
| # so pre-releases never trigger this automation. | ||
| - cron: '0 */6 * * *' | ||
|
|
||
| workflow_dispatch: | ||
| inputs: | ||
| version: | ||
| description: 'Override upstream version to release (e.g. 0.111.0). Leave empty to auto-detect latest.' | ||
| required: false | ||
| default: '' | ||
| dry_run: | ||
| description: 'Only detect and report; do not build or open a PR.' | ||
| required: false | ||
| default: false | ||
| type: boolean | ||
|
|
||
| permissions: | ||
| contents: write | ||
| packages: write | ||
| pull-requests: write | ||
| id-token: write | ||
|
|
||
| env: | ||
| UPSTREAM_REPO: documentdb/documentdb | ||
|
|
||
| jobs: | ||
| # --------------------------------------------------------------------------- | ||
| # Detect whether a newer upstream release exists | ||
| # --------------------------------------------------------------------------- | ||
| detect: | ||
| name: Detect new DocumentDB release | ||
| runs-on: ubuntu-22.04 | ||
| outputs: | ||
| new_version: ${{ steps.check.outputs.new_version }} | ||
| should_release: ${{ steps.check.outputs.should_release }} | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| persist-credentials: false | ||
|
|
||
| - name: Resolve latest upstream release | ||
| id: upstream | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| run: | | ||
| set -euo pipefail | ||
| OVERRIDE="${{ github.event.inputs.version || '' }}" | ||
| if [[ -n "$OVERRIDE" ]]; then | ||
| RAW="$OVERRIDE" | ||
| echo "Using manual version override: $RAW" | ||
| else | ||
| RAW=$(gh api "repos/${UPSTREAM_REPO}/releases/latest" --jq '.tag_name') | ||
| echo "Latest upstream release tag: $RAW" | ||
| fi | ||
| # Normalize: strip leading 'v', convert dashed (0.110-0) to dotted (0.110.0). | ||
| RAW="${RAW#v}" | ||
| if [[ "$RAW" =~ ^[0-9]+\.[0-9]+-[0-9]+$ ]]; then | ||
| VERSION="${RAW/-/.}" | ||
| else | ||
| VERSION="$RAW" | ||
| fi | ||
| if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | ||
| echo "Could not parse a dotted semver from upstream tag '$RAW'" >&2 | ||
| exit 1 | ||
| fi | ||
| echo "version=$VERSION" >> "$GITHUB_OUTPUT" | ||
| echo "Upstream DocumentDB version: $VERSION" | ||
|
|
||
| - name: Read current default version | ||
| id: current | ||
| run: | | ||
| set -euo pipefail | ||
| CURRENT=$(sed -nE 's|^[[:space:]]*DEFAULT_DOCUMENTDB_IMAGE[[:space:]]*=.*:([0-9]+\.[0-9]+\.[0-9]+)".*|\1|p' \ | ||
| operator/src/internal/utils/constants.go | head -1) | ||
| if [[ -z "$CURRENT" ]]; then | ||
| echo "Failed to read DEFAULT_DOCUMENTDB_IMAGE from operator/src/internal/utils/constants.go" >&2 | ||
| exit 1 | ||
| fi | ||
| echo "version=$CURRENT" >> "$GITHUB_OUTPUT" | ||
| echo "Current default DocumentDB version: $CURRENT" | ||
|
|
||
| - name: Decide whether to release | ||
| id: check | ||
| run: | | ||
| set -euo pipefail | ||
| NEW="${{ steps.upstream.outputs.version }}" | ||
| CUR="${{ steps.current.outputs.version }}" | ||
| echo "new_version=$NEW" >> "$GITHUB_OUTPUT" | ||
|
|
||
| # Not newer than the current default? Nothing to do. | ||
| if [[ "$NEW" == "$CUR" ]] || \ | ||
| [[ "$(printf '%s\n%s\n' "$CUR" "$NEW" | sort -V | tail -1)" != "$NEW" ]]; then | ||
| echo "Upstream $NEW is not newer than current default $CUR. Nothing to do." | ||
| echo "should_release=false" >> "$GITHUB_OUTPUT" | ||
| exit 0 | ||
| fi | ||
|
|
||
| # Already promoted? If the release tag exists, the bump PR is likely | ||
| # pending review/merge, so don't rebuild on every cron tick. | ||
| echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin | ||
| if docker manifest inspect "ghcr.io/${{ github.repository }}/documentdb:${NEW}" >/dev/null 2>&1; then | ||
| echo "Release image documentdb:${NEW} already exists; version-bump PR is likely pending merge. Skipping." | ||
| echo "should_release=false" >> "$GITHUB_OUTPUT" | ||
| exit 0 | ||
| fi | ||
|
|
||
|
|
||
| if [[ "${{ github.event.inputs.dry_run }}" == "true" ]]; then | ||
| echo "Dry run: a newer version $NEW (current $CUR) was detected but no build/PR will be created." | ||
| echo "should_release=false" >> "$GITHUB_OUTPUT" | ||
| exit 0 | ||
| fi | ||
|
|
||
| echo "New upstream version $NEW detected (current default $CUR). Proceeding to build + release." | ||
| echo "should_release=true" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Detection summary | ||
| if: always() | ||
| run: | | ||
| echo "## DocumentDB Release Watch" >> "$GITHUB_STEP_SUMMARY" | ||
| echo "" >> "$GITHUB_STEP_SUMMARY" | ||
| echo "- **Upstream latest**: \`${{ steps.upstream.outputs.version }}\`" >> "$GITHUB_STEP_SUMMARY" | ||
| echo "- **Current default**: \`${{ steps.current.outputs.version }}\`" >> "$GITHUB_STEP_SUMMARY" | ||
| echo "- **Action**: ${{ steps.check.outputs.should_release == 'true' && 'Building candidate images and opening version-bump PR' || 'No release needed' }}" >> "$GITHUB_STEP_SUMMARY" | ||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # Build candidate images for the new version | ||
| # --------------------------------------------------------------------------- | ||
| build: | ||
| name: Build candidate images | ||
| needs: detect | ||
| if: needs.detect.outputs.should_release == 'true' | ||
| uses: ./.github/workflows/build_documentdb_images.yml | ||
| with: | ||
| version: ${{ needs.detect.outputs.new_version }} | ||
| secrets: inherit | ||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # Promote candidate images and open the version-bump PR | ||
| # --------------------------------------------------------------------------- | ||
| release: | ||
| name: Promote images and open version-bump PR | ||
| needs: [detect, build] | ||
| if: needs.detect.outputs.should_release == 'true' | ||
| uses: ./.github/workflows/release_documentdb_images.yml | ||
| with: | ||
| candidate_version: ${{ needs.build.outputs.image_tag }} | ||
| version: ${{ needs.detect.outputs.new_version }} | ||
| update_defaults: true | ||
| secrets: inherit | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Minor — no
concurrency:group on the watch workflow.The daily
schedulecron, arepository_dispatch, and a manualworkflow_dispatchcan overlap for the same upstream version, launching parallel build→promote→PR chains. Thedetect"images already exist" guard narrows but doesn't close the window — two runs can both pass it before either finishes pushing, racing the promote step and theauto/documentdb-<version>PR branch.Fix: add a single-flight group, e.g.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of cron I was hoping for a web-hhok somethign we are also planning for COPR
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in ec9dbe8. Added a single-flight concurrency group keyed on the resolved upstream version, with
cancel-in-progress: falseso a half-finished promotion is allowed to converge rather than being killed mid-flight:This closes the window you described — overlapping cron /
repository_dispatch/workflow_dispatchruns for the same version now serialize instead of racing the promote step and theauto/documentdb-<version>PR branch.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, and that's already the primary path here: the workflow's main trigger is a
repository_dispatch(documentdb-release) that upstreamdocumentdb/documentdbfires onrelease: published— a webhook-style push, not polling. A reference sender workflow is drafted indocs/designs/upstream-release-dispatch-sender.md. The dailyschedulecron is kept only as a low-frequency safety-net for a missed/dropped dispatch, and it's cheap (it exits early atdetectwhen there's nothing newer). Happy to align the dispatch event name / payload shape with whatever you land on for COPR so both consumers share one sender contract.