forked from pmorie/ubuntu-buildpack
-
Notifications
You must be signed in to change notification settings - Fork 1
/
buildpack
executable file
·95 lines (79 loc) · 2.12 KB
/
buildpack
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
#!/bin/bash
set -e
indent() {
sed -u 's/^/ /'
}
message() {
echo "-----> $*"
}
if [ -z $BUILDPACK_URL ]; then
message "No BUILDPACK_URL specified, source will not be built"
exit 1;
fi
SOURCE_DIR=$1
CACHE_DIR=${CACHE_DIR:-/tmp/cache}
HOME=/home/buildpack
if [ ! -e $SOURCE_DIR ]; then
message "Need to provide a source directory as the first argument"
exit 1
fi
message Building your $SOURCE_DIR with $BUILDPACK_URL
mkdir -p $HOME
mkdir -p $CACHE_DIR
mkdir -p $CACHE_DIR/compile
cp -Rf $SOURCE_DIR/* $HOME
cd /tmp
PACK_ID=$(message $BUILDPACK_URL | md5sum | cut -d ' ' -f 1)
PACK_DIR=$CACHE_DIR/packs/$PACK_ID
if [ -d $PACK_DIR ] && [ -f $PACK_DIR/.complete ]; then
message "Using cached buildpack"
else
mkdir -p $PACK_DIR
if [[ $BUILDPACK_URL = "git@"* ]] || [[ $BUILDPACK_URL = "git://"* ]] || [[ $BUILDPACK_URL = *".git" ]]; then
if (git clone $BUILDPACK_URL $PACK_DIR | indent); then
message
else
message "Unable to clone $BUILDPACK_URL"
exit 1
fi
elif [[ $BUILDPACK_URL = "http://"* ]] || [[ $BUILDPACK_URL = "https://"* ]]; then
if (wget -O $BUILDPACK_URL | tar xvz -C $PACK_DIR | indent); then
message
else
message "Unable to download and extract $BUILDPACK_URL"
exit 1
fi
else
message "BUILDPACK_URL not recognized"
exit 1
fi
touch $PACK_DIR/.complete
fi
OUT=$($PACK_DIR/bin/detect $HOME)
ret=$?
if [ $ret -ne 0 ]; then
message "bin/detect reported the source is not recognizable"
exit 1
fi
message "Building framework '$OUT'"
$PACK_DIR/bin/compile $HOME $CACHE_DIR/compile
ret=$?
if [ $ret -ne 0 ]; then
message "Build failed"
exit 1
fi
message "Check Procfile"
if [ ! -e $HOME/Procfile ]; then
$PACK_DIR/bin/release $HOME > /tmp/release.yaml
ret=$?
if [ $ret -ne 0 ]; then
message "Unable to generate release info"
exit 1
fi
cat /tmp/release.yaml | ruby -ryaml -e 'puts (YAML.load(STDIN)["default_process_types"] || {}).sort_by{|(k,v)| k == "web" ? [0,k] : [1,k]}.map{|(k,v)| "#{k}: #{v}"}.join("\n")' > $HOME/Procfile
ret=$?
if [ $ret -ne 0 ]; then
message "Unable to generate default Procfile"
exit 1
fi
fi