#!/bin/bash #################################################################### # This script demonstrates how you can use detect / docker inspector # such that the image inspector services get started once, and # re-used by each subsequent run of Detect / Docker inspector. # This results in much faster performance since Detect / Docker # Inspector doesn't start/stop the services every time. #################################################################### #################################################################### # ==> Adjust the value of localSharedDirPath # This path cannot have any symbolic links in it #################################################################### localSharedDirPath=~/blackduck/shared imageInspectorVersion=5.0.1 #################################################################### # This script will start the imageinspector alpine service (if # it's not already running). # # This script will leave the alpine imageinspector service running # (and will re-use it on subsequent runs) # For troubleshooting, you might need to do a "docker logs" on # the imageinspector service container. # # All three "docker run" commands (starting the services) will have # all 3 port numbers in them, so every service knows how to find # every other service. # This allows a service to redirect requests to the other services when necessary. #################################################################### mkdir -p ${localSharedDirPath}/target # Make sure the alpine service is running alpineServiceIsUp=false successMsgCount=$(curl http://localhost:9000/health | grep "\"status\":\"UP\"" | wc -l) if [ "$successMsgCount" -eq "1" ]; then echo "The alpine image inspector service is up" alpineServiceIsUp=true else # Start the image inspector service for alpine on port 9000 docker run -d --user 1001 -p 9000:8081 --label "app=blackduck-imageinspector" --label="os=ALPINE" -v ${localSharedDirPath}:/opt/blackduck/blackduck-imageinspector/shared --name blackduck-imageinspector-alpine blackducksoftware/blackduck-imageinspector-alpine:${imageInspectorVersion} java -jar /opt/blackduck/blackduck-imageinspector/blackduck-imageinspector.jar --server.port=8081 --current.linux.distro=alpine --inspector.url.alpine=http://localhost:9000 --inspector.url.centos=http://localhost:9001 --inspector.url.ubuntu=http://localhost:9002 fi while [ "$alpineServiceIsUp" == "false" ]; do successMsgCount=$(curl http://localhost:9000/health | grep "\"status\":\"UP\"" | wc -l) if [ "$successMsgCount" -eq "1" ]; then echo "The alpine service is up" alpineServiceIsUp=true break fi echo "The alpine service is not up yet" sleep 15 done # Make sure the centos service is running centosServiceIsUp=false successMsgCount=$(curl http://localhost:9001/health | grep "\"status\":\"UP\"" | wc -l) if [ "$successMsgCount" -eq "1" ]; then echo "The centos image inspector service is up" centosServiceIsUp=true else # Start the image inspector service for centos on port 9001 docker run -d --user 1001 -p 9001:8081 --label "app=blackduck-imageinspector" --label="os=CENTOS" -v ${localSharedDirPath}:/opt/blackduck/blackduck-imageinspector/shared --name blackduck-imageinspector-centos blackducksoftware/blackduck-imageinspector-centos:${imageInspectorVersion} java -jar /opt/blackduck/blackduck-imageinspector/blackduck-imageinspector.jar --server.port=8081 --current.linux.distro=centos --inspector.url.alpine=http://localhost:9000 --inspector.url.centos=http://localhost:9001 --inspector.url.ubuntu=http://localhost:9002 fi while [ "$centosServiceIsUp" == "false" ]; do successMsgCount=$(curl http://localhost:9001/health | grep "\"status\":\"UP\"" | wc -l) if [ "$successMsgCount" -eq "1" ]; then echo "The centos service is up" centosServiceIsUp=true break fi echo "The centos service is not up yet" sleep 15 done # Make sure the ubuntu service is running ubuntuServiceIsUp=false successMsgCount=$(curl http://localhost:9002/health | grep "\"status\":\"UP\"" | wc -l) if [ "$successMsgCount" -eq "1" ]; then echo "The ubuntu image inspector service is up" ubuntuServiceIsUp=true else # Start the image inspector service for ubuntu on port 9002 docker run -d --user 1001 -p 9002:8081 --label "app=blackduck-imageinspector" --label="os=UBUNTU" -v ${localSharedDirPath}:/opt/blackduck/blackduck-imageinspector/shared --name blackduck-imageinspector-ubuntu blackducksoftware/blackduck-imageinspector-ubuntu:${imageInspectorVersion} java -jar /opt/blackduck/blackduck-imageinspector/blackduck-imageinspector.jar --server.port=8081 --current.linux.distro=ubuntu --inspector.url.alpine=http://localhost:9000 --inspector.url.centos=http://localhost:9001 --inspector.url.ubuntu=http://localhost:9002 fi while [ "$ubuntuServiceIsUp" == "false" ]; do successMsgCount=$(curl http://localhost:9002/health | grep "\"status\":\"UP\"" | wc -l) if [ "$successMsgCount" -eq "1" ]; then echo "The ubuntu service is up" ubuntuServiceIsUp=true break fi echo "The ubuntu service is not up yet" sleep 15 done cd run curl -O https://detect.synopsys.com/detect.sh chmod +x detect.sh ./detect.sh --blackduck.offline.mode=true --detect.tools.excluded=SIGNATURE_SCAN,POLARIS --detect.docker.image=alpine:latest --detect.docker.path.required=false --detect.docker.passthrough.imageinspector.service.url=http://localhost:9002 --detect.docker.passthrough.imageinspector.service.start=false --logging.level.com.synopsys.integration=INFO --detect.docker.passthrough.shared.dir.path.local=${localSharedDirPath}