Created
February 20, 2022 08:52
-
-
Save m-tmatma/eead8603a0e8846194335394bba5cc22 to your computer and use it in GitHub Desktop.
docker image build
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 | |
SCRIPT_PATH=$(cd $(dirname $0); pwd) | |
DOCKER_DIR=$SCRIPT_PATH/docker | |
TESTS_DIR=$SCRIPT_PATH/tests | |
DOCKER_NAME=$(basename $SCRIPT_PATH) | |
DOCKER_REV=rev1 | |
function getFileListCheckSum() { | |
(cd $DOCKER_DIR; find . -type f | xargs md5sum) | |
} | |
function getDirCheckSum() { | |
getFileListCheckSum | md5sum | awk '{print $1}' | |
} | |
DOCKER_TAG=${DOCKER_NAME}:${DOCKER_REV}-$(getDirCheckSum) | |
function docker_build() { | |
docker build -t $DOCKER_TAG $DOCKER_DIR | |
} | |
function docker_runi() { | |
docker run -i -u user:user -v $TESTS_DIR:/home/user/tests -t $DOCKER_TAG $* | |
} | |
function docker_shell() { | |
docker_runi bash | |
} | |
function docker_find_image() { | |
IMAGE_TAG=$(docker image ls -q $DOCKER_TAG) | |
if [ x"$IMAGE_TAG" == x"" ]; then | |
echo "run '$0 image' first" | |
exit 1; | |
fi | |
} | |
ACTION=$1 | |
case "$ACTION" in | |
"image" ) docker_build ;; | |
"shell" ) docker_find_image; docker_shell ;; | |
* ) echo help ;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment