Skip to content
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

Fix race condition when publishing images #848

Merged
merged 5 commits into from
Jan 22, 2025

Conversation

lorenyu
Copy link
Contributor

@lorenyu lorenyu commented Jan 22, 2025

Ticket

Resolves #836

Changes

The ci-{{app_name}}-infra-service.yml and cd-{{app_name}}.yml workflows
occasionally run into issues trying to publish an already existing image tag[1],
failing with something like:

tag invalid: The image tag '48995925face06c5fcb68fc52c50e7d57bb46ff6' already exists in the 'platform-nextjs-app' repository and cannot be overwritten because the repository is immutable.

I believe what's happening is that for merges to main, the two workflows get
kicked off at the same time, both needing build and publish an image for the
same commit and using different methods for doing that building/publishing.
ci-{{app_name}}-infra-service.yml runs the commands internally to its test
logic, cd-{{app_name}}.yml uses the build-and-publish.yml workflow.

By having ci-{{app_name}}-infra-service.yml use the re-usable
build-and-publish workflow that cd-{{app_name}}.yml is using, which has an
internal concurrency limit, the workflows should no longer race against each
other to build the same commit.

[1] https://github.com/navapbc/platform-test-nextjs/actions/runs/12484891877/job/34842946860

Testing

see navapbc/platform-test#146

echo "Commit hash: $COMMIT_HASH"
echo "commit_hash=$COMMIT_HASH" >> "$GITHUB_OUTPUT"
build-and-publish:
name: Build and publish
runs-on: ubuntu-latest
needs: get-commit-hash
concurrency: ${{ github.workflow }}-${{ needs.get-commit-hash.outputs.commit_hash }}
concurrency: ${{ github.workflow }}-${{ inputs.app_name }}-${{ needs.get-commit-hash.outputs.commit_hash }}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Add app_name to the concurrency group so that multiple apps can build at the same time

@lorenyu lorenyu requested a review from doshitan January 22, 2025 21:35
Copy link
Contributor

@doshitan doshitan left a comment

Choose a reason for hiding this comment

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

I think comment can be cleaned up, otherwise looks good.

.github/workflows/ci-{{app_name}}-infra-service.yml.jinja Outdated Show resolved Hide resolved
@lorenyu lorenyu merged commit 58ef707 into main Jan 22, 2025
9 checks passed
@lorenyu lorenyu deleted the doshitan/avoid-race-infra-service-ci branch January 22, 2025 21:52
lorenyu added a commit that referenced this pull request Jan 22, 2025
Previous fix #848 didn't
quite fix the race condition (see
https://github.com/navapbc/platform-test/actions/runs/12917748724/attempts/1).
I think it’s because the github.workflow in the concurrency group refers
to the parent workflow, which is different, so cd-app.yml and
ci-app-infra-service.yml both calling build-and-publish.yml workflow
would produce different concurrency groups.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Race condition between infra-app-service.yml and build-and-publish workflows
2 participants