Skip to content

Commit 7f93229

Browse files
committed
Simplify / fix tests, CI
1 parent 0e5d53b commit 7f93229

File tree

10 files changed

+33
-82
lines changed

10 files changed

+33
-82
lines changed

.circleci/config.yml

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,31 @@ workflows:
88
jobs:
99
build-and-test:
1010
machine:
11-
image: ubuntu-2004:202104-01
11+
image: ubuntu-2004:current
1212
steps:
1313
- checkout
14+
- run:
15+
name: install deps
16+
command: |
17+
sudo apt-get update
18+
sudo apt-get -y install cryptsetup-bin squashfs-tools
19+
- run:
20+
name: install singularity
21+
command: |
22+
wget https://github.com/sylabs/singularity/releases/download/v3.9.7/singularity-ce_3.9.7-focal_amd64.deb
23+
sudo apt -y install ./singularity-ce_3.9.7-focal_amd64.deb
24+
rm singularity-ce_3.9.7-focal_amd64.deb
1425
- run:
1526
name: install
16-
command: python3 setup.py install
27+
command: python3 setup.py install --user
28+
- run:
29+
name: start clair
30+
command: |
31+
docker pull arminc/clair-db:2021-06-14
32+
docker run -d --name clair-db arminc/clair-db:2021-06-14
33+
sleep 5
34+
docker pull arminc/clair-local-scan:v2.1.7_5125fde67edee46cb058a3feee7164af9645e07d
35+
docker run -p 6060:6060 --link clair-db:postgres -d --name clair arminc/clair-local-scan:v2.1.7_5125fde67edee46cb058a3feee7164af9645e07d
1736
- run:
1837
name: test
19-
command: build_scripts/docker_local_tests.sh
20-
38+
command: python3 setup.py test

Dockerfile

Lines changed: 0 additions & 17 deletions
This file was deleted.

README.md

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
[![CircleCI](https://circleci.com/gh/dtrudg/clair-singularity/tree/master.svg?style=svg)](https://circleci.com/gh/dtrudg/clair-singularity/tree/master)
44

5-
__Scan [SingularityCE](http://sylabs.io/singularity/) container images for security vulnerabilities
5+
__Scan [Singularity](http://sylabs.io/singularity/) container images for security vulnerabilities
66
using [CoreOS Clair](https://github.com/coreos/clair).__
77

8+
![screenshot](screenshot.png)
9+
810
The [CoreOS Clair vulnerability scanner](https://github.com/coreos/clair) is a useful tool able to scan docker and other container
911
formats for security vulnerabilities. It obtains up-to-date lists of vulnerabilities for various
1012
platforms (namespaces) from public databases.
@@ -25,7 +27,7 @@ Based on experiments detailed [in this Gist](https://gist.github.com/dctrud/4797
2527

2628
__IMPORTANT NOTES__
2729

28-
CI tests usage with SingularityCE 3.9.7
30+
Funtionality was last tested using SingularityCE 3.9.7.
2931

3032
This tool should be considered proof of concept, not heavily tested. Use at your own risk.
3133

@@ -39,7 +41,7 @@ Clair instance, or that only a trusted Clair instance can retrieve images from t
3941
To use clair-singularity you will need a _Linux_ host with:
4042

4143
* Python 3.5 or greater installed
42-
* Singularity 3+ installed (tested with 3.8.0) and the singularity executable in your `PATH`
44+
* SingularityCE 3+ installed (tested with 3.9.7) and the singularity executable in your `PATH`
4345
* A Clair instance running somewhere, that is able to access the machine you will run
4446
clair-singularity on. It's easiest to accomplish this using docker to run a local Clair instance as below.
4547

@@ -77,15 +79,10 @@ python setup.py install
7779

7880
__Clair on same machine__
7981

80-
81-
If you are running `clair-singularity` locally (outside of docker), and clair
82-
within docker, you need to tell `clair-singularity` to serve images on the main
83-
IP of your host, so that dockerized clair can access them.
84-
8582
To scan a singularity image, using a clair instance running under local docker, on
8683
port 6060:
8784

88-
clair-singularity myimage.img
85+
clair-singularity myimage.sif
8986

9087
/If your hostname is not resolvable to a non-localhost IP of your machine, accessible to
9188
docker containers, you must specify the IP with `--bind-ip`/
@@ -105,20 +102,3 @@ By default, clair-singularity gives a simplified text report on STDOUT. To obtai
105102
report returned by Clair use the `--jsoon-output` option.
106103

107104
clair-singularity --json-output myimage.img
108-
109-
## Development / Testing
110-
111-
Tests can are run in 3 different ways:
112-
113-
__Local - no access to Clair__
114-
115-
Runs all tests that don't depend on access to a Clair server, using the local Python.
116-
117-
$ build_scripts/noclair_local_tests.sh
118-
119-
__Local - dockerized with Clair__
120-
121-
Starts a Clair service with local docker, builds clair-singularity into a docker container, with Python 3.5, and
122-
runs tests in this docker container.
123-
124-
$ build_scripts/docker_local_tests.sh

build_scripts/docker_local_tests.sh

Lines changed: 0 additions & 24 deletions
This file was deleted.

build_scripts/noclair_local_tests.sh

Lines changed: 0 additions & 6 deletions
This file was deleted.

clair_singularity/clair.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def format_report_text(report):
9797
vuln['Link'] + "\n" + vuln['Description']
9898
])
9999

100-
print("Image contains %d features/packages total.\n", len(features))
100+
print("Image contains %d features/packages total.\n" % len(features))
101101
print("Found %d vulnerabilities in %d features/packages:\n" % (len(vulns)-1, vulnFeatures))
102102

103103
if vulnFeatures > 0:

screenshot.png

97.4 KB
Loading

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
setup(
99
name='clair_singularity',
10-
version='0.3.0',
10+
version='0.4.0',
1111
url='https://github.com/dctrud/clair-singularity',
1212
author='David Trudgian',
1313
author_email='[email protected]',

tests/test_clair.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from clair_singularity.clair import check_clair, post_layer, get_report
44

5-
API_URL = 'http://clair:6060/v1/'
5+
API_URL = 'http://localhost:6060/v1/'
66

77
@pytest.mark.needs_clair
88
def test_check_clair():

tests/test_cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def test_help(runner):
2424
def test_full_json(runner, testimage):
2525
result = runner.invoke(cli,
2626
['--json-output', '--bind-ip', MY_IP, '--bind-port', '8081', '--clair-uri',
27-
'http://clair:6060', testimage])
27+
'http://localhost:6060', testimage])
2828
output = json.loads(result.output)
2929

3030
# There are 62 features in the container scan, and 18 have vulnerabilities
@@ -41,7 +41,7 @@ def test_full_json(runner, testimage):
4141
@pytest.mark.needs_clair
4242
def test_full_text(runner, testimage):
4343
result = runner.invoke(cli, ['--bind-ip', MY_IP, '--bind-port', '8082', '--clair-uri',
44-
'http://clair:6060', testimage])
44+
'http://localhost:6060', testimage])
4545
# Check we do have some CVEs we expect reported here
4646
assert 'coreutils' in result.output
4747
assert 'CVE' in result.output

0 commit comments

Comments
 (0)