|
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 | | - if: github.ref_name == 'master' |
49 | | - id: get-latest-tag |
50 | | - run: | |
51 | | - # source: https://github.com/actions-ecosystem/action-get-latest-tag/blob/main/entrypoint.sh |
52 | | - set -e |
53 | | - git config --global --add safe.directory /github/workspace |
54 | | - git fetch --tags --force |
55 | | - # This suppress an error occurred when the repository is a complete one. |
56 | | - git fetch --prune --unshallow 2>/dev/null || true |
57 | | - latest_tag=$(git describe --abbrev=0 --tags || true) |
58 | | - echo "tag=${latest_tag}" >> "$GITHUB_OUTPUT" |
59 | | - echo "Latest tag: $latest_tag" |
60 | | -
|
61 | | - - name: Set short git commit SHA |
62 | | - if: github.ref_name == 'master' |
63 | | - run: | |
64 | | - calculatedSha=$(git rev-parse --short ${{ github.sha }}) |
65 | | - echo "COMMIT_SHORT_SHA=$calculatedSha" >> $GITHUB_ENV |
66 | | - echo "COMMIT_SHORT_SHA: $calculatedSha" |
67 | | -
|
68 | | - - name: Get the current version of Go from project. |
69 | | - run: echo "GO_VERSION_FROM_PROJECT=$(go mod edit -json | jq -r .Go)" >> $GITHUB_ENV |
70 | | - |
71 | | - - name: Build master goss image |
72 | | - if: github.ref_name == 'master' |
73 | | - uses: docker/build-push-action@v6 |
74 | | - with: |
75 | | - build-args: | |
76 | | - GO_VERSION=${{ env.GO_VERSION_FROM_PROJECT }} |
77 | | - GOSS_VERSION=${{ steps.get-latest-tag.outputs.tag }}-${{ github.ref_name }}+${{ env.COMMIT_SHORT_SHA }} |
78 | | - context: . |
79 | | - push: true |
80 | | - tags: | |
81 | | - ghcr.io/${{ github.repository_owner }}/goss:master |
82 | | - labels: ${{ steps.meta.outputs.labels }} |
83 | | - platforms: ${{ env.PLATFORMS }} |
84 | | - |
85 | | - - name: Build release goss image |
86 | | - if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') |
87 | | - uses: docker/build-push-action@v6 |
88 | | - with: |
89 | | - build-args: | |
90 | | - GO_VERSION=${{ env.GO_VERSION_FROM_PROJECT }} |
91 | | - GOSS_VERSION=${{ github.ref_name }} |
92 | | - context: . |
93 | | - push: true |
94 | | - tags: | |
95 | | - ghcr.io/${{ github.repository_owner }}/goss:latest |
96 | | - ghcr.io/${{ github.repository_owner }}/goss:${{ github.ref_name }} |
97 | | - labels: ${{ steps.meta.outputs.labels }} |
98 | | - platforms: ${{ env.PLATFORMS }} |
99 | | - |
100 | | - - name: Run Trivy vulnerability scanner |
101 | | - uses: aquasecurity/[email protected] |
102 | | - with: |
103 | | - image-ref: ghcr.io/${{ github.repository_owner }}/goss:master |
104 | | - format: "sarif" |
105 | | - output: "trivy-results.sarif" |
106 | | - |
107 | | - - name: Upload Trivy scan results to GitHub Security tab |
108 | | - uses: github/codeql-action/upload-sarif@v3 |
109 | | - with: |
110 | | - sarif_file: "trivy-results.sarif" |
| 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 | + if: github.ref_name == 'master' |
| 49 | + id: get-latest-tag |
| 50 | + run: | |
| 51 | + # source: https://github.com/actions-ecosystem/action-get-latest-tag/blob/main/entrypoint.sh |
| 52 | + set -e |
| 53 | + git config --global --add safe.directory /github/workspace |
| 54 | + git fetch --tags --force |
| 55 | + # This suppress an error occurred when the repository is a complete one. |
| 56 | + git fetch --prune --unshallow 2>/dev/null || true |
| 57 | + latest_tag=$(git describe --abbrev=0 --tags || true) |
| 58 | + echo "tag=${latest_tag}" >> "$GITHUB_OUTPUT" |
| 59 | + echo "Latest tag: $latest_tag" |
| 60 | +
|
| 61 | + - name: Set short git commit SHA |
| 62 | + if: github.ref_name == 'master' |
| 63 | + run: | |
| 64 | + calculatedSha=$(git rev-parse --short ${{ github.sha }}) |
| 65 | + echo "COMMIT_SHORT_SHA=$calculatedSha" >> $GITHUB_ENV |
| 66 | + echo "COMMIT_SHORT_SHA: $calculatedSha" |
| 67 | +
|
| 68 | + - name: Get the current version of Go from project. |
| 69 | + run: echo "GO_VERSION_FROM_PROJECT=$(go mod edit -json | jq -r .Go)" >> $GITHUB_ENV |
| 70 | + |
| 71 | + - name: Build master goss image |
| 72 | + if: github.ref_name == 'master' |
| 73 | + uses: docker/build-push-action@v6 |
| 74 | + with: |
| 75 | + build-args: | |
| 76 | + GO_VERSION=${{ env.GO_VERSION_FROM_PROJECT }} |
| 77 | + GOSS_VERSION=${{ steps.get-latest-tag.outputs.tag }}-${{ github.ref_name }}+${{ env.COMMIT_SHORT_SHA }} |
| 78 | + context: . |
| 79 | + push: true |
| 80 | + tags: | |
| 81 | + ghcr.io/${{ github.repository_owner }}/goss:master |
| 82 | + labels: ${{ steps.meta.outputs.labels }} |
| 83 | + platforms: ${{ env.PLATFORMS }} |
| 84 | + |
| 85 | + - name: Build release goss image |
| 86 | + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') |
| 87 | + uses: docker/build-push-action@v6 |
| 88 | + with: |
| 89 | + build-args: | |
| 90 | + GO_VERSION=${{ env.GO_VERSION_FROM_PROJECT }} |
| 91 | + GOSS_VERSION=${{ github.ref_name }} |
| 92 | + context: . |
| 93 | + push: true |
| 94 | + tags: | |
| 95 | + ghcr.io/${{ github.repository_owner }}/goss:latest |
| 96 | + ghcr.io/${{ github.repository_owner }}/goss:${{ github.ref_name }} |
| 97 | + labels: ${{ steps.meta.outputs.labels }} |
| 98 | + platforms: ${{ env.PLATFORMS }} |
| 99 | + |
| 100 | + - name: Run Trivy vulnerability scanner |
| 101 | + uses: aquasecurity/[email protected] |
| 102 | + with: |
| 103 | + image-ref: ghcr.io/${{ github.repository_owner }}/goss:master |
| 104 | + format: "sarif" |
| 105 | + output: "trivy-results.sarif" |
| 106 | + |
| 107 | + - name: Upload Trivy scan results to GitHub Security tab |
| 108 | + uses: github/codeql-action/upload-sarif@v3 |
| 109 | + with: |
| 110 | + sarif_file: "trivy-results.sarif" |
0 commit comments