mirror of
https://github.com/aquasecurity/kube-hunter.git
synced 2026-02-14 18:09:56 +00:00
* Fix Dockerfile build The Docker build used a 2-step installation of requirements and application. This was broken by #272. Fixes #300 * Add dependencies cache for docker build Caching installation requirements saves time when building
66 lines
1.6 KiB
Python
66 lines
1.6 KiB
Python
from subprocess import check_call
|
|
from pkg_resources import parse_requirements
|
|
from configparser import ConfigParser
|
|
from setuptools import setup, Command
|
|
|
|
|
|
class ListDependenciesCommand(Command):
|
|
"""A custom command to list dependencies"""
|
|
|
|
description = "list package dependencies"
|
|
user_options = []
|
|
|
|
def initialize_options(self):
|
|
pass
|
|
|
|
def finalize_options(self):
|
|
pass
|
|
|
|
def run(self):
|
|
cfg = ConfigParser()
|
|
cfg.read("setup.cfg")
|
|
requirements = cfg["options"]["install_requires"]
|
|
print(requirements)
|
|
|
|
|
|
class PyInstallerCommand(Command):
|
|
"""A custom command to run PyInstaller to build standalone executable."""
|
|
|
|
description = "run PyInstaller on kube-hunter entrypoint"
|
|
user_options = []
|
|
|
|
def initialize_options(self):
|
|
pass
|
|
|
|
def finalize_options(self):
|
|
pass
|
|
|
|
def run(self):
|
|
cfg = ConfigParser()
|
|
cfg.read("setup.cfg")
|
|
command = [
|
|
"pyinstaller",
|
|
"--clean",
|
|
"--onefile",
|
|
"--name",
|
|
"kube-hunter",
|
|
]
|
|
setup_cfg = cfg["options"]["install_requires"]
|
|
requirements = parse_requirements(setup_cfg)
|
|
for r in requirements:
|
|
command.extend(["--hidden-import", r.key])
|
|
command.append("kube_hunter/__main__.py")
|
|
print(' '.join(command))
|
|
check_call(command)
|
|
|
|
|
|
setup(
|
|
use_scm_version={
|
|
"fallback_version": "noversion"
|
|
},
|
|
cmdclass={
|
|
"dependencies": ListDependenciesCommand,
|
|
"pyinstaller": PyInstallerCommand,
|
|
},
|
|
)
|