Skip to content

Commit 68ee0af

Browse files
committed
Adding procfile_structure to app api
1 parent 7698eb9 commit 68ee0af

3 files changed

Lines changed: 37 additions & 1 deletion

File tree

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):

0 commit comments

Comments
 (0)