Skip to content

Commit 73f7e9e

Browse files
authored
Merge pull request #2 from teamhephy/feature/procfile-structure-on-app
Adding procfile_structure on app api
2 parents 7010764 + 8fe90cf commit 73f7e9e

File tree

6 files changed

+42
-3
lines changed

6 files changed

+42
-3
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
sudo: required
2+
language: go
23

34
services:
45
- docker
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# -*- coding: utf-8 -*-
2+
# Generated by Django 1.11.2 on 2017-08-14 20:45
3+
from __future__ import unicode_literals
4+
5+
import api.models.app
6+
from django.db import migrations
7+
import jsonfield.fields
8+
9+
10+
class Migration(migrations.Migration):
11+
12+
dependencies = [
13+
('api', '0024_config_lifecycle_hooks'),
14+
]
15+
16+
operations = [
17+
migrations.AddField(
18+
model_name='app',
19+
name='procfile_structure',
20+
field=jsonfield.fields.JSONField(blank=True, default={}, validators=[api.models.app.validate_app_structure]),
21+
),
22+
]

rootfs/api/models/app.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ class App(UuidAuditedModel):
7171
validators=[validate_app_id,
7272
validate_reserved_names])
7373
structure = JSONField(default={}, blank=True, validators=[validate_app_structure])
74+
procfile_structure = JSONField(default={}, blank=True, validators=[validate_app_structure])
7475

7576
class Meta:
7677
verbose_name = 'Application'
@@ -408,6 +409,7 @@ def scale(self, user, structure): # noqa
408409
if new_structure != self.structure:
409410
# save new structure to the database
410411
self.structure = new_structure
412+
self.procfile_structure = release.build.procfile
411413
self.save()
412414

413415
try:
@@ -474,6 +476,7 @@ def deploy(self, release, force_deploy=False, rollback_on_failure=True): # noqa
474476
# set processes structure to default if app is new.
475477
if self.structure == {}:
476478
self.structure = self._default_structure(release)
479+
self.procfile_structure = self._default_structure(release)
477480
self.save()
478481
# reset canonical process types if build type has changed.
479482
else:
@@ -489,8 +492,18 @@ def deploy(self, release, force_deploy=False, rollback_on_failure=True): # noqa
489492
# update with the default process type.
490493
structure.update(self._default_structure(release))
491494
self.structure = structure
495+
# if procfile structure exists then we use it
496+
if release.build.procfile and \
497+
release.build.sha and not \
498+
release.build.dockerfile:
499+
self.procfile_structure = release.build.procfile
492500
self.save()
493501

502+
# always set the procfile structure for any new release
503+
if release.build.procfile:
504+
self.procfile_structure = release.build.procfile
505+
self.save()
506+
494507
# deploy application to k8s. Also handles initial scaling
495508
app_settings = self.appsettings_set.latest()
496509
deploys = {}

rootfs/api/serializers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,12 @@ class AppSerializer(serializers.ModelSerializer):
172172

173173
owner = serializers.ReadOnlyField(source='owner.username')
174174
structure = serializers.JSONField(required=False)
175+
procfile_structure = serializers.JSONField(required=False)
175176

176177
class Meta:
177178
"""Metadata options for a :class:`AppSerializer`."""
178179
model = models.App
179-
fields = ['uuid', 'id', 'owner', 'structure', 'created', 'updated']
180+
fields = ['uuid', 'id', 'owner', 'structure', 'procfile_structure', 'created', 'updated']
180181

181182

182183
class BuildSerializer(serializers.ModelSerializer):

rootfs/api/tests/test_app.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ def test_response_data(self, mock_requests):
9090
body = {'id': 'app-{}'.format(random.randrange(1000, 10000))}
9191
response = self.client.post('/v2/apps', body)
9292
for key in response.data:
93-
self.assertIn(key, ['uuid', 'created', 'updated', 'id', 'owner', 'structure'])
93+
self.assertIn(key, ['uuid', 'created', 'updated', 'id', 'owner', 'structure',
94+
'procfile_structure'])
9495
expected = {
9596
'id': body['id'],
9697
'owner': self.user.username,

rootfs/api/tests/test_auth.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,5 +378,6 @@ def test_regenerate(self):
378378
def test_auth_no_ldap_by_default(self, mock_logger):
379379
"""Ensure that LDAP authentication is disabled by default."""
380380
self.test_auth()
381-
# NOTE(bacongobbler): Using https://github.com/deisthree/controller/issues/1189 as a test case
381+
# NOTE(bacongobbler): Using https://github.com/deisthree/controller/issues/1189
382+
# as a test case
382383
mock_logger.warning.assert_not_called()

0 commit comments

Comments
 (0)