1+ stages :
2+ - build-and-test
3+
4+ build-and-test :
5+ stage : build-and-test
6+ image : docker:latest
7+ services :
8+ - docker:dind
9+ variables :
10+ DOCKER_HOST : tcp://docker:2375
11+ script :
12+ - apk add --no-cache curl jq python3 py3-pip
13+ - python3 -m venv venv
14+ - source ./venv/bin/activate
15+ # Install Probely CLI
16+ - pip install probely
17+ - probely targets get --api-key ${PROBELY_API_KEY}
18+
19+ - docker network create custom-network
20+
21+ - docker build -t test-app .
22+ - docker run --name test-app --hostname custom-web-app --network custom-network -p 0.0.0.0:8080:8080 -d test-app
23+
24+ - cat /etc/hosts # current /etc/hosts
25+
26+ - CONTAINER_IP=$(grep -i 'docker' /etc/hosts | head -1 | awk '{print $1}')
27+ - echo "Container IP from /etc/hosts is $CONTAINER_IP"
28+ - echo "${CONTAINER_IP} ${TARGET_HOSTNAME} ${TARGET_HOSTNAME}." | tee -a /etc/hosts # Add to /etc/hosts
29+ - cat /etc/hosts # Confirm host was added
30+
31+ - |
32+ for i in {1..10}; do # Wait for the app to start
33+ if curl -s ${TARGET_URL} > /dev/null; then
34+ echo "App is up!";
35+ break;
36+ fi
37+ echo "Waiting for the app to be ready...";
38+ sleep 2;
39+ done
40+
41+ # Test the application
42+ - RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" ${TARGET_URL})
43+ - |
44+ if [[ "$RESPONSE" -ne 200 ]]; then
45+ echo "App test failed with HTTP status ${RESPONSE}";
46+ exit 1;
47+ fi
48+ - curl -s -i ${TARGET_URL}
49+ - echo "App test passed with HTTP status ${RESPONSE}";
50+
51+ # Run userspace agent
52+ - chmod +x scanning-agent/farcasterd-linux-amd64-0.4.3
53+ - ./scanning-agent/farcasterd-linux-amd64-0.4.3 --token ${AGENT_TOKEN} &
54+
55+ # Wait for the agent to start
56+ - sleep 40
57+
58+ # Start Scan
59+ - |
60+ for i in {1..20}; do # Start Probely scan
61+ echo "-----------------------------------"
62+ SCAN_ID=$(probely targets start-scan ${TARGET_ID} -o IDS_ONLY --api-key ${PROBELY_API_KEY})
63+ echo ${SCAN_ID}
64+ if [[ -z "${SCAN_ID}" ]]; then
65+ echo "Scan didn't start... Retry start-scan"
66+ else
67+ echo "Scan started with SCAN ID ${SCAN_ID}";
68+ break;
69+ fi
70+ sleep 5
71+ done
72+ - |
73+ if [[ -z "${SCAN_ID}" ]]; then
74+ echo "No Scan ID, aborting..."
75+ exit 1
76+ fi
77+
78+ # Wait for scan to end
79+ - |
80+ while true; do
81+ echo "-----------------------------------"
82+ SCAN_OUTPUT=$(probely scans get ${SCAN_ID} --api-key ${PROBELY_API_KEY} | tail -1)
83+ echo ${SCAN_OUTPUT}
84+ echo "-----------------------------------"
85+ SCAN_STATUS=$(probely scans get ${SCAN_ID} --api-key ${PROBELY_API_KEY} -o JSON | jq -r '.[0].status')
86+ if [[ "$SCAN_STATUS" == "started" ]] || [[ "$SCAN_STATUS" == "queued" ]]; then
87+ echo "Scan is running or queued!";
88+ else
89+ echo "Scan is not running... finishing"
90+ break;
91+ fi
92+ sleep 30;
93+ done
94+
95+ # Check for high vulnerabilities
96+ - HIGH_VULNS=$(probely scans get ${SCAN_ID} --api-key ${PROBELY_API_KEY} -o JSON | jq -r '.[0].highs')
97+ - echo "HIGH vulnerabilities ${HIGH_VULNS}"
98+ - |
99+ if [[ "$HIGH_VULNS" -gt 0 ]]; then
100+ echo "Scan has High vulnerabilities... aborting"
101+ exit 1
102+ else
103+ echo "Scan doesn't have high vulnerabilities"
104+ fi
105+
106+ # Clean up
107+ - docker stop test-app
108+ - docker rm test-app
109+ - docker network rm custom-network
0 commit comments