-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
deploy package with custom function and the softwares.josn are read f…
…rom the function
- Loading branch information
Showing
34 changed files
with
515 additions
and
406 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,77 @@ | ||
import json | ||
import docker | ||
import re | ||
import os | ||
|
||
client_docker= docker.DockerClient(base_url="unix://var/run/docker.sock") | ||
|
||
def on_message(repo_name, context): | ||
|
||
logger = context['logger'] | ||
docker_hub = context['hub'] | ||
client_images = context['images'] | ||
|
||
def handler_analysis(image_name, context): | ||
print ("Hello world "+ image_name) | ||
print (context.get_images()) | ||
logger.info("Received name " + repo_name) | ||
|
||
my_image = dict() | ||
|
||
tag = "latest" | ||
try: | ||
# download the Docker image | ||
list_tags = docker_hub.get_all_tags(repo_name) | ||
tag = "" | ||
if "latest" in list_tags: | ||
tag = "latest" | ||
elif len(list_tags)>0: | ||
tag = list_tags[0] # take the first tag | ||
|
||
|
||
|
||
logger.info("Pulling image {0}:{1} ...".format(repo_name, tag)) | ||
image = client_docker.images.pull(name=repo_name, tag=tag) | ||
tag = image.tags[0] | ||
logger.info("{} is pulled locally.".format(tag)) | ||
|
||
my_image['name'] = tag | ||
|
||
# create a infinite running container | ||
container = client_docker.containers.create(tag, entrypoint="sleep 1000000000") | ||
# start the container | ||
container.start() | ||
|
||
|
||
# list of software distributions found in the image. | ||
softwares = [] | ||
with open(os.path.join(os.path.dirname(__file__),'softwares.json')) as json_data: | ||
#with open('pyfinder/deploy/softwares.json') as json_data: | ||
software= json.load(json_data) | ||
for sw in software:# [{'opt':'python --version','regex':'[0-9]+[.][0-9]*[.0-9]*'}]: | ||
command = sw['name']+" " + sw['cmd'] | ||
# create an exec instance | ||
res = container.exec_run(cmd=command) | ||
output = res.decode() | ||
prog = re.compile(sw['regex']) | ||
match = prog.search(output) | ||
if match: | ||
version = match.group(0) | ||
softwares.append({'software': sw['name'], 'ver': version}) | ||
logger.debug("{0} {1} found.".format(sw['name'], version)) | ||
else: | ||
logger.debug("[{0}] NOT found in ".format(sw['name'])) | ||
|
||
#logger.info("{0} {1} found.".format(sw['name'], version)) | ||
logger.info('['+''.join('{} {},'.format(s['software'],s['ver']) for s in softwares)+"]") | ||
|
||
my_image['softwares'] = softwares | ||
|
||
client_images.post_image(my_image) | ||
|
||
container.stop(timeout=2) # after 2 second it stops the container with SIGKILL | ||
container.remove() | ||
client_docker.images.remove(image=tag, force=True) | ||
logger.info("Removed image {0}".format(tag)) | ||
|
||
except docker.errors.APIError as e: | ||
logger.error(str(e)) | ||
except docker.errors.ImageNotFound as e: | ||
logger.error(str(e)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
[{ | ||
"name": "python", | ||
"cmd": "--version", | ||
"regex": "[0-9]+[.][0-9]*[.0-9]*" | ||
}, { | ||
"name": "java", | ||
"cmd": "-version", | ||
"regex": "[0-9]+[.][0-9]*[.0-9]*" | ||
}, { | ||
"name": "perl", | ||
"cmd": "-version", | ||
"regex": "[0-9]+[.][0-9]*[.0-9]*" | ||
}, { | ||
"name": "curl", | ||
"cmd": "--version", | ||
"regex": "[0-9]+[.][0-9]*[.0-9]*" | ||
}, { | ||
"name": "nano", | ||
"cmd": "--version", | ||
"regex": "[0-9]+[.][0-9]*[.0-9]*" | ||
}, { | ||
"name": "php", | ||
"cmd": "-v", | ||
"regex": "[0-9]+[.][0-9]*[.0-9]*" | ||
},{ | ||
"name": "ruby", | ||
"cmd": "--version", | ||
"regex": "[0-9]+[.][0-9]*[.0-9]*" | ||
}, { | ||
"name": "scala", | ||
"cmd": "-version", | ||
"regex": "[0-9]+[.][0-9]*[.0-9]*" | ||
}, { | ||
"name": "groovy", | ||
"cmd": "-version", | ||
"regex": "[0-9]+[.][0-9]*[.0-9]*" | ||
},{ | ||
"name": "httpd", | ||
"cmd": "-V", | ||
"regex": "[0-9]+[.][0-9]*[.0-9]*" | ||
}, { | ||
"name": "nginx", | ||
"cmd": "-v", | ||
"regex": "[0-9]+[.][0-9]*[.0-9]*" | ||
}, { | ||
"name": "pip", | ||
"cmd": "--version", | ||
"regex": "[0-9]+[.][0-9]*[.0-9]*" | ||
}, { | ||
"name": "node", | ||
"cmd": "-v", | ||
"regex": "[0-9]+[.][0-9]*[.0-9]*" | ||
}, { | ||
"name": "npm", | ||
"cmd": "-v", | ||
"regex": "[0-9]+[.][0-9]*[.0-9]*" | ||
}, { | ||
"name": "gunicorn", | ||
"cmd": "--version", | ||
"regex": "[0-9]+[.][0-9]*[.0-9]*" | ||
}, | ||
{ | ||
"name": "wget", | ||
"cmd": "--version", | ||
"regex": "[0-9]+[.][0-9]*[.0-9]*" | ||
} | ||
] |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,7 @@ | ||
from .scanner import Scanner | ||
from .checker import Checker | ||
from .crawler import Crawler | ||
from .model.image import Image | ||
from .client_images_service import ClientImages | ||
from .client_dockerhub import ClientHub | ||
from .client_software import ClientSoftware | ||
from .tester import Tester | ||
from .client_software import ClientSoftware | ||
|
||
__all__ = [Scanner, Crawler, ClientImages, ClientHub, Tester, Checker, Image] | ||
# from .scanner import Scanner | ||
# from .checker import Checker | ||
# from .crawler import Crawler | ||
# from .model.image import Image | ||
# from .tester import Tester | ||
# | ||
# __all__ = [Scanner, Crawler, Checker] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from .client_images_service import ClientImages | ||
from .client_dockerhub import ClientHub | ||
from .client_software import ClientSoftware | ||
from .consumer_rabbit import ConsumerRabbit | ||
from .publisher_rabbit import PublisherRabbit | ||
|
||
|
||
__all__ = [ClientImages, ClientHub, ConsumerRabbit, PublisherRabbit, ClientSoftware] |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
1 change: 0 additions & 1 deletion
1
...sis/pyFinder/pyfinder/publisher_rabbit.py → ...yFinder/pyfinder/core/publisher_rabbit.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import pika | ||
from pyfinder import utils | ||
import logging | ||
|
||
|
||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# The folder will contains the deploy package of the scanner | ||
# -- analysis.py | ||
# --requirements.txt | ||
# (any othe file needed) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from .image import Image | ||
|
||
|
||
__all__ = [Image] |
Oops, something went wrong.