|
| 1 | +name: Docker image for Goss |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + tags: |
| 8 | + - "v*" |
| 9 | + workflow_dispatch: |
| 10 | + |
| 11 | +env: |
| 12 | + PLATFORMS: "linux/amd64,linux/arm64" |
| 13 | + |
| 14 | +jobs: |
| 15 | + goss: |
| 16 | + name: Build and push Docker image |
| 17 | + runs-on: ubuntu-latest |
| 18 | + permissions: |
| 19 | + packages: write |
| 20 | + contents: read |
| 21 | + security-events: write # To upload Trivy sarif files |
| 22 | + |
| 23 | + steps: |
| 24 | + - name: Checkout |
| 25 | + uses: actions/checkout@v4 |
| 26 | + |
| 27 | + - name: Set up QEMU |
| 28 | + uses: docker/setup-qemu-action@v3 |
| 29 | + |
| 30 | + - name: Set up Docker Buildx |
| 31 | + uses: docker/setup-buildx-action@v3 |
| 32 | + |
| 33 | + - name: Login to GHCR |
| 34 | + uses: docker/login-action@v3 |
| 35 | + with: |
| 36 | + registry: ghcr.io |
| 37 | + username: ${{ github.repository_owner }} |
| 38 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 39 | + |
| 40 | + - name: Extract metadata (tags, labels) for Docker |
| 41 | + id: meta |
| 42 | + uses: docker/metadata-action@v5 |
| 43 | + with: |
| 44 | + images: | |
| 45 | + ghcr.io/${{ github.repository_owner }}/goss |
| 46 | +
|
| 47 | + - name: Get latest git tag |
| 48 | + uses: actions-ecosystem/action-get-latest-tag@v1 |
| 49 | + id: get-latest-tag |
| 50 | + |
| 51 | + - name: Set short git commit SHA |
| 52 | + run: | |
| 53 | + calculatedSha=$(git rev-parse --short ${{ github.sha }}) |
| 54 | + echo "COMMIT_SHORT_SHA=$calculatedSha" >> $GITHUB_ENV |
| 55 | +
|
| 56 | + - name: Get the current version of Go from project. |
| 57 | + run: echo "GO_VERSION_FROM_PROJECT=$(go mod edit -json | jq -r .Go)" >> $GITHUB_ENV |
| 58 | + |
| 59 | + - name: Build master goss image |
| 60 | + if: github.ref_name == 'master' |
| 61 | + uses: docker/build-push-action@v5 |
| 62 | + with: |
| 63 | + build-args: | |
| 64 | + GO_VERSION=${{ env.GO_VERSION_FROM_PROJECT }} |
| 65 | + GOSS_VERSION=${{ steps.get-latest-tag.outputs.tag }}-${{ github.ref_name }}+${{ env.COMMIT_SHORT_SHA }} |
| 66 | + context: . |
| 67 | + push: true |
| 68 | + tags: | |
| 69 | + ghcr.io/${{ github.repository_owner }}/goss:master |
| 70 | + labels: ${{ steps.meta.outputs.labels }} |
| 71 | + platforms: ${{ env.PLATFORMS }} |
| 72 | + |
| 73 | + - name: Build release goss image |
| 74 | + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') |
| 75 | + uses: docker/build-push-action@v5 |
| 76 | + with: |
| 77 | + build-args: | |
| 78 | + GO_VERSION=${{ env.GO_VERSION_FROM_PROJECT }} |
| 79 | + GOSS_VERSION=${{ github.ref_name }} |
| 80 | + context: . |
| 81 | + push: true |
| 82 | + tags: | |
| 83 | + ghcr.io/${{ github.repository_owner }}/goss:latest |
| 84 | + ghcr.io/${{ github.repository_owner }}/goss:${{ github.ref_name }} |
| 85 | + labels: ${{ steps.meta.outputs.labels }} |
| 86 | + platforms: ${{ env.PLATFORMS }} |
| 87 | + |
| 88 | + - name: Run Trivy vulnerability scanner |
| 89 | + uses: aquasecurity/trivy-action@master |
| 90 | + with: |
| 91 | + image-ref: ghcr.io/${{ github.repository_owner }}/goss:master |
| 92 | + format: "sarif" |
| 93 | + output: "trivy-results.sarif" |
| 94 | + |
| 95 | + - name: Upload Trivy scan results to GitHub Security tab |
| 96 | + uses: github/codeql-action/upload-sarif@v3 |
| 97 | + with: |
| 98 | + sarif_file: "trivy-results.sarif" |
0 commit comments