Repository navigation
fix(ci): fix race conditions and syntax errors #310
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a9d2df1
fix(ci): fix omitted image inputs in deploy.yml and indents in pr-aut…
Ryan-Millard 547ad4c
ci(docker-ci): use main's build cache as well in case other build cac…
Ryan-Millard 302399f
ci(ci.yml): switch to main from latest docker image tag
Ryan-Millard 8d440f5
fix(ci): wait for Docker image before running dependent jobs
Ryan-Millard db20776
perf(ci): use curl instead of docker pull to check image existence in…
Ryan-Millard 6230fa5
feat(ci): add new update check to wait-for-docker-image.yml
Ryan-Millard 790a081
ci(permissions): update permissions in wait-for-docker-image.yml
Ryan-Millard 3596a86
ci(deploy): fix env usage by using a setup job instead
Ryan-Millard 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
Some comments aren't visible on the classic Files Changed page.
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
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,81 @@ | ||
| # What is the point in this file if it is just an exponential backoff? | ||
| # | ||
| # The file is used to prevent race conditions between docker-ci.yml and any workflow that | ||
| # depends on the image it pushes. Without this, workflows like ci.yml may pull an outdated | ||
| # or unavailable image — most likely on a fresh PR where the image does not exist yet — | ||
| # causing failures that have nothing to do with the code being tested. | ||
|
|
||
| name: Wait for Docker Image | ||
|
|
||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| image: | ||
| required: false | ||
| type: string | ||
| default: ryanmillard/img2num-dev:main | ||
| description: > | ||
| Docker image that this workflow waits for. It will check Docker Hub for this image. Defaults to: ryanmillard/img2num-dev:main | ||
| max_attempts: | ||
| required: false | ||
| type: number | ||
| default: 8 | ||
| description: > | ||
| Maximum number of pull attempts before giving up. | ||
| With the default of 8 attempts and an initial delay of 15s, | ||
| the total worst-case wait is ~63 minutes (15+30+60+120+240+480+960+1920s). | ||
| initial_delay_seconds: | ||
| required: false | ||
| type: number | ||
| default: 15 | ||
| description: > | ||
| Initial delay in seconds between attempts. Doubles after each failure. | ||
| With the default of 15s and 8 attempts, worst-case wait is ~63 minutes. | ||
|
|
||
| permissions: {} | ||
|
|
||
| jobs: | ||
| wait-for-image: | ||
| name: Wait for Docker Image | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Wait for image to be available | ||
| run: | | ||
| # Retries with exponential backoff. | ||
| # Defaults: 8 attempts, 15s initial delay -> delays of 15, 30, 60, 120, 240, 480, 960, 1920 (all in seconds) | ||
| # Total worst-case wait with defaults: ~63 minutes (enough for Dawn to typically be built into the image) | ||
| IMAGE="${{ inputs.image }}" | ||
| MAX_ATTEMPTS=${{ inputs.max_attempts }} | ||
| DELAY=${{ inputs.initial_delay_seconds }} | ||
| IMAGE_NAME="${IMAGE%%:*}" | ||
| TAG="${IMAGE##*:}" | ||
| WORKFLOW_STARTED_AT="${{ github.event.repository.updated_at }}" | ||
| WORKFLOW_START_TS=$(date -d "$WORKFLOW_STARTED_AT" +%s) | ||
|
|
||
| for i in $(seq 1 $MAX_ATTEMPTS); do | ||
| echo "Attempt $i of $MAX_ATTEMPTS: checking $IMAGE..." | ||
|
|
||
| LAST_PUSHED=$(curl -sf "https://hub.docker.com/v2/repositories/${IMAGE_NAME}/tags/${TAG}/" \ | ||
| | jq -r '.tag_last_pushed // empty') | ||
|
|
||
| if [[ -n "$LAST_PUSHED" ]]; then | ||
| LAST_PUSHED_TS=$(date -d "$LAST_PUSHED" +%s) | ||
| echo "Image last pushed at: $LAST_PUSHED (workflow started at: $WORKFLOW_STARTED_AT)" | ||
|
|
||
| if [[ "$LAST_PUSHED_TS" -ge "$WORKFLOW_START_TS" ]]; then | ||
| echo "Image is fresh, proceeding." | ||
| exit 0 | ||
| else | ||
| echo "Image exists but is stale." | ||
| fi | ||
| else | ||
| echo "Image not found yet." | ||
| fi | ||
|
|
||
| echo "Waiting ${DELAY}s..." | ||
| sleep $DELAY | ||
| DELAY=$((DELAY * 2)) | ||
| done | ||
|
|
||
| echo "Image never became fresh after $MAX_ATTEMPTS attempts" | ||
| exit 1 | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.