@@ -141,35 +141,4 @@ COPY --from=builder /lib/pkcs11/p11-kit-trust.so /lib/pkcs11/
141141RUN ln -s /lib/pkcs11/p11-kit-trust.so /lib/libnssckbi.so
142142RUN ln -s /lib/libnssckbi.so /lib/p11-kit-trust.so
143143
144- # Do vulnerability scan in a seperate stage to avoid adding layer
145- FROM distroless_image AS vulnscan
146- COPY .trivyignore .trivyignore
147- RUN ["/bin/bash", "-c", "curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sh -s -- -b /usr/local/bin v0.39.0"]
148-
149- # Set up primary and secondary repository URLs
150- ENV PRIMARY_TRIVY_DB_REPOSITORY="ghcr.io/aquasecurity/trivy-db"
151- ENV SECONDARY_TRIVY_DB_REPOSITORY="public.ecr.aws/aquasecurity/trivy-db"
152-
153- # Download Trivy main database with a fallback mechanism
154- RUN export TRIVY_DB_REPOSITORY=$PRIMARY_TRIVY_DB_REPOSITORY && \
155- trivy image --download-db-only || \
156- (echo "Primary TRIVY_DB_REPOSITORY failed, trying secondary." && \
157- export TRIVY_DB_REPOSITORY=$SECONDARY_TRIVY_DB_REPOSITORY && \
158- trivy image --download-db-only) || \
159- (echo "Both TRIVY_DB_REPOSITORY sources failed." && exit 1)
160-
161- # Perform Trivy rootfs scan (only OS vulnerabilities, no Java scanning)
162- RUN ["/bin/bash", "-c", "trivy rootfs --ignore-unfixed --no-progress --severity HIGH,CRITICAL,MEDIUM --vuln-type os --scanners vuln --skip-files \"/usr/local/bin/trivy\" /"]
163- RUN ["/bin/bash", "-c", "trivy rootfs --ignore-unfixed --no-progress --severity HIGH,CRITICAL,MEDIUM --vuln-type os --scanners vuln /usr/lib"]
164- RUN ["/bin/bash", "-c", "trivy rootfs --exit-code 1 --ignore-unfixed --no-progress --severity HIGH,CRITICAL,MEDIUM --vuln-type os --scanners vuln --skip-files \"/usr/local/bin/trivy\" / > /dev/null 2>&1 && trivy rootfs --exit-code 1 --ignore-unfixed --no-progress --severity HIGH,CRITICAL,MEDIUM --vuln-type os --scanners vuln /usr/lib > /dev/null 2>&1"]
165-
166- # Revert to base layer before vulnscan
167- FROM distroless_image AS ContainerInsights
168- # force the trivy stage to run
169- # docker buildx (BUILDKIT) does not build stages which do not affect the final stage
170- # by copying over a file we create a dependency
171- # see: https://github.com/docker/build-push-action/issues/377
172- COPY --from=vulnscan /usr/local/bin/trivy /usr/local/bin/trivy
173- RUN ["/bin/bash", "-c", "rm -rf /usr/local/bin/trivy"]
174-
175144CMD [ "/opt/main.sh" ]
0 commit comments