forked from negativetwelve/heroku-buildpack-subdir
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcompile
121 lines (97 loc) · 2.92 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
#!/usr/bin/env bash
set -e
function indent() {
c='s/^/ /'
case $(uname) in
Darwin) sed -l "$c";;
*) sed -u "$c";;
esac
}
unset GIT_DIR
subdirs=()
for BUILDPACK in $(cat $1/.buildpacks); do
dir=$(mktemp -t buildpackXXXXX)
rm -rf $dir
subdir=""
if [[ $BUILDPACK == *'='* ]]; then
subdir=$(echo $BUILDPACK | cut -d"=" -f 1)
BUILDPACK=$(echo $BUILDPACK | cut -d"=" -f 2)
fi
url=${BUILDPACK%#*}
branch=${BUILDPACK#*#}
if [ "$branch" == "$url" ]; then
branch=""
fi
if [ "$url" != "" ]; then
echo "=====> Downloading Buildpack: $url, branch: $branch, to tmp dir $dir, against source's subdir: $subdir"
if [[ "$url" =~ \.tgz$ ]] || [[ "$url" =~ \.tgz\? ]]; then
mkdir -p "$dir"
curl -s "$url" | tar xvz -C "$dir" >/dev/null 2>&1
else
git clone $url $dir >/dev/null 2>&1
if [ -f "$dir/.gitmodules" ]; then
echo "=====> Detected git submodules. Initializing..."
(cd $dir && git submodule update --init --recursive)
fi
fi
cd $dir
if [ "$branch" != "" ]; then
git checkout $branch >/dev/null 2>&1
fi
# Ensure that these files exist.
chmod -f +x $dir/bin/{detect,compile,release} || true
framework=$($dir/bin/detect $1/$subdir)
if [ $? == 0 ]; then
echo "=====> Detected Framework: $framework"
# echo "-----> Compiling with BUILD_DIR: $1, SUB_DIR: $subdir"
# echo "-----> Ls BUILD_DIR: $(ls -la $1)"
# echo "-----> Ls \$3: $(ls -la $3)"
# echo "-----> Ls \$2: $(ls -la $2)"
# echo "-----> Ls SUB_DIR(\$1/\$subdir): $(ls -la $1/$subdir)"
# bin/compile BUILD_DIR CACHE_DIR ENV_DIR
$dir/bin/compile $1/$subdir $2 $3
if [ $? != 0 ]; then
exit 1
fi
# check if the buildpack left behind an environment for subsequent ones
if [ -e $dir/export ]; then
source $dir/export
fi
if [ ! -z $subdir ]; then
subdirs+=($subdir)
fi
if [ -x $dir/bin/release ]; then
$dir/bin/release $1/$subdir > $1/$subdir/last_pack_release.out
fi
else
echo "Couldn't detect any framework for this buildpack. Exiting."
exit 1
fi
fi
done
# create a special .profile.d script that sources the
# .profile.d scripts in sub directories when the app starts
if [[ -f "$3/SUBDIR_ENABLE_PROFILE_SOURCING" ]]; then
mkdir -p $1/.profile.d
cat >$1/.profile.d/subdir-buildpack.sh <<EOL
#!/usr/bin/env bash
APP_DIR="\$HOME"
dirs="${subdirs[@]}"
for dir in \$dirs
do
cd "\$dir"
export HOME="\$APP_DIR/\$dir"
files=\$(find .profile.d -maxdepth 1 -name "*.sh" -type f)
for script in \$files
do
source "\$script"
done
export HOME="\$APP_DIR"
cd - > /dev/null
done
EOL
chmod +x $1/.profile.d/subdir-buildpack.sh
fi
if [[ -e $1/last_pack_release.out ]]; then
echo "Using release configuration from last framework ($framework)."
fi