Skip to content

Commit c04a05f

Browse files
author
Matthew Fisher
committed
fix(controller): use /runner/init entrypoint only on procfile
When a dockerfile and a Procfile are present, the default entrypoint should be /bin/bash instead of /runner/init, which is the default entrypoint for Procfile-based applications.
1 parent 64ffeac commit c04a05f

3 files changed

Lines changed: 53 additions & 2 deletions

File tree

controller/api/models.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,11 @@ def run(self, command):
477477
image = self.release.image
478478
job_id = self._job_id
479479
entrypoint = '/bin/bash'
480-
if self.release.build.procfile:
480+
# if this is a procfile-based app, switch the entrypoint to slugrunner's default
481+
# FIXME: remove slugrunner's hardcoded entrypoint
482+
if self.release.build.procfile and \
483+
self.release.build.sha and not \
484+
self.release.build.dockerfile:
481485
entrypoint = '/runner/init'
482486
command = "'{}'".format(command)
483487
else:

controller/api/tests/test_container.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,3 +468,44 @@ def test_command_good(self):
468468
self.assertEqual(c._command, 'start worker')
469469
c.type = 'cmd'
470470
self.assertEqual(c._command, '')
471+
472+
def test_run_command_good(self):
473+
"""Test the run command for each container workflow"""
474+
url = '/v1/apps'
475+
response = self.client.post(url, HTTP_AUTHORIZATION='token {}'.format(self.token))
476+
self.assertEqual(response.status_code, 201)
477+
app_id = response.data['id']
478+
app = App.objects.get(id=app_id)
479+
user = User.objects.get(username='autotest')
480+
# dockerfile + procfile worflow
481+
build = Build.objects.create(owner=user,
482+
app=app,
483+
image="qwerty",
484+
procfile={'web': 'node server.js',
485+
'worker': 'node worker.js'},
486+
dockerfile='foo',
487+
sha='somereallylongsha')
488+
# create an initial release
489+
release = Release.objects.create(version=2,
490+
owner=user,
491+
app=app,
492+
config=app.config_set.latest(),
493+
build=build)
494+
# create a container
495+
c = Container.objects.create(owner=user,
496+
app=app,
497+
release=release,
498+
type='web',
499+
num=1)
500+
rc, output = c.run('echo hi')
501+
self.assertEqual(rc, 0)
502+
self.assertEqual(json.loads(output)['entrypoint'], '/bin/bash')
503+
# docker image workflow
504+
build.dockerfile = None
505+
build.sha = None
506+
rc, output = c.run('echo hi')
507+
self.assertEqual(json.loads(output)['entrypoint'], '/bin/bash')
508+
# procfile workflow
509+
build.sha = 'somereallylongsha'
510+
rc, output = c.run('echo hi')
511+
self.assertEqual(json.loads(output)['entrypoint'], '/runner/init')

controller/scheduler/mock.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
2+
import json
13
from cStringIO import StringIO
24

35

@@ -39,7 +41,11 @@ def run(self, name, image, entrypoint, command):
3941
"""
4042
Run a one-off command
4143
"""
42-
return 0, ''
44+
# dump input into a json object for testing purposes
45+
return 0, json.dumps({'name': name,
46+
'image': image,
47+
'entrypoint': entrypoint,
48+
'command': command})
4349

4450
def attach(self, name):
4551
"""

0 commit comments

Comments
 (0)