Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

creating standalone binary for kapitan #323

Merged
merged 11 commits into from Aug 22, 2019
2 changes: 2 additions & 0 deletions .travis.yml
Expand Up @@ -38,6 +38,8 @@ install:
script:
- make build_helm_binding
- make test && make test_coverage
- make build_binary
- make test_binary

after_success:
- if [ "$TRAVIS_PULL_REQUEST" = "false" ] && [ "$TRAVIS_BRANCH" = "master" ]; then bash ./scripts/inc_version.sh; fi
Expand Down
9 changes: 8 additions & 1 deletion Makefile
Expand Up @@ -44,7 +44,14 @@ codestyle:
flake8 --ignore E501 . --exclude=reclass
@echo

.PHONY: build_binary
build_binary:
scripts/build-binary.sh

.PHONY: test_binary
test_binary:
python3 -m unittest tests.test_binary

.PHONY: build_helm_binding
build_helm_binding:
bash kapitan/inputs/helm/build.sh

2 changes: 1 addition & 1 deletion kapitan/inputs/helm/__init__.py
Expand Up @@ -68,7 +68,7 @@ def render_chart(chart_dir, output_path, **kwargs):
try:
# lib is opened inside the function to allow multiprocessing
lib = ffi.dlopen(os.path.join(os.path.dirname(os.path.abspath(__file__)), "libtemplate.so"))
except NameError:
except (NameError, OSError):
raise HelmBindingUnavailableError("Helm binding is not available. Run 'make build_helm_binding' to create it")

if kwargs.get('helm_values_file', None):
Expand Down
40 changes: 40 additions & 0 deletions pyinstaller-Dockerfile
@@ -0,0 +1,40 @@
FROM debian:stretch
yoshi-1224 marked this conversation as resolved.
Show resolved Hide resolved
SHELL ["/bin/bash", "-i", "-c"]

ARG PYTHON_VERSION=3.7.2
ARG PYINSTALLER_VERSION=3.5

RUN mkdir /kapitan
WORKDIR /kapitan
COPY kapitan/ kapitan/
# COPY __main__.spec ./build.spec
COPY requirements.txt ./requirements.txt
COPY scripts/pyinstaller.sh ./pyinstaller.sh

RUN apt-get update \
&& apt-get install -y --no-install-recommends \
build-essential \
ca-certificates \
git \
libffi-dev \
libbz2-dev \
libreadline-dev \
libsqlite3-dev \
libssl-dev \
zlib1g-dev \
curl

RUN echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc \
&& echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc \
&& source ~/.bashrc \
&& curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash \
&& echo 'eval "$(pyenv init -)"' >> ~/.bashrc \
&& source ~/.bashrc \
&& PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install $PYTHON_VERSION \
&& pyenv global $PYTHON_VERSION \
&& pip install --upgrade pip \
&& pip install pyinstaller==$PYINSTALLER_VERSION \
&& pip install -r requirements.txt \
&& chmod +x pyinstaller.sh

ENTRYPOINT ["./pyinstaller.sh"]
2 changes: 1 addition & 1 deletion requirements.txt
Expand Up @@ -15,4 +15,4 @@ cffi
rfc3987==1.3.8
GitPython==2.1.11
# Reclass dependencies
pyparsing
pyparsing
7 changes: 7 additions & 0 deletions scripts/build-binary.sh
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

# make sure to run this from project root
set -e
IMAGE_NAME='pyinstaller-debian'
docker build -t $IMAGE_NAME -f pyinstaller-Dockerfile .
docker run -it -v $(pwd)/dist:/kapitan/dist $IMAGE_NAME
17 changes: 17 additions & 0 deletions scripts/pyinstaller.sh
@@ -0,0 +1,17 @@
#!/bin/bash -i
yoshi-1224 marked this conversation as resolved.
Show resolved Hide resolved

# this script is for building the binary inside docker image.]
yoshi-1224 marked this conversation as resolved.
Show resolved Hide resolved

set -e
. /root/.bashrc

entry='__main__'
output_name='runner'
pyi-makespec kapitan/"$entry".py --onefile \
--add-data kapitan/reclass/reclass:reclass \
--add-data kapitan/lib:kapitan/lib \
--add-data kapitan/inputs/helm/libtemplate.so:kapitan/inputs/helm \
--hidden-import pyparsing --hidden-import jsonschema \
--exclude-module doctest --exclude-module pydoc
pyinstaller "$entry".spec --clean
mv dist/$entry dist/$output_name