-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathpush.sh
executable file
·51 lines (43 loc) · 1.37 KB
/
push.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
source vars
#This will take the latest locally built image and push it to the repository as
#configured in vars and tag it as latest.
if [[ ! -f builds ]]; then
echo
echo "It appears that the Docker image hasn't been built yet, run build.sh first"
echo
exit 1
fi
LATESTIMAGE=`tail -1 builds | awk '{print $8}'`
# Flatten is here as an option and not the default because with the export/import
# process we lose Dockerfile attributes like PORT and VOLUMES. Flattening helps if
# we are concerned about hitting the AUFS 42 layer limit or creating an image that
# other containers source FROM
DockerExport () {
docker export ${APP_NAME} | docker import - ${REPO_NAME}/${APP_NAME}:latest
}
DockerPush () {
docker push ${REPO_NAME}/${APP_NAME}:latest
}
case "$1" in
flatten)
docker inspect ${APP_NAME} > /dev/null 2>&1
if [[ $? -ne 0 ]]; then
echo "The ${APP_NAME} container doesn't appear to exist, exiting"
exit 1
fi
RUNNING=`docker inspect ${APP_NAME} | python -c 'import sys, json; print json.load(sys.stdin)[0]["State"]["Running"]'`
if [[ "${RUNNING}" = "True" ]]; then
echo "Stopping ${APP_NAME} container for export"
docker stop ${APP_NAME}
DockerExport
DockerPush
else
DockerExport
DockerPush
fi
;;
*)
docker tag -f ${LATESTIMAGE} ${REPO_NAME}/${APP_NAME}:latest
DockerPush
esac