-
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chore(CI/CD): Add new workflow to create image for each opened PR
- Loading branch information
1 parent
f533fea
commit dfd5149
Showing
1 changed file
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,67 @@ | ||
name: Build and Push Docker Image for PR | ||
|
||
on: | ||
pull_request: | ||
types: [opened, synchronize, reopened] | ||
|
||
jobs: | ||
|
||
build_image_and_push_to_registry: | ||
if: github.event.action != 'closed' && github.repository == 'l7mp/stunner' | ||
name: Push Docker image to DockerHub | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Login to Docker Hub | ||
uses: docker/login-action@v2 | ||
with: | ||
username: ${{ secrets.DOCKER_USER }} | ||
password: ${{ secrets.DOCKER_TOKEN }} | ||
|
||
- name: Build and Push Docker Image | ||
id: docker_build | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
platforms: linux/amd64,linux/arm64 | ||
push: true | ||
tags: | | ||
l7mp/stunner:pr-${{ github.event.pull_request.number }} | ||
- name: Comment on PR | ||
if: success() && github.event_name == 'pull_request' | ||
uses: actions/github-script@v6 | ||
with: | ||
script: | | ||
const prNumber = context.issue.number; | ||
const comment = `The Docker image for this pull request (#${prNumber}) has been successfully built and pushed to DockerHub as \`docker.io/l7mp/stunner:pr-${prNumber}\`.`; | ||
github.rest.issues.createComment({ | ||
issue_number: prNumber, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
body: comment, | ||
}); | ||
delete_docker_image_tag: | ||
if: github.event.action == 'closed' && github.repository == 'l7mp/stunner' | ||
name: Delete Docker Image Tag from DockerHub | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Delete Docker Image Tag | ||
env: | ||
DOCKER_USER: ${{ secrets.DOCKER_USER }} | ||
DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }} | ||
run: | | ||
PR_NUMBER=${{ github.event.pull_request.number }} | ||
curl -s -u "$DOCKER_USER:$DOCKER_TOKEN" \ | ||
-X DELETE "https://hub.docker.com/v2/repositories/l7mp/stunner/tags/pr-$PR_NUMBER/" \ | ||
-w "HTTP Response Code: %{http_code}\n" |