react Docker Image Deployment #42
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
name: react Docker Image Deployment | |
on: | |
workflow_run: | |
workflows: ["Build React App (front end)"] | |
types: | |
- completed | |
jobs: | |
build: | |
if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
runs-on: ubuntu-latest | |
env: | |
IMAGE_TAG: v2 | |
steps: | |
- uses: actions/checkout@v4 | |
name: Checkout Repository | |
- name: Log in to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_HUB_USERNAME }} | |
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} | |
- name: Build the Docker image | |
run: | | |
docker build -f Dockerfile -t reactdoc:${{ env.IMAGE_TAG }} . | |
- name: Scan Docker image with Trivy | |
uses: aquasecurity/trivy-action@v0.11.0 | |
id: trivy-scan | |
with: | |
image-ref: reactdoc:${{ env.IMAGE_TAG }} | |
severity: HIGH,CRITICAL | |
ignore-unfixed: true | |
- name: Check Trivy scan result | |
if: steps.trivy-scan.outputs.success == 'false' | |
run: | | |
echo "Vulnerabilities found in the image, not pushing to Docker Hub" | |
exit 1 | |
- name: Tag Docker image | |
run: | | |
docker tag reactdoc:${{ env.IMAGE_TAG }} ${{ secrets.DOCKER_HUB_USERNAME }}/reactdoc:${{ env.IMAGE_TAG }} | |
- name: Push Docker image to Docker Hub | |
if: steps.trivy-scan.outputs.success == 'true' | |
run: | | |
docker push ${{ secrets.DOCKER_HUB_USERNAME }}/reactdoc:${{ env.IMAGE_TAG }} |