Update outdated python packages in docker container and write out new requirements.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
#set -euo pipefail | |
# no set -e has diff results in non-zero | |
echo "Checking Inside of Container For Outdated Pip" | |
hostdatetime=$(date +"%d-%m-%y-%H-%M-%S") | |
docker exec -i yourcontainer /bin/sh -c 'python3 -m pip list --outdated' | |
echo "Press y to Try Upgrading Inside of Container (any other to skip)" | |
read -r -p "Upgrade? [y/N] " response | |
if [[ "$response" =~ ^([yY])$ ]]; then | |
echo "will upgrade" | |
docker exec --env hdt=$hostdatetime -i yourcontainer /bin/sh -c 'python3 -m pip list --outdated |grep -v "^\-e" |cut -d = -f 1 | xargs -n1 python3 -m pip install --upgrade --use-deprecated=legacy-resolver ; wait ; python3 -m pip freeze > requirements-$hdt.txt' | |
# copy out from container is unnecessary in dev | |
# as we are mounted so the change shows locally. | |
echo "this will take a few minutes, when done you should see requirements-date/time appear" | |
while [[ ! -f ./requirements-${hostdatetime}.txt ]]; do sleep 1; done | |
echo "here is your diff" | |
curdiff=$(diff ./requirements.txt ./requirements-${hostdatetime}.txt) | |
echo $curdiff | |
echo "if the new reqs looks good we can backup and overwrite requirements" | |
read -r -p "BU and Overwrite? [y/N] " buresponse | |
if [[ "$buresponse" =~ ^([yY])$ ]]; then | |
cp ./requirements.txt ./requirements-$hostdatetime.backup | |
mv ./requirements-$hostdatetime.txt ./requirements.txt | |
echo "moved over and backedup" | |
else | |
echo "not backed-up or moved - you can choose later..." | |
fi | |
else | |
echo "skipping" | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment