Skip to content

Commit 981f6cb

Browse files
author
Matthew Fisher
committed
fix(controller): read command from procfile
1 parent 0261f04 commit 981f6cb

2 files changed

Lines changed: 38 additions & 1 deletion

File tree

controller/api/models.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,11 @@ def _get_command(self):
404404
# handle special case for Dockerfile deployments
405405
if self.type == 'cmd':
406406
return ''
407-
else:
407+
try:
408+
# ensure they cannot break out and run commands on the host
409+
return "bash -c '{}'".format(self.release.build.procfile[self.type])
410+
# if the key is not present or if a parent attribute is None
411+
except (KeyError, TypeError):
408412
return 'start {}'.format(self.type)
409413

410414
_command = property(_get_command)

controller/api/tests/test_container.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,3 +435,36 @@ def test_scale_without_build_should_error(self):
435435
HTTP_AUTHORIZATION='token {}'.format(self.token))
436436
self.assertEqual(response.status_code, 400)
437437
self.assertEqual(response.data, "No build associated with this release")
438+
439+
def test_command_good(self):
440+
"""Test the default command for each container workflow"""
441+
url = '/v1/apps'
442+
response = self.client.post(url, HTTP_AUTHORIZATION='token {}'.format(self.token))
443+
self.assertEqual(response.status_code, 201)
444+
app_id = response.data['id']
445+
app = App.objects.get(id=app_id)
446+
user = User.objects.get(username='autotest')
447+
build = Build.objects.create(owner=user,
448+
app=app,
449+
image="qwerty",
450+
procfile={'web': 'node server.js',
451+
'worker': 'node worker.js'})
452+
# create an initial release
453+
release = Release.objects.create(version=2,
454+
owner=user,
455+
app=app,
456+
config=app.config_set.latest(),
457+
build=build)
458+
# create a container
459+
c = Container.objects.create(owner=user,
460+
app=app,
461+
release=release,
462+
type='web',
463+
num=1)
464+
self.assertEqual(c._command, "bash -c 'node server.js'")
465+
c.type = 'worker'
466+
self.assertEqual(c._command, "bash -c 'node worker.js'")
467+
c.release.build.procfile = None
468+
self.assertEqual(c._command, 'start worker')
469+
c.type = 'cmd'
470+
self.assertEqual(c._command, '')

0 commit comments

Comments
 (0)