Update docker.yml #7
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
| name: Build, Scan and Push Docker Image | |
| on: | |
| push: | |
| branches: [ main ] | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| image-tag: ${{ steps.tag.outputs.sha_tag }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| - name: Set image tag | |
| id: tag | |
| run: echo "sha_tag=${GITHUB_SHA}" >> $GITHUB_OUTPUT | |
| - name: Log in to DockerHub | |
| uses: docker/login-action@v2 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Build Docker images | |
| run: | | |
| IMAGE_BASE=${{ secrets.DOCKERHUB_USERNAME }}/myhello | |
| docker build -t $IMAGE_BASE:latest -t $IMAGE_BASE:${{ github.sha }} . | |
| - name: Push Docker images | |
| run: | | |
| IMAGE_BASE=${{ secrets.DOCKERHUB_USERNAME }}/myhello | |
| docker push $IMAGE_BASE:latest | |
| docker push $IMAGE_BASE:${{ github.sha }} | |
| scan: | |
| runs-on: ubuntu-latest | |
| needs: build | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| - name: Trivy Image Scan | |
| uses: aquasecurity/trivy-action@master | |
| with: | |
| image-ref: ${{ secrets.DOCKERHUB_USERNAME }}/myhello:${{ needs.build.outputs.image-tag }} | |
| format: 'table' | |
| exit-code: '1' | |
| ignore-unfixed: true | |
| vuln-type: 'os,library' | |
| severity: 'CRITICAL,HIGH' | |
| scan-type: image | |
| - name: Trivy FS Scan (source & Dockerfile) | |
| uses: aquasecurity/trivy-action@master | |
| with: | |
| scan-type: 'fs' | |
| scan-ref: '.' | |
| format: 'table' | |
| exit-code: '1' | |
| ignore-unfixed: true | |
| vuln-type: 'os,library' | |
| severity: 'CRITICAL,HIGH' |