Skip to content

Commit a5d1aaa

Browse files
author
Matthew Fisher
committed
Merge pull request #2673 from bacongobbler/no-bash-wrapping
fix(controller): revert to `start proctype` for buildpack images
2 parents 8756caf + 53204c1 commit a5d1aaa

7 files changed

Lines changed: 41 additions & 14 deletions

File tree

builder/bin/generate-buildhook.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"encoding/json"
55
"fmt"
66
"os"
7-
"strconv"
87

98
"github.com/deis/deis/builder"
109
)
@@ -29,8 +28,10 @@ func main() {
2928
var procfile builder.ProcessType
3029
assert(json.Unmarshal([]byte(os.Args[5]), &procfile))
3130

32-
dockerfile, err := strconv.ParseBool(os.Args[6])
33-
assert(err)
31+
var dockerfile string = os.Args[6]
32+
if dockerfile == "false" {
33+
dockerfile = ""
34+
}
3435

3536
buildHook := builder.BuildHook{
3637
Sha: os.Args[1],

builder/image/templates/builder

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,12 @@ else
149149
RELEASE_INFO="{}"
150150
fi
151151

152-
if [ -f $TMP_DIR/Procfile ]; then
153-
# update release info with data from the Procfile
154-
RELEASE_INFO=$(cat $TMP_DIR/Procfile | /app/bin/yaml2json-procfile)
152+
if [ "$RELEASE_INFO" == "{}" ]; then
153+
if [ -f $TMP_DIR/Procfile ]; then
154+
# fall back to Procfile if there's no default process types
155+
# FIXME: refactor into slugbuilder
156+
RELEASE_INFO=$(cat $TMP_DIR/Procfile | /app/bin/yaml2json-procfile)
157+
fi
155158
fi
156159

157160
puts-step "Launching... "

builder/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ type BuildHook struct {
2727
ReceiveRepo string `json:"receive_repo"`
2828
Image string `json:"image"`
2929
Procfile ProcessType `json:"procfile"`
30-
Dockerfile bool `json:"dockerfile"`
30+
Dockerfile string `json:"dockerfile"`
3131
}
3232

3333
// BuildHookResponse represents a controller's build-hook response object.

builder/utils.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func ParseReleaseVersion(bytes []byte) (int, error) {
7171

7272
func GetDefaultType(bytes []byte) (string, error) {
7373
type YamlTypeMap struct {
74-
DefaultProcessTypes ProcessType
74+
DefaultProcessTypes ProcessType `default_process_types`
7575
}
7676

7777
var p YamlTypeMap
@@ -80,7 +80,7 @@ func GetDefaultType(bytes []byte) (string, error) {
8080
return "", err
8181
}
8282

83-
retVal, err := json.Marshal(&p)
83+
retVal, err := json.Marshal(&p.DefaultProcessTypes)
8484

8585
if err != nil {
8686
return "", err

builder/utils_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,11 @@ default_process_types:
121121
if err != nil {
122122
t.Error(err)
123123
}
124-
if defaultType == "" {
125-
t.Error("default type cannot be empty")
124+
if defaultType != `{"web":"while true; do echo hello; sleep 1; done"}` && string(data) != "" {
125+
t.Errorf("incorrect default type, got %s", defaultType)
126+
}
127+
if string(data) == "" && defaultType != "{}" {
128+
t.Errorf("incorrect default type, got %s", defaultType)
126129
}
127130
}
128131
}

controller/api/models.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,8 +407,13 @@ def _get_command(self):
407407
if self.type == 'cmd':
408408
return ''
409409
try:
410-
# ensure they cannot break out and run commands on the host
411-
return "bash -c '{}'".format(self.release.build.procfile[self.type])
410+
# if this is not procfile-based app, ensure they cannot break out
411+
# and run arbitrary commands on the host
412+
# FIXME: remove slugrunner's hardcoded entrypoint
413+
if self.release.build.dockerfile or not self.release.build.sha:
414+
return "bash -c '{}'".format(self.release.build.procfile[self.type])
415+
else:
416+
return 'start {}'.format(self.type)
412417
# if the key is not present or if a parent attribute is None
413418
except (KeyError, TypeError):
414419
return 'start {}'.format(self.type)

controller/api/tests/test_container.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,11 +456,14 @@ def test_command_good(self):
456456
app_id = response.data['id']
457457
app = App.objects.get(id=app_id)
458458
user = User.objects.get(username='autotest')
459+
# Heroku Buildpack app
459460
build = Build.objects.create(owner=user,
460461
app=app,
461462
image="qwerty",
462463
procfile={'web': 'node server.js',
463-
'worker': 'node worker.js'})
464+
'worker': 'node worker.js'},
465+
sha='african-swallow',
466+
dockerfile='')
464467
# create an initial release
465468
release = Release.objects.create(version=2,
466469
owner=user,
@@ -473,10 +476,22 @@ def test_command_good(self):
473476
release=release,
474477
type='web',
475478
num=1)
479+
# use `start web` for backwards compatibility with slugrunner
480+
self.assertEqual(c._command, 'start web')
481+
c.type = 'worker'
482+
self.assertEqual(c._command, 'start worker')
483+
# switch to docker image app
484+
build.sha = None
485+
c.type = 'web'
486+
self.assertEqual(c._command, "bash -c 'node server.js'")
487+
# switch to dockerfile app
488+
build.sha = 'european-swallow'
489+
build.dockerfile = 'dockerdockerdocker'
476490
self.assertEqual(c._command, "bash -c 'node server.js'")
477491
c.type = 'worker'
478492
self.assertEqual(c._command, "bash -c 'node worker.js'")
479493
c.release.build.procfile = None
494+
# for backwards compatibility if no Procfile is supplied
480495
self.assertEqual(c._command, 'start worker')
481496
c.type = 'cmd'
482497
self.assertEqual(c._command, '')

0 commit comments

Comments
 (0)