Skip to content

Commit 1db155f

Browse files
author
Matthew Fisher
committed
Merge pull request #3159 from bacongobbler/3042-lock-buildpack-url-to-revision
lock buildpack url to revision
2 parents 777ef1c + bdc4313 commit 1db155f

4 files changed

Lines changed: 45 additions & 11 deletions

File tree

builder/image/slugbuilder/builder/build.sh

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,32 @@ selected_buildpack=
7777
if [[ -n "$BUILDPACK_URL" ]]; then
7878
echo_title "Fetching custom buildpack"
7979

80+
# FIXME: strip single quotes coming from the builder
81+
BUILDPACK_URL=$(echo $BUILDPACK_URL | tr -d "'")
82+
8083
buildpack="$buildpack_root/custom"
8184
rm -fr "$buildpack"
82-
git clone --quiet --depth=1 "$BUILDPACK_URL" "$buildpack"
85+
86+
url=${BUILDPACK_URL%#*}
87+
committish=${BUILDPACK_URL#*#}
88+
89+
if [ "$committish" == "$url" ]; then
90+
committish="master"
91+
fi
92+
93+
set +e
94+
git clone --branch "$committish" --depth=1 "$url" "$buildpack" &> /dev/null
95+
SHALLOW_CLONED=$?
96+
set -e
97+
if [ $SHALLOW_CLONED -ne 0 ]; then
98+
# if the shallow clone failed partway through, clean up and try a full clone
99+
rm -rf "$buildpack"
100+
git clone --quiet "$url" "$buildpack"
101+
pushd "$buildpack" &>/dev/null
102+
git checkout --quiet "$committish"
103+
popd &>/dev/null
104+
fi
105+
83106
selected_buildpack="$buildpack"
84107
buildpack_name=$($buildpack/bin/detect "$build_root") && selected_buildpack=$buildpack
85108
else

docs/using_deis/using-buildpacks.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,14 @@ To use a custom buildpack, set the ``BUILDPACK_URL`` environment variable.
135135
=== humble-autoharp
136136
BUILDPACK_URL: https://github.com/dpiddy/heroku-buildpack-ruby-minimal
137137
138+
.. note::
139+
140+
If, however, you're unable to deploy using the latest version of the buildpack,
141+
You can set
142+
an exact version of a buildpack by using a git revision in your
143+
``BUILDPACK_URL``.
144+
For example: ``BUILDPACK_URL=https://github.com/dpiddy/heroku-buildpack-ruby-minimal#v13``
145+
138146
On your next ``git push``, the custom buildpack will be used.
139147

140148

tests/config_test.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ import (
99
)
1010

1111
var (
12-
configListCmd = "config:list --app={{.AppName}}"
13-
configSetCmd = "config:set FOO=讲台 --app={{.AppName}}"
14-
configSet2Cmd = "config:set FOO=10 --app={{.AppName}}"
15-
configSet3Cmd = "config:set POWERED_BY=\"the Deis team\" --app={{.AppName}}"
16-
configSet4Cmd = "config:set CAR='`star' --app={{.AppName}}"
17-
configUnsetCmd = "config:unset FOO --app={{.AppName}}"
12+
configListCmd = "config:list --app={{.AppName}}"
13+
configSetCmd = "config:set FOO=讲台 --app={{.AppName}}"
14+
configSet2Cmd = "config:set FOO=10 --app={{.AppName}}"
15+
configSet3Cmd = "config:set POWERED_BY=\"the Deis team\" --app={{.AppName}}"
16+
configSet4Cmd = "config:set CAR='`star' --app={{.AppName}}"
17+
configSetBuildpackCmd = "config:set BUILDPACK_URL=https://github.com/heroku/heroku-buildpack-go#98f37cc --app={{.AppName}}"
18+
configUnsetCmd = "config:unset FOO --app={{.AppName}}"
1819
)
1920

2021
func TestConfig(t *testing.T) {
@@ -48,6 +49,8 @@ func configSetup(t *testing.T) *utils.DeisTestConfig {
4849
// ensure envvars with backticks work too
4950
// https://github.com/deis/deis/issues/2980
5051
utils.Execute(t, configSet4Cmd, cfg, false, "`star")
52+
// ensure custom buildpack URLS are in order
53+
utils.Execute(t, configSetBuildpackCmd, cfg, false, "https://github.com/heroku/heroku-buildpack-go#98f37cc")
5154
utils.Execute(t, gitPushCmd, cfg, false, "")
5255
utils.CurlWithFail(t, cfg, false, "the Deis team")
5356
if err := utils.Chdir(".."); err != nil {
@@ -63,13 +66,13 @@ func configListTest(
6366

6467
func configSetTest(t *testing.T, params *utils.DeisTestConfig) {
6568
utils.Execute(t, configSetCmd, params, false, "讲台")
66-
utils.CheckList(t, appsInfoCmd, params, "(v5)", false)
67-
utils.Execute(t, configSet2Cmd, params, false, "10")
6869
utils.CheckList(t, appsInfoCmd, params, "(v6)", false)
70+
utils.Execute(t, configSet2Cmd, params, false, "10")
71+
utils.CheckList(t, appsInfoCmd, params, "(v7)", false)
6972
}
7073

7174
func configUnsetTest(t *testing.T, params *utils.DeisTestConfig) {
7275
utils.Execute(t, configUnsetCmd, params, false, "")
73-
utils.CheckList(t, appsInfoCmd, params, "(v7)", false)
76+
utils.CheckList(t, appsInfoCmd, params, "(v8)", false)
7477
utils.CheckList(t, "run env --app={{.AppName}}", params, "FOO", true)
7578
}

tests/utils/itutils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ func Execute(t *testing.T, cmd string, params interface{}, failFlag bool, expect
251251
cmdString := cmdBuf.String()
252252
fmt.Println(cmdString)
253253
var cmdl *exec.Cmd
254-
if strings.Contains(cmd, "git") {
254+
if strings.Contains(cmd, "git ") {
255255
cmdl = exec.Command("sh", "-c", cmdString)
256256
} else {
257257
cmdl = exec.Command("sh", "-c", Deis+cmdString)

0 commit comments

Comments
 (0)