Hayaku - a lightweight Python utility to generate Dockerfile and distribute tiny python tooling/apps without explicitly including sources
pip install hayaku
Disclaimer this repo being made just for fun in certain circumstances and have non opinionated approach for doing things. The purpose of this is to wrap your existing tooling written in python into containers and then ship/distribute it without complicated workflow around git repo's.
- Autodetect of required pypi packages to install
- Encode py sources with base64/zip/bzip
- Put encoded data into of generated
Dockerfile
ENV (According to POSIX we can put up to 256Mb into env variable)
ENV PY_LIB "{body}"
- Extract it during docker build within the image
RUN python -c "import os,base64;b=os.getenv('PY_LIB');b=base64.b64decode(b);print(b.decode('utf-8'))" | tee app.py
- Final generated Dockerfile will looks like
hayaku app.py
FROM python:3.6
MAINTAINER Erlich Bachman
WORKDIR /app
RUN pip install requests
ENV PY_LIB "aW1wb3J0IGJhc2U2NAppbXBvcnQgb3MKZnJvbSB...."
RUN python -c "import os,base64;b=os.getenv('PY_LIB');b=base64.b64decode(b);print(b.decode('utf-8'))" | tee app.py
CMD python app.py
which you can ship as a file, build and push image to private docker registry, etc...
It's up to you. It worked for my limited usecase and I hope it might be helpfull for somebody else. As it said in disclamer: this repo being made just for fun in certain circumstances and have non opinionated approach for doing such things.
Does not work with multi file modules and local packages (TBD)