This repository has been archived by the owner on Jul 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.sh
executable file
·119 lines (92 loc) · 1.97 KB
/
deploy.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/bin/bash
if [ -z "$1" ]
then
echo "Run with option -h for some help."
exit 1
fi
## Set defaults
COMMIT="HEAD"
## Read options to override defaults
while getopts ":c:h" opt; do
case $opt in
h)
echo "Usage: deploy.sh [-h] [-c commit-id] config-dir"
echo " -h: Help"
echo " -c commit-id: Specify a certain commit ID (default: HEAD)."
echo " config-dir: The directory containing the config file."
exit 0;
;;
c)
COMMIT="$OPTARG"
;;
\?)
echo "Illegal option -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
shift $((OPTIND-1))
## Load functions and configuration
source functions.sh
loadconfig $1
## Create volume container
docker create --name ${VOLUME_NAME} ${IMAGE_VOLUME} /bin/true
if [ $? -ne 0 ]
then
exit 1
fi
## Clone source from repository
if [ "${DO_GIT_CLONE}" = true ]
then
docker run --rm \
-e "REPOSITORY=${REPOSITORY}" \
-e "BRANCH=${BRANCH}" \
-e "COMMIT=${COMMIT}" \
--volumes-from ${VOLUME_NAME} \
-v ${CUSTOM_DIR}:/custom:ro \
${IMAGE_GITCLONE}
if [ $? -ne 0 ]
then
exit 1
fi
fi
## Run custom build scripts using custom Docker images
if [ "${DO_BUILD}" = true ]
then
docker run --rm \
--volumes-from ${VOLUME_NAME} \
-v ${CUSTOM_DIR}:/custom:ro \
${IMAGE_BUILDER} \
bash -c 'source ~/.nvm/nvm.sh ; source /custom/build.sh'
if [ $? -ne 0 ]
then
exit 1
fi
fi
## Run deployment
if [ "${DO_DEPLOY}" = true ]
then
docker run --rm \
--volumes-from ${VOLUME_NAME} \
-v ${CUSTOM_DIR}:/custom:ro \
${IMAGE_DEPLOYER} \
bash -c 'cp /custom/id_rsa ~/.ssh/id_rsa ; /custom/deploy.sh'
if [ $? -ne 0 ]
then
exit 1
fi
fi
## Look into volume
# docker run --rm --volumes-from ${VOLUME_NAME} ubuntu:15.04 ls -lah /code
# docker run --rm --volumes-from ${VOLUME_NAME} ubuntu:15.04 ls -lah /build
## Remove volume container
echo "Finished. Removing Docker volume conatiner:"
docker rm -v ${VOLUME_NAME}
if [ $? -ne 0 ]
then
exit 1
fi