-
Notifications
You must be signed in to change notification settings - Fork 276
feat: GHA for deploying docker images to GAR on dev push #6189
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| name: Build Docker image for dev and publish to GAR | ||
|
|
||
| permissions: {} | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - dev | ||
|
|
||
| jobs: | ||
| build_and_push_to_gar: | ||
| # Define permissions at the job level | ||
| permissions: | ||
| contents: "read" # Needed for checkout | ||
| id-token: "write" # Needed for GCP auth | ||
| packages: "none" # Explicitly disable package permissions | ||
| name: Build and Push Docker image to GAR | ||
| runs-on: ubuntu-latest | ||
| environment: build | ||
| env: | ||
| GAR_IMAGE_BASE: ${{ vars.GAR_REPO }}/${{ github.event.repository.name }} # Base name for GAR image | ||
| GAR_REGISTRY: us-docker.pkg.dev | ||
| steps: | ||
| - name: Check out the repo | ||
| uses: actions/checkout@v5 | ||
| with: | ||
| persist-credentials: false | ||
|
|
||
| - name: Authenticate to Google Cloud | ||
| id: gcp-auth | ||
| uses: google-github-actions/auth@v3 | ||
| with: | ||
| token_format: access_token | ||
| workload_identity_provider: ${{ vars.GCPV2_GITHUB_WORKLOAD_IDENTITY_PROVIDER }} | ||
| service_account: ${{ vars.GCP_GAR_SERVICE_ACCOUNT }} | ||
|
|
||
| - name: Login to Artifact Registry | ||
| id: gar-login | ||
| uses: docker/login-action@v3 | ||
| with: | ||
| registry: ${{ env.GAR_REGISTRY }} | ||
| username: oauth2accesstoken | ||
| password: ${{ steps.gcp-auth.outputs.access_token }} | ||
|
|
||
| - name: Extract metadata (tags, labels) for Docker | ||
| id: meta | ||
| uses: docker/metadata-action@v5 | ||
| with: | ||
| # Only generate the image name for GAR | ||
| images: ${{ env.GAR_IMAGE_BASE }} | ||
| tags: | | ||
| # Generate tag based on short commit SHA with dev- prefix | ||
| type=sha,format=short,prefix=dev- | ||
|
|
||
| - name: Create version.json | ||
| run: | | ||
| # Use full sha here for version.json content | ||
| echo "{\"commit\":\"$GITHUB_SHA\",\"version\":\"$GITHUB_REF_NAME\",\"source\":\"https://github.com/$GITHUB_REPOSITORY\",\"build\":\"$GITHUB_RUN_ID\"}" > version.json | ||
|
|
||
| - name: Set up QEMU | ||
| uses: docker/setup-qemu-action@v3 | ||
|
|
||
| - name: Set up Docker Buildx | ||
| id: buildx | ||
| uses: docker/setup-buildx-action@v3 | ||
|
|
||
| - name: Build and push Docker image to GAR | ||
| id: build-and-push | ||
| uses: docker/build-push-action@v6 | ||
| with: | ||
| context: . | ||
| # Push is true to push to GAR after build | ||
| push: true | ||
| # Tags generated by the metadata action (only GAR tag) | ||
| tags: ${{ steps.meta.outputs.tags }} | ||
| # Pass build arguments | ||
| build-args: | | ||
| SENTRY_RELEASE=${{ github.sha }} # Use full SHA for Sentry release clarity | ||
| NEXT_PUBLIC_SENTRY_DSN=${{ secrets.SENTRY_DSN }} | ||
| # Pass secrets securely to the build | ||
| secrets: | | ||
| SENTRY_AUTH_TOKEN=${{ secrets.SENTRY_AUTH_TOKEN }} | ||
| # Enable build cache for faster builds (optional but recommended) | ||
| cache-from: type=gha | ||
| cache-to: type=gha,mode=max | ||
|
|
||
| - name: Print Image URI | ||
| run: | | ||
| echo "Pushed GAR image: ${{ steps.meta.outputs.tags }}" | ||
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.
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.
where does the environment get passed in to sentry?
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.
rather than doing this in the dockerfile I'd recommend using the sentry release action getsentry/action-release@v1