Skip to content
This repository has been archived by the owner on May 6, 2020. It is now read-only.

fix(models/app): recreate proc types on switch from Dockerfile to buildpack #1201

Merged
merged 1 commit into from
Feb 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions rootfs/api/models/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,13 +449,28 @@ def deploy(self, release, force_deploy=False, rollback_on_failure=True): # noqa
# use create to make sure minimum resources are created
self.create()

# set processes structure to default if app is new.
if self.structure == {}:
self.structure = self._default_structure(release)
self.save()

app_settings = self.appsettings_set.latest()
# reset canonical process types if build type has changed.
else:
# find the previous release's build type
prev_release = release.previous()
if prev_release and prev_release.build:
if prev_release.build.type != release.build.type:
structure = self.structure.copy()
# zero out canonical pod counts
for proctype in ['cmd', 'web']:
if proctype in structure:
structure[proctype] = 0
# update with the default process type.
structure.update(self._default_structure(release))
self.structure = structure
self.save()

# deploy application to k8s. Also handles initial scaling
app_settings = self.appsettings_set.latest()
deploys = {}
for scale_type, replicas in self.structure.items():
deploys[scale_type] = self._gather_app_settings(release, app_settings, scale_type, replicas) # noqa
Expand Down Expand Up @@ -874,9 +889,8 @@ def _update_application_service(self, namespace, app_type, port, routable=False,
# delete the annotation
service['metadata']['labels'].pop('router.deis.io/routable', None)

# Set app type if there is not one available
if 'type' not in service['spec']['selector']:
service['spec']['selector']['type'] = app_type
# Set app type selector
service['spec']['selector']['type'] = app_type

# Find if target port exists already, update / create as required
if routable:
Expand Down
10 changes: 8 additions & 2 deletions rootfs/api/tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,17 +288,23 @@ def test_build_forgotten_procfile(self, mock_requests):
self.assertEqual(response.status_code, 200, response.data)
self.assertEqual(len(response.data['results']), 0)

# verify web is still there
# verify web is not there
url = "/v2/apps/{app_id}/pods/web".format(**locals())
response = self.client.get(url)
self.assertEqual(response.status_code, 200, response.data)
self.assertEqual(len(response.data['results']), 0)

# verify cmd is there
url = "/v2/apps/{app_id}/pods/cmd".format(**locals())
response = self.client.get(url)
self.assertEqual(response.status_code, 200, response.data)
self.assertEqual(len(response.data['results']), 1)

# look at the app structure
url = "/v2/apps/{app_id}".format(**locals())
response = self.client.get(url)
self.assertEqual(response.status_code, 200, response.data)
self.assertEqual(response.json()['structure'], {'web': 0, 'worker': 0})
self.assertEqual(response.json()['structure'], {'cmd': 1, 'web': 0, 'worker': 0})

@override_settings(DEIS_DEPLOY_PROCFILE_MISSING_REMOVE=False)
def test_build_no_remove_process(self, mock_requests):
Expand Down