python-rotate-backups icon indicating copy to clipboard operation
python-rotate-backups copied to clipboard

Create Dockerfile

Open zemkogabor opened this issue 3 years ago • 1 comments

Simple Dockerfile for this package.

zemkogabor avatar Sep 20 '22 14:09 zemkogabor

This will be useful if you have Docker but no Python, or had trouble getting the dependencies installed. If you think about it, though, you're pulling a small Debian operating system image across the InterWebs and spinning up a server just to run one Python program.

If you already have a Python interpreter on the host system, or another similar system, you might be happier deploying a zipapp. Because rotate-backups has a lot of dependencies, Python's built-in zipapp module won't cut it here. In spite of its terrible name, the shiv utility works as advertised:

git clone https://github.com/xolox/python-rotate-backups.git
cd python-rotate-backups
shiv -c rotate-backups -o rotate-backups .
./rotate-backups --help

That rotate-backups file is basically a ZIP archive with #!/usr/bin/env python3 at the top. It can then be copied anywhere with a compatible Python interpreter; all dependencies are included inside. After running it once, the archive is extracted to ~/.shiv for faster subsequent startups.

If you don't already have shiv installed somewhere else (e.g. with pip install --user or pipx), it would be fine to create a virtualenv within the rotate-backups source and then throw it away later:

python -m venv venv
. venv/bin/activate  # or venv/Scripts/Activate.ps1 on Windows
pip install shiv
shiv --help

One caveat: Windows doesn't understand Unix "shebang" lines without hacks and workarounds, so you may need to add a .py extension to the zipapp in order to use it on that platform.

ernstki avatar Dec 11 '25 14:12 ernstki