1010jobs :
1111 build-and-test :
1212 runs-on : ubuntu-latest
13-
13+
1414 steps :
1515 - uses : actions/checkout@v4
16-
16+
1717 - name : Set up Python
1818 uses : actions/setup-python@v4
1919 with :
2020 python-version : ' 3.12'
21-
21+
22+ - name : Install dependencies
23+ run : |
24+ python -m pip install --upgrade pip
25+ pip install -r requirements.txt
26+
27+ - name : Build and install package
28+ run : |
29+ pip install build
30+ python -m build
31+ pip install -e .
32+
2233 - name : Setup Hadolint
2334 run : |
2435 curl -sL -o hadolint https://github.com/hadolint/hadolint/releases/latest/download/hadolint-Linux-x86_64
2536 chmod +x hadolint
2637 sudo mv hadolint /usr/local/bin/
27-
38+
2839 - name : Setup Trivy
2940 run : |
30- sudo apt-get update
41+ sudo apt-get update -qq
3142 sudo apt-get install -y wget apt-transport-https gnupg lsb-release
3243 wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | sudo gpg --dearmor -o /usr/share/keyrings/trivy.gpg
3344 echo "deb [signed-by=/usr/share/keyrings/trivy.gpg] https://aquasecurity.github.io/trivy-repo/deb $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/trivy.list
34- sudo apt-get update
45+ sudo apt-get update -qq
3546 sudo apt-get install -y trivy
36-
37- - name : Install dependencies
38- run : |
39- python -m pip install --upgrade pip
40- if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
41-
42- - name : Build package
43- run : |
44- pip install build
45- python -m build
46-
47- - name : Install package in development mode
47+
48+ - name : Run unit tests
4849 run : |
49- pip install -e .
50- # Ensure all dependencies are installed (including from setup.py)
51- pip install -r requirements.txt
52-
53- - name : Run Hadolint on Dockerfiles
50+ pip install pytest
51+ pytest tests/ -v
52+
53+ - name : Lint Dockerfiles with Hadolint
5454 run : |
5555 find . -name "Dockerfile*" -exec hadolint {} \;
56-
57- - name : Run Trivy for vulnerability scanning
56+
57+ - name : Scan Dockerfiles with Trivy
5858 run : |
5959 find . -name "Dockerfile*" -exec trivy config {} \;
60-
61- - name : Debug folder structure
62- run : |
63- echo "Current directory: $(pwd)"
64- ls -R
65-
66- - name : Run tests
67- env :
68- OPENAI_API_KEY : ${{ secrets.OPENAI_API_KEY }}
60+
61+ - name : Verify CLI installs correctly
6962 run : |
70- # Test 1: Version check
71- echo "=========================================="
72- echo "Test 1: Version check"
73- echo "=========================================="
7463 docksec --version
75-
76- # Test 2: Help command
77- echo ""
78- echo "=========================================="
79- echo "Test 2: Help command"
80- echo "=========================================="
81- docksec -h
82-
83- # Test 3: Create a test Dockerfile
84- echo ""
85- echo "=========================================="
86- echo "Test 3: Creating test Dockerfile"
87- echo "=========================================="
64+ docksec --help
65+
66+ - name : Run scan-only mode (no AI required)
67+ run : |
8868 mkdir -p test_dir
8969 cat > test_dir/Dockerfile << 'EOF'
9070 FROM alpine:latest
@@ -93,68 +73,18 @@ jobs:
9373 COPY . .
9474 CMD ["sh"]
9575 EOF
96- cat test_dir/Dockerfile
97-
98- # Test 4: Pull Docker image for testing
99- echo ""
100- echo "=========================================="
101- echo "Test 4: Pull test Docker image"
102- echo "=========================================="
10376 docker pull alpine:latest
104- echo "✅ Alpine image pulled successfully"
105-
106- # Test 5: Scan-only mode (no AI)
107- echo ""
108- echo "=========================================="
109- echo "Test 5: Scan-only mode (no AI)"
110- echo "=========================================="
111- docksec test_dir/Dockerfile --scan-only -i alpine:latest || echo "Scan completed"
112-
113- # Test 6: Image-only scan
114- echo ""
115- echo "=========================================="
116- echo "Test 6: Image-only scan"
117- echo "=========================================="
118- docksec --image-only -i alpine:latest || echo "Image scan completed"
119-
120- # Test 7: Verify results directory was created
121- echo ""
122- echo "=========================================="
123- echo "Test 7: Checking results"
124- echo "=========================================="
125- if [ -d "results" ]; then
126- echo "✅ Results directory created successfully"
127- echo "Contents:"
128- ls -lh results/ 2>/dev/null || echo "No files in results (may be expected)"
129- else
130- echo "⚠️ Results directory not found"
131- echo "This may be expected if scans failed due to missing API key"
132- fi
133-
134- # Cleanup
135- echo ""
136- echo "=========================================="
137- echo "Cleanup"
138- echo "=========================================="
77+ docksec test_dir/Dockerfile --scan-only -i alpine:latest
13978 rm -rf test_dir
140- echo "Test directory cleaned up"
141-
142- echo ""
143- echo "=========================================="
144- echo "✅ All DockSec CLI tests passed!"
145- echo "=========================================="
146- echo ""
147- echo "Summary:"
148- echo "- Version flag: ✅ Working"
149- echo "- Help command: ✅ Working"
150- echo "- CLI installation: ✅ Working"
151- echo "- Scan modes: ⚠️ Working (API key warnings expected)"
152- echo ""
153- echo "Note: Full AI features require OPENAI_API_KEY to be set in GitHub Secrets"
154-
155- - name : Upload coverage report
79+
80+ - name : Run image-only scan
81+ run : |
82+ docksec --image-only -i alpine:latest
83+
84+ - name : Upload scan results
15685 uses : actions/upload-artifact@v4
86+ if : always()
15787 with :
158- name : coverage-report
159- path : coverage.xml
160- if-no-files-found : ignore
88+ name : scan-results
89+ path : results/
90+ if-no-files-found : ignore
0 commit comments