Created
November 22, 2021 11:01
-
-
Save mehd-io/d4b774b17cb284c2bdbe62d6ceb0a88f to your computer and use it in GitHub Desktop.
medium-python-api-boilerplate managing version of dockerfile
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
#!/bin/bash | |
# Simple bash script to generate version based on hash of files or git command | |
ROOT=$(git rev-parse --show-toplevel) | |
OS=$(uname -s) | |
if [ "$OS" = "Linux" ]; then | |
md5_cmd="md5sum | |
elif [ "$OS" = "Darwin" ]; then | |
md5_cmd="md5 -r" | |
else | |
echo "OS NOT DETECTED, couldn't get hash for version" | |
exit 1; | |
fi | |
case $1 in | |
base) | |
REQ_HASH=$( | |
cat \ | |
"$ROOT/pyproject.toml" \ | |
"$ROOT/poetry.lock" \ | |
"$ROOT/docker/base.Dockerfile" \ | |
| ${md5_cmd} \ | |
| cut -d' ' -f1 \ | |
| tr '[:upper:]' '[:lower:]' | |
) | |
echo "$1-${REQ_HASH:0:20}" | |
;; | |
app) | |
echo "$1-$(git rev-parse --short=20 HEAD)" | |
;; | |
dev) | |
echo "$1-latest" | |
;; | |
*) | |
echo "unknown" | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment