Skip to content

Instantly share code, notes, and snippets.

@sergio-bershadsky
Last active July 9, 2018 11:34
Show Gist options
  • Select an option

  • Save sergio-bershadsky/c74a71fc48fb426019341ddef1703d0c to your computer and use it in GitHub Desktop.

Select an option

Save sergio-bershadsky/c74a71fc48fb426019341ddef1703d0c to your computer and use it in GitHub Desktop.
Docker based python freezer
#!/usr/bin/env bash
# Note:
# requirements.pip file must be inside current directory
#
# Use: freeze.sh [version:3.6]
#
# Example:
# > freeze.sh
# > freeze.sh 3.4
PYTHON_VERSION=${1:-3.7}
set -e
# Backup frozen version
mkdir $(pwd)/.history/ || true &> /dev/null
mv requirements.frozen.pip $(pwd)/.history/requirements.frozen.$(date +"%Y%m%d%H%M").pip || true &> /dev/null
echo "Freezing, please wait ..."
# Freeze
docker run \
-it \
--rm \
--entrypoint bash \
-v $(pwd)/requirements.pip:/tmp/requirements.pip \
python:$PYTHON_VERSION \
-c "pip install -r /tmp/requirements.pip &> /dev/null && pip freeze -q" > $(pwd)/requirements.frozen.pip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment