Skip to content

Commit

Permalink
Merge pull request #2 from teamhephy/feature/procfile-structure-on-app
Browse files Browse the repository at this point in the history
Adding procfile_structure on app api
  • Loading branch information
Cryptophobia committed Nov 13, 2017
2 parents 7010764 + 8fe90cf commit 73f7e9e
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 3 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
sudo: required
language: go

services:
- docker
Expand Down
22 changes: 22 additions & 0 deletions rootfs/api/migrations/0025_app_procfile_structure.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.2 on 2017-08-14 20:45
from __future__ import unicode_literals

import api.models.app
from django.db import migrations
import jsonfield.fields


class Migration(migrations.Migration):

dependencies = [
('api', '0024_config_lifecycle_hooks'),
]

operations = [
migrations.AddField(
model_name='app',
name='procfile_structure',
field=jsonfield.fields.JSONField(blank=True, default={}, validators=[api.models.app.validate_app_structure]),
),
]
13 changes: 13 additions & 0 deletions rootfs/api/models/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class App(UuidAuditedModel):
validators=[validate_app_id,
validate_reserved_names])
structure = JSONField(default={}, blank=True, validators=[validate_app_structure])
procfile_structure = JSONField(default={}, blank=True, validators=[validate_app_structure])

class Meta:
verbose_name = 'Application'
Expand Down Expand Up @@ -408,6 +409,7 @@ def scale(self, user, structure): # noqa
if new_structure != self.structure:
# save new structure to the database
self.structure = new_structure
self.procfile_structure = release.build.procfile
self.save()

try:
Expand Down Expand Up @@ -474,6 +476,7 @@ def deploy(self, release, force_deploy=False, rollback_on_failure=True): # noqa
# set processes structure to default if app is new.
if self.structure == {}:
self.structure = self._default_structure(release)
self.procfile_structure = self._default_structure(release)
self.save()
# reset canonical process types if build type has changed.
else:
Expand All @@ -489,8 +492,18 @@ def deploy(self, release, force_deploy=False, rollback_on_failure=True): # noqa
# update with the default process type.
structure.update(self._default_structure(release))
self.structure = structure
# if procfile structure exists then we use it
if release.build.procfile and \
release.build.sha and not \
release.build.dockerfile:
self.procfile_structure = release.build.procfile
self.save()

# always set the procfile structure for any new release
if release.build.procfile:
self.procfile_structure = release.build.procfile
self.save()

# deploy application to k8s. Also handles initial scaling
app_settings = self.appsettings_set.latest()
deploys = {}
Expand Down
3 changes: 2 additions & 1 deletion rootfs/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,12 @@ class AppSerializer(serializers.ModelSerializer):

owner = serializers.ReadOnlyField(source='owner.username')
structure = serializers.JSONField(required=False)
procfile_structure = serializers.JSONField(required=False)

class Meta:
"""Metadata options for a :class:`AppSerializer`."""
model = models.App
fields = ['uuid', 'id', 'owner', 'structure', 'created', 'updated']
fields = ['uuid', 'id', 'owner', 'structure', 'procfile_structure', 'created', 'updated']


class BuildSerializer(serializers.ModelSerializer):
Expand Down
3 changes: 2 additions & 1 deletion rootfs/api/tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ def test_response_data(self, mock_requests):
body = {'id': 'app-{}'.format(random.randrange(1000, 10000))}
response = self.client.post('/v2/apps', body)
for key in response.data:
self.assertIn(key, ['uuid', 'created', 'updated', 'id', 'owner', 'structure'])
self.assertIn(key, ['uuid', 'created', 'updated', 'id', 'owner', 'structure',
'procfile_structure'])
expected = {
'id': body['id'],
'owner': self.user.username,
Expand Down
3 changes: 2 additions & 1 deletion rootfs/api/tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,5 +378,6 @@ def test_regenerate(self):
def test_auth_no_ldap_by_default(self, mock_logger):
"""Ensure that LDAP authentication is disabled by default."""
self.test_auth()
# NOTE(bacongobbler): Using https://github.com/deisthree/controller/issues/1189 as a test case
# NOTE(bacongobbler): Using https://github.com/deisthree/controller/issues/1189
# as a test case
mock_logger.warning.assert_not_called()

0 comments on commit 73f7e9e

Please sign in to comment.