Skip to content

Commit

Permalink
fix(CI): Enforce vulnerability scans on PRs (#1546)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmed-nour-fdc authored Apr 25, 2024
1 parent 7fdcab2 commit 6bed8c8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/execution-plan-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,10 @@ jobs:
with:
trigger: main
secrets: inherit

trivy-scan:
needs: [execution-plan]
uses: ./.github/workflows/trivy-scan.yml
with:
trigger: main
secrets: inherit
2 changes: 1 addition & 1 deletion .github/workflows/trivy-scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
- name: Run trivy scan
run: |
cd trivy
earthly +scan-all --kuberpult_version="$IMAGE_TAG_KUBERPULT"
earthly +scan-all --kuberpult_version="$IMAGE_TAG_KUBERPULT" --trigger=${{ inputs.trigger }}
- name: Archive reports
uses: actions/upload-artifact@v4
with:
Expand Down
25 changes: 19 additions & 6 deletions trivy/Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,31 @@ deps:
scan-all:
FROM +deps
ARG --required kuberpult_version

ARG trigger=""
ARG VERSION_REPORT_NAME="kuberpult-${kuberpult_version}-reports"
ARG REPORT_TAR_NAME="${VERSION_REPORT_NAME}.tar.gz"
RUN mkdir $VERSION_REPORT_NAME

FOR service IN $SERVICES
BUILD +scan-service --service=$service --version=$kuberpult_version
COPY (+scan-service/* --service=$service --version=$kuberpult_version) $VERSION_REPORT_NAME/
IF [ "$trigger" == "pull-request" ]
FOR service IN $SERVICES
BUILD +scan-service-pr --service=$service --version=$kuberpult_version
END
ELSE
FOR service IN $SERVICES
BUILD +scan-service --service=$service --version=$kuberpult_version
COPY (+scan-service/* --service=$service --version=$kuberpult_version) $VERSION_REPORT_NAME/
END
RUN tar -czf $REPORT_TAR_NAME $VERSION_REPORT_NAME/
SAVE ARTIFACT $REPORT_TAR_NAME AS LOCAL $REPORT_TAR_NAME
END

RUN tar -czf $REPORT_TAR_NAME $VERSION_REPORT_NAME/
SAVE ARTIFACT $REPORT_TAR_NAME AS LOCAL $REPORT_TAR_NAME
scan-service-pr:
FROM +deps
ARG --required service
ARG --required version
CACHE --sharing locked --id trivy-cache /tmp/trivy_cache

RUN trivy --cache-dir /tmp/trivy_cache --severity HIGH,CRITICAL --exit-code 1 image $IMAGE_REGISTRY/kuberpult-$service:$version

scan-service:
FROM +deps
Expand Down

0 comments on commit 6bed8c8

Please sign in to comment.