Clone a fresh copy of the source before building an image from it.
Chris Pressey
3 years ago
0 | #!/bin/sh | |
1 | ||
0 | 2 | # Common script for building a Docker image. |
1 | 3 | # Usage: build-docker-image.sh <dir-containing-docker-config> |
2 | 4 | |
3 | 5 | CONFIG_DIR=$1 |
4 | . $CONFIG_DIR/settings.sh | |
6 | if [ -r $CONFIG_DIR/settings.sh ]; then | |
7 | . $CONFIG_DIR/settings.sh | |
8 | else | |
9 | echo "'$CONFIG_DIR' is not a valid configuration directory" | |
10 | exit 1 | |
11 | fi | |
5 | 12 | |
6 | 13 | shelf_pwd() { |
7 | 14 | name="$1" |
16 | 23 | } |
17 | 24 | |
18 | 25 | if shelf_pwd ${SOURCE}; then |
19 | SRCDIR=`shelf_pwd ${SOURCE}` | |
26 | GITDIR=`shelf_pwd ${SOURCE}` | |
20 | 27 | else |
21 | 28 | echo "Please set SHELF_PATH to a directory where the source '${SOURCE}' can be found." |
22 | 29 | exit 1 |
26 | 33 | DOCKERFILE=$CONFIG_DIR/Dockerfile |
27 | 34 | IMAGENAME=$EXENAME |
28 | 35 | |
29 | find ${SRCDIR} -name '*.pyc' -exec rm {} \; | |
30 | find ${SRCDIR} -name '__pycache__' -exec rm -r {} \; | |
36 | SRCDIR=/tmp/$EXENAME | |
37 | ||
38 | echo "Cloning ${GITDIR} to ${SRCDIR}..." | |
39 | ||
40 | rm -rf ${SRCDIR} | |
41 | (cd /tmp/ && git clone ${GITDIR} ${EXENAME}) | |
31 | 42 | |
32 | 43 | docker container prune -f |
33 | 44 | docker rmi ${ORGNAME}/${IMAGENAME}:${VERSION} |