Workflows fil #1
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 Image | |
| on: | |
| push: | |
| branches: [ "main" ] | |
| env: | |
| IMAGE_NAME: ghcr.io/${{ github.repository }}/min-nginx-app | |
| jobs: | |
| build-scan-push: | |
| name: Build, Scan and Push | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| security-events: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Log in to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Build Docker image | |
| run: | | |
| docker build -t $IMAGE_NAME:${{ github.sha }} . | |
| - name: Scan image with Trivy and upload results | |
| uses: aquasecurity/trivy-action@master | |
| with: | |
| image-ref: $IMAGE_NAME:${{ github.sha }} | |
| format: 'sarif' | |
| output: 'trivy-results.sarif' | |
| severity: 'HIGH,CRITICAL' | |
| - name: Upload Trivy scan results to GitHub Security tab | |
| uses: github/codeql-action/upload-sarif@v3 | |
| with: | |
| sarif_file: 'trivy-results.sarif' | |
| - name: Push Docker image to registry | |
| run: | | |
| docker push $IMAGE_NAME:${{ github.sha }} |