11#! /bin/bash
22set -eo pipefail
33
4- slug_file=/tmp/slug.tgz
4+
5+ if [[ " $1 " == " -" ]]; then
6+ slug_file=" $1 "
7+ else
8+ slug_file=/tmp/slug.tgz
9+ if [[ " $1 " ]]; then
10+ put_url=" $1 "
11+ fi
12+ fi
13+
14+
515app_dir=/app
616build_root=/tmp/build
717cache_root=/tmp/cache
@@ -13,37 +23,36 @@ mkdir -p $buildpack_root
1323mkdir -p $build_root /.profile.d
1424
1525function output_redirect() {
16- if [[ " $slug_file " == " -" ]]; then
17- cat - 1>&2
18- else
19- cat -
20- fi
26+ if [[ " $slug_file " == " -" ]]; then
27+ cat - 1>&2
28+ else
29+ cat -
30+ fi
2131}
2232
2333function echo_title() {
24- echo $' \e [1G----->' $* | output_redirect
34+ echo $' \e [1G----->' $* | output_redirect
2535}
2636
2737function echo_normal() {
28- echo $' \e [1G ' $* | output_redirect
38+ echo $' \e [1G ' $* | output_redirect
2939}
3040
3141function ensure_indent() {
32- while read line; do
33- if [[ " $line " == --* ]]; then
34- echo $' \e [1G' $line | output_redirect
35- else
36- echo $' \e [1G ' " $line " | output_redirect
37- fi
38-
39- done
42+ while read line; do
43+ if [[ " $line " == --* ]]; then
44+ echo $' \e [1G' $line | output_redirect
45+ else
46+ echo $' \e [1G ' " $line " | output_redirect
47+ fi
48+ done
4049}
4150
4251# # Copy application code over
4352if [ -d " /tmp/app" ]; then
44- cp -rf /tmp/app/. $app_dir
53+ cp -rf /tmp/app/. $app_dir
4554else
46- cat | tar -xmC $app_dir
55+ cat | tar -xmC $app_dir
4756fi
4857
4958# In heroku, there are two separate directories, and some
@@ -63,24 +72,24 @@ buildpacks=($buildpack_root/*)
6372selected_buildpack=
6473
6574if [[ -n " $BUILDPACK_URL " ]]; then
66- echo_title " Fetching custom buildpack"
75+ echo_title " Fetching custom buildpack"
6776
68- buildpack=" $buildpack_root /custom"
69- rm -fr " $buildpack "
70- git clone --quiet --depth=1 " $BUILDPACK_URL " " $buildpack "
71- selected_buildpack=" $buildpack "
72- buildpack_name=$( $buildpack /bin/detect " $build_root " ) && selected_buildpack=$buildpack
77+ buildpack=" $buildpack_root /custom"
78+ rm -fr " $buildpack "
79+ git clone --quiet --depth=1 " $BUILDPACK_URL " " $buildpack "
80+ selected_buildpack=" $buildpack "
81+ buildpack_name=$( $buildpack /bin/detect " $build_root " ) && selected_buildpack=$buildpack
7382else
7483 for buildpack in " ${buildpacks[@]} " ; do
75- buildpack_name=$( $buildpack /bin/detect " $build_root " ) && selected_buildpack=$buildpack && break
84+ buildpack_name=$( $buildpack /bin/detect " $build_root " ) && selected_buildpack=$buildpack && break
7685 done
7786fi
7887
7988if [[ -n " $selected_buildpack " ]]; then
80- echo_title " $buildpack_name app detected"
81- else
82- echo_title " Unable to select a buildpack"
83- exit 1
89+ echo_title " $buildpack_name app detected"
90+ else
91+ echo_title " Unable to select a buildpack"
92+ exit 1
8493fi
8594
8695# # Buildpack compile
@@ -93,25 +102,29 @@ $selected_buildpack/bin/release "$build_root" "$cache_root" > $build_root/.relea
93102
94103echo_title " Discovering process types"
95104if [[ -f " $build_root /Procfile" ]]; then
96- types=$( ruby -e " require 'yaml';puts YAML.load_file('$build_root /Procfile').keys().join(', ')" )
97- echo_normal " Procfile declares types -> $types "
105+ types=$( ruby -e " require 'yaml';puts YAML.load_file('$build_root /Procfile').keys().join(', ')" )
106+ echo_normal " Procfile declares types -> $types "
98107fi
99108default_types=" "
100109if [[ -s " $build_root /.release" ]]; then
101- default_types=$( ruby -e " require 'yaml';puts (YAML.load_file('$build_root /.release')['default_process_types'] || {}).keys().join(', ')" )
102- [[ $default_types ]] && echo_normal " Default process types for $buildpack_name -> $default_types "
110+ default_types=$( ruby -e " require 'yaml';puts (YAML.load_file('$build_root /.release')['default_process_types'] || {}).keys().join(', ')" )
111+ [[ $default_types ]] && echo_normal " Default process types for $buildpack_name -> $default_types "
103112fi
104113
105114
106115# # Produce slug
107116
108117if [[ -f " $build_root /.slugignore" ]]; then
109- tar -z --exclude=' .git' -X " $build_root /.slugignore" -C $build_root -cf $slug_file . | cat
118+ tar -z --exclude=' .git' -X " $build_root /.slugignore" -C $build_root -cf $slug_file . | cat
110119else
111- tar -z --exclude=' .git' -C $build_root -cf $slug_file . | cat
120+ tar -z --exclude=' .git' -C $build_root -cf $slug_file . | cat
112121fi
113122
114123if [[ " $slug_file " != " -" ]]; then
115- slug_size=$( du -Sh " $slug_file " | cut -f1)
116- echo_title " Compiled slug size is $slug_size "
124+ slug_size=$( du -Sh " $slug_file " | cut -f1)
125+ echo_title " Compiled slug size is $slug_size "
126+
127+ if [[ $put_url ]]; then
128+ curl -0 -s -o /dev/null -X PUT -T $slug_file " $put_url "
129+ fi
117130fi
0 commit comments