forked from cloudfoundry/go-buildpack
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcompile
executable file
·213 lines (184 loc) · 5.82 KB
/
compile
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#!/bin/bash
# usage: bin/compile <build-dir> <cache-dir> <env-dir>
echo "-----> Starting buildpack installation.."
set -eo pipefail
install_db2_odbc() {
DB2_DIR="$1"
CLI_DIR=$DB2_DIR/clidriver
if [ ! -d "$CLI_DIR" ]; then
DB2_DSDRIVER_URL="https://public.dhe.ibm.com/ibmdl/export/pub/software/data/db2/drivers/odbc_cli/linuxx64_odbc_cli.tar.gz"
echo "-----> Downloading and extracting DB2 CLI driver..."
curl ${DB2_DSDRIVER_URL} -s -o ${DB2_DIR}/clidriver.tgz
tar xzf ${DB2_DIR}/clidriver.tgz -C ${DB2_DIR}
fi
export CGO_LDFLAGS=-L$CLI_DIR/lib
export CGO_CFLAGS=-I$CLI_DIR/include
}
# Go releases for Darwin beginning with 1.2rc1
# have included more than one build, depending
# on the specific version of Mac OS X. Try to
# account for that, but don't try too hard.
# This doesn't affect Heroku builds, it's only
# for testing on Darwin systems.
platext() {
case $1 in
go1.0*|go1.1beta*|go1.1rc*|go1.1|go1.1.*) return ;;
esac
case $(uname|tr A-Z a-z) in
darwin) printf %s -osx10.8 ;;
esac
}
# Go releases have moved to a new URL scheme
# starting with Go version 1.2.2. Return the old
# location for known old versions and the new
# location otherwise.
urlfor() {
ver=$1
file=$2
case $ver in
go1.0*|go1.1beta*|go1.1rc*|go1.1|go1.1.*|go1.2beta*|go1.2rc*|go1.2|go1.2.1)
echo http://go.googlecode.com/files/$file
;;
*)
echo https://storage.googleapis.com/golang/$file
;;
esac
}
mkdir -p "$1" "$2"
build=$(cd "$1/" && pwd)
cache=$(cd "$2/" && pwd)
export buildpack=$(dirname $(dirname $0))
# CF Common
BUILDPACK_PATH=$buildpack
export BUILDPACK_PATH
source $buildpack/compile-extensions/lib/common
export PYTHONHOME=$BUILDPACK_PATH/builds/runtimes/python-2.7.6
export PATH=$PYTHONHOME/bin:$PATH
# END CF Common
arch=$(uname -m|tr A-Z a-z)
if test $arch = x86_64
then arch=amd64
fi
plat=$(uname|tr A-Z a-z)-$arch
# Python
venv=$cache/venv
mkdir -p $cache/pip
python=python2.7
PATH=$buildpack/$plat/bin:$venv/bin:$PATH
virtualenv() {
python "$buildpack/vendor/virtualenv-1.11.6/virtualenv.py" "$@"
}
if test -f $build/Godeps
then
name=$(<$build/Godeps jq -r .ImportPath)
ver=$(<$build/Godeps jq -r .GoVersion)
elif test -d $build/Godeps
then
name=$(<$build/Godeps/Godeps.json jq -r .ImportPath)
ver=$(<$build/Godeps/Godeps.json jq -r .GoVersion)
elif test -f $build/.godir
then
name=$(cat $build/.godir)
ver=go${GOVERSION:-1.4}
else
echo >&2 " ! A .godir is required. For instructions:"
echo >&2 " ! http://mmcgrana.github.io/2012/09/getting-started-with-go-on-heroku"
exit 1
fi
file=${GOFILE:-$ver.$(uname|tr A-Z a-z)-amd64$(platext $ver).tar.gz}
url=${GOURL:-$(urlfor $ver $file)}
if test -e $build/bin && ! test -d $build/bin
then
echo >&2 " ! File bin exists and is not a directory."
exit 1
fi
if is_cached
then
resource_error_msg="\n-----> Resource $url is not provided by this buildpack. Please upgrade your buildpack to receive the latest resources."
else
resource_error_msg="\n-----> Resource $url does not exist."
fi
if test -d $cache/$ver/go
then
echo "-----> Using $ver"
else
rm -rf $cache/* # be sure not to build up cruft
mkdir -p $cache/$ver
cd $cache/$ver
echo -n "-----> Installing $ver..."
(curl `translate_dependency_url $url` -s --fail -o - | tar xzf - -C $cache/$ver 2>/dev/null) || (echo -e $resource_error_msg 1>&2 ; exit 22)
echo " done"
fi
mkdir -p $build/bin
GOBIN=$build/bin export GOBIN
GOROOT=$cache/$ver/go export GOROOT
GOPATH=$build/.heroku/g export GOPATH
PATH=$GOROOT/bin:$PATH
if ! (test -d $build/Godeps || (which hg >/dev/null && which bzr >/dev/null))
then
## Allow unset variables for virtualenv
set +u
echo
echo " Tired of waiting for bzr and hg?"
echo " Try github.com/kr/godep for faster deploys."
echo
echo -n " Installing Virtualenv..."
virtualenv --python $python --distribute --never-download --prompt='(venv) ' $venv > /dev/null 2>&1
. $venv/bin/activate > /dev/null 2>&1
echo " done"
echo -n " Installing Mercurial..."
pip install mercurial --no-index --find-links=file://$buildpack/vendor > /dev/null 2>&1
echo " done"
echo -n " Installing Bazaar..."
pip install bzr --no-index --find-links=file://$buildpack/vendor > /dev/null 2>&1
echo " done"
## Re-disable unset variables
set -u
fi
p=$GOPATH/src/$name
mkdir -p $p
cp -R $build/* $p
# allow apps to specify cgo flags and set up /app symlink so things like CGO_CFLAGS=-I/app/... work
env_dir=${3:-''}
if [ -d $env_dir ]
then
ln -sfn $build /app/code
for key in CGO_CFLAGS CGO_CPPFLAGS CGO_CXXFLAGS CGO_LDFLAGS GO_GIT_DESCRIBE_SYMBOL
do
if [ -f "$env_dir/$key" ]
then
export "$key=$(cat "$env_dir/$key")"
fi
done
fi
FLAGS=(-tags cloudfoundry)
if [ -z GO_GIT_DESCRIBE_SYMBOL ] && [ test -n "$GO_GIT_DESCRIBE_SYMBOL" ]
then
git_describe=$(git describe --tags --always)
FLAGS=(${FLAGS[@]} -ldflags "-X $GO_GIT_DESCRIBE_SYMBOL $git_describe")
fi
unset GIT_DIR # unset git dir or it will mess with goinstall
#Check for db2 dependency in application
if [ "$(go list -f {{.Deps}} | grep 'db2')" = "" ]
then
echo "-----> DB2 dependency found, Installing DB2 dependency..."
if test -d $cache/clidriver; then
echo "-----> Restoring DB2 ODBC driver [DB2 CLI] setup from cache"
cp -r $cache/clidriver $build/
else
install_db2_odbc "${build}"
fi
fi
cd $p
if test -e $build/Godeps
then
echo "-----> Running: godep go install ${FLAGS[@]} ./..."
godep go install "${FLAGS[@]}" ./...
else
echo "-----> Running: go get ${FLAGS[@]} ./..."
go get "${FLAGS[@]}" ./...
fi
rm -rf $build/.heroku
mkdir -p $build/.profile.d
echo 'PATH=$PATH:$HOME/bin' > $build/.profile.d/go.sh
echo "export LD_LIBRARY_PATH=\"\$HOME/clidriver/lib:\$LD_LIBRARY_PATH\"" >> $build/.profile.d/go.sh