Skip to content

Commit 9f26520

Browse files
committed
ci: build and scan Docker image like coder/coder
- Build Go binary for linux/amd64 - Build Docker image with buildx - Scan the built image (not filesystem) - Matches coder/coder scanning approach
1 parent 980a039 commit 9f26520

File tree

1 file changed

+33
-7
lines changed

1 file changed

+33
-7
lines changed

.github/workflows/security.yaml

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ jobs:
4646
with:
4747
category: "/language:go"
4848

49-
trivy-repo:
50-
name: Trivy Filesystem Scan
49+
trivy:
50+
name: Trivy Docker Image Scan
5151
runs-on: ubuntu-latest
5252
permissions:
5353
security-events: write
@@ -56,18 +56,44 @@ jobs:
5656
- name: Checkout repository
5757
uses: actions/checkout@v4
5858

59-
- name: Run Trivy vulnerability scanner in repo mode
59+
- name: Setup Go
60+
uses: actions/setup-go@v5
61+
with:
62+
go-version-file: "go.mod"
63+
64+
- name: Build binary for linux/amd64
65+
run: |
66+
TAG=$(git describe --always)
67+
mkdir -p bin
68+
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
69+
-ldflags "-X github.com/coder/code-marketplace/buildinfo.tag=${TAG}" \
70+
-o bin/code-marketplace-linux-amd64 \
71+
./cmd/marketplace/main.go
72+
73+
- name: Set up Docker Buildx
74+
uses: docker/setup-buildx-action@v3
75+
76+
- name: Build Docker image
77+
id: build
78+
run: |
79+
docker buildx build \
80+
--platform linux/amd64 \
81+
--tag code-marketplace:scan \
82+
--load \
83+
--build-arg TARGETARCH=amd64 \
84+
.
85+
echo "image=code-marketplace:scan" >> "$GITHUB_OUTPUT"
86+
87+
- name: Run Trivy vulnerability scanner
6088
uses: aquasecurity/[email protected]
6189
with:
62-
scan-type: "fs"
63-
scan-ref: "."
90+
image-ref: ${{ steps.build.outputs.image }}
6491
format: "sarif"
6592
output: "trivy-results.sarif"
6693
severity: "LOW,MEDIUM,HIGH,CRITICAL"
67-
scanners: "vuln,secret,misconfig"
6894

6995
- name: Upload Trivy scan results to GitHub Security tab
7096
uses: github/codeql-action/upload-sarif@v3
7197
with:
7298
sarif_file: "trivy-results.sarif"
73-
category: "Trivy-Filesystem"
99+
category: "Trivy"

0 commit comments

Comments
 (0)