Files
kube-hunter/setup.py
Yehuda Chikvashvili 11efbb7514 Fix Dockerfile build (#303)
* 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
2020-02-27 14:37:25 +02:00

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,
},
)