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
This commit is contained in:
Yehuda Chikvashvili
2020-02-27 14:37:25 +02:00
committed by GitHub
parent ac5dd40b74
commit 11efbb7514
5 changed files with 48 additions and 20 deletions

4
.dockerignore Normal file
View File

@@ -0,0 +1,4 @@
*.png
tests/
docs/
.github/

1
.gitignore vendored
View File

@@ -1,6 +1,5 @@
*.pyc
.venv
.dockerignore
*aqua*
venv/
.vscode

View File

@@ -1,25 +1,19 @@
FROM python:3.7-alpine3.10 as builder
FROM python:3.8-alpine as builder
RUN apk add --no-cache \
linux-headers \
tcpdump \
build-base \
ebtables
ebtables \
make \
git && \
apk upgrade --no-cache
WORKDIR /kube-hunter
COPY ./requirements.txt /kube-hunter/.
RUN pip install -r /kube-hunter/requirements.txt -t /kube-hunter
COPY setup.py setup.cfg Makefile ./
RUN make deps
COPY . /kube-hunter
COPY . .
RUN make install
FROM python:3.7-alpine3.10
RUN apk add --no-cache \
tcpdump
RUN apk upgrade --no-cache
COPY --from=builder /kube-hunter /kube-hunter
WORKDIR /kube-hunter
ENTRYPOINT ["python", "kube-hunter.py"]
ENTRYPOINT ["kube-hunter"]

View File

@@ -1,4 +1,4 @@
.SILENT:
.SILENT: clean
NAME := kube-hunter
SRC := kube_hunter
@@ -10,6 +10,13 @@ STATIC_COMPILED := $(COMPILED).static
.PHONY: deps
deps:
requires=$(shell mktemp)
python setup.py -q dependencies > \$requires
pip install -r \$requires
rm \$requires
.PHONY: dev-deps
dev-deps:
pip install -r requirements-dev.txt
.PHONY: lint

View File

@@ -4,6 +4,25 @@ 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."""
@@ -36,6 +55,11 @@ class PyInstallerCommand(Command):
setup(
use_scm_version=True,
cmdclass={"pyinstaller": PyInstallerCommand},
use_scm_version={
"fallback_version": "noversion"
},
cmdclass={
"dependencies": ListDependenciesCommand,
"pyinstaller": PyInstallerCommand,
},
)