Skip to content

Commit c22ff9e

Browse files
author
Matthew Fisher
committed
Merge pull request #2794 from bacongobbler/2740-slugbuilder-to-stdout
fix(builder): allow users to cat slugfile
2 parents f798261 + 343d84b commit c22ff9e

1 file changed

Lines changed: 50 additions & 37 deletions

File tree

  • builder/image/slugbuilder/builder
Lines changed: 50 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
#!/bin/bash
22
set -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+
515
app_dir=/app
616
build_root=/tmp/build
717
cache_root=/tmp/cache
@@ -13,37 +23,36 @@ mkdir -p $buildpack_root
1323
mkdir -p $build_root/.profile.d
1424

1525
function 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

2333
function echo_title() {
24-
echo $'\e[1G----->' $* | output_redirect
34+
echo $'\e[1G----->' $* | output_redirect
2535
}
2636

2737
function echo_normal() {
28-
echo $'\e[1G ' $* | output_redirect
38+
echo $'\e[1G ' $* | output_redirect
2939
}
3040

3141
function 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
4352
if [ -d "/tmp/app" ]; then
44-
cp -rf /tmp/app/. $app_dir
53+
cp -rf /tmp/app/. $app_dir
4554
else
46-
cat | tar -xmC $app_dir
55+
cat | tar -xmC $app_dir
4756
fi
4857

4958
# In heroku, there are two separate directories, and some
@@ -63,24 +72,24 @@ buildpacks=($buildpack_root/*)
6372
selected_buildpack=
6473

6574
if [[ -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
7382
else
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
7786
fi
7887

7988
if [[ -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
8493
fi
8594

8695
## Buildpack compile
@@ -93,25 +102,29 @@ $selected_buildpack/bin/release "$build_root" "$cache_root" > $build_root/.relea
93102

94103
echo_title "Discovering process types"
95104
if [[ -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"
98107
fi
99108
default_types=""
100109
if [[ -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"
103112
fi
104113

105114

106115
## Produce slug
107116

108117
if [[ -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
110119
else
111-
tar -z --exclude='.git' -C $build_root -cf $slug_file . | cat
120+
tar -z --exclude='.git' -C $build_root -cf $slug_file . | cat
112121
fi
113122

114123
if [[ "$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
117130
fi

0 commit comments

Comments
 (0)