-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbuilder
More file actions
117 lines (97 loc) · 2.93 KB
/
builder
File metadata and controls
117 lines (97 loc) · 2.93 KB
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
#!/usr/bin/env bash
#
# builder hook called on every git receive-pack
# NOTE: this script must be run as root (for docker access)
#
set -eo pipefail
ARGS=3
indent() {
echo " $@"
}
puts-step() {
echo "-----> $@"
}
puts-step-sameline() {
echo -n "-----> $@"
}
puts-warn() {
echo " ! $@"
}
usage() {
echo "Usage: $0 <user> <repo> <sha>"
}
parse-string(){
# helper to avoid the single quote escape
# occurred in command substitution
local args=() idx=0 IFS=' ' c
for c; do printf -v args[idx++] '%s ' "$c"; done
printf "%s\n" "${args[*]}"
}
if [ $# -ne $ARGS ]; then
usage
exit 1
fi
USER=$1
REPO=$2
GIT_SHA=$3
SHORT_SHA=${GIT_SHA:0:8}
APP_NAME="${REPO%.*}"
cd $(dirname $0) # ensure we are in the root dir
ROOT_DIR=$(pwd)
REPO_DIR="${ROOT_DIR}/${REPO}"
BUILD_DIR="${REPO_DIR}/build"
CACHE_DIR="${REPO_DIR}/cache"
# define image names
SLUG_NAME="$APP_NAME:git-$SHORT_SHA"
# create app directories
mkdir -p $BUILD_DIR $CACHE_DIR
# create temporary directory inside the build dir for this push
TMP_DIR=$(mktemp -d -p $BUILD_DIR)
cd $REPO_DIR
# use Procfile if provided, otherwise try default process types from ./release
git archive --format=tar.gz ${GIT_SHA} > ${APP_NAME}.tar.gz
TAR_URL=http://${HOST}:3000/git/home/${SLUG_NAME}/tar
PUSH_URL=http://${HOST}:3000/git/home/${SLUG_NAME}/push
if [ "$nosecret" == true ]; then
head -n 21 /etc/slugbuilder.yaml > /etc/tmp.yaml
mv /etc/tmp.yaml /etc/slugbuilder.yaml
fi
sed -i -- 's/puturl/${PUSH_URL}/g' /etc/deis-slugbuilder.yaml
sed -i -- 's/tar-url/${TAR_URL}/g' /etc/deis-slugbuilder.yaml
kubectl create -f /etc/deis-slugbuilder.yaml
PROCFILE='{"web":"example-go"}'
URL="{{ getv "/deis/controller/protocol" }}://{{ getv "/deis/controller/host" }}:{{ getv "/deis/controller/port" }}/v1/hooks/config"
RESPONSE=$(get-app-config -url="$URL" -key="{{ getv "/deis/controller/builderKey" }}" -user=$USER -app=$APP_NAME)
CODE=$?
echo $URL
echo $RESPONSE
if [ $CODE -ne 0 ]; then
puts-warn $RESPONSE
exit 1
fi
# use Procfile if provided, otherwise try default process types from ./release
echo $PROCFILE
USING_DOCKERFILE=false
puts-step "Launching... "
URL="{{ getv "/deis/controller/protocol" }}://{{ getv "/deis/controller/host" }}:{{ getv "/deis/controller/port" }}/v1/hooks/build"
DATA="$(generate-buildhook "$SHORT_SHA" "$USER" "$APP_NAME" "$APP_NAME" "$PROCFILE" "$USING_DOCKERFILE")"
echo $DATA
PUBLISH_RELEASE=$(echo "$DATA" | publish-release-controller -url=$URL -key={{ getv "/deis/controller/builderKey" }})
echo $PUBLISH_RELEASE
CODE=$?
if [ $CODE -ne 0 ]; then
puts-warn "ERROR: Failed to launch container"
puts-warn $PUBLISH_RELEASE
exit 1
fi
RELEASE=$(echo $PUBLISH_RELEASE | extract-version)
DOMAIN=$(echo $PUBLISH_RELEASE | extract-domain)
indent "done, $APP_NAME:v$RELEASE deployed to Deis"
echo
indent "http://$DOMAIN"
echo
indent "To learn more, use \`deis help\` or visit http://deis.io"
echo
# cleanup
cd $REPO_DIR
git gc &>/dev/null