Check if Dockerfile exists (create one if missing), build the Docker image locally, then run Trivy to scan for CVEs. Use when user says "scan cve", "trivy scan", "check vulnerabilities", "test cve on trivy", or "security scan".
You are performing a local Docker build + Trivy CVE scan. Follow these steps in order.
Use the Glob tool to check if a Dockerfile exists in the project root.
FROM node:20-alpine AS base
FROM base AS deps
ENV NODE_ENV=production
WORKDIR /app
COPY package.json ./
RUN npm install --include=dev
FROM base AS production-deps
WORKDIR /app
COPY --from=deps /app/node_modules /app/node_modules
COPY package.json ./
RUN npm prune --omit=dev
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules /app/node_modules
COPY . .
RUN npm run build
FROM base
RUN apk upgrade --no-cache
WORKDIR /app
ENV NODE_ENV=production
COPY --from=production-deps /app/node_modules ./node_modules
COPY --from=deps /app/package.json ./package.json
COPY --from=builder /app/build ./build
EXPOSE 3000
CMD ["node", "build/server/index.js"]
Adapt the template to match the project's actual build output and start command.
Generate a lowercase image name from the project directory name or package.json name field:
/ with -cop-wfcap-web → image tag cop-wfcap-web:scanRun the build with the Bash tool:
docker build -t <image-name>:scan .
which trivy || brew install trivy
If brew is unavailable on Linux:
curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sh -s -- -b /usr/local/bin
trivy image --severity HIGH,CRITICAL <image-name>:scan
Capture the full output. Also run with --format json and save to a temp file for structured analysis:
trivy image --severity HIGH,CRITICAL --format json -o /tmp/trivy-report.json <image-name>:scan
Parse and present a clear summary table:
| Severity | Package | Installed Version | Fixed Version | CVE ID |
|---|---|---|---|---|
| CRITICAL | ... | ... | ... | ... |
| HIGH | ... | ... | ... | ... |
Then provide:
node:20-alpine → node:22-alpine)Ask the user if they want to remove the scan image:
docker rmi <image-name>:scan
HIGH,CRITICAL severity. Offer --severity LOW,MEDIUM,HIGH,CRITICAL if the user wants a full report.trivy image manually and paste the output back.