Skip to content

Commit

Permalink
Fix Dockerfile build (#303)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
iyehuda authored Feb 27, 2020
1 parent ac5dd40 commit 11efbb7
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 20 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.png
tests/
docs/
.github/
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
*.pyc
.venv
.dockerignore
*aqua*
venv/
.vscode
Expand Down
26 changes: 10 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.SILENT:
.SILENT: clean

NAME := kube-hunter
SRC := kube_hunter
Expand All @@ -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
Expand Down
28 changes: 26 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,25 @@
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."""

Expand Down Expand Up @@ -36,6 +55,11 @@ def run(self):


setup(
use_scm_version=True,
cmdclass={"pyinstaller": PyInstallerCommand},
use_scm_version={
"fallback_version": "noversion"
},
cmdclass={
"dependencies": ListDependenciesCommand,
"pyinstaller": PyInstallerCommand,
},
)

0 comments on commit 11efbb7

Please sign in to comment.