Skip to content

Commit ccc6b1f

Browse files
committed
feat(release): require PORT to be set when private registry is set
Prior to this the PORT was defaulting to 5000 instead. Fixes #775
1 parent c7fb984 commit ccc6b1f

3 files changed

Lines changed: 48 additions & 1 deletion

File tree

rootfs/api/models/config.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,13 @@ def set_registry(self):
8585
# lower case all registry options for consistency
8686
self.registry = {key.lower(): value for key, value in self.registry.copy().items()}
8787

88+
# PORT must be set if private registry is being used
89+
if self.registry and self.values.get('PORT', None) is None:
90+
# only thing that can get past post_save in the views
91+
raise DeisException(
92+
'PORT needs to be set in the config '
93+
'when using a private registry')
94+
8895
def set_tags(self, previous_config):
8996
"""verify the tags exist on any nodes as labels"""
9097
if not self.tags:

rootfs/api/tests/test_build.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,12 +361,34 @@ def test_build_image_in_registry_with_auth(self, mock_requests):
361361
response = self.client.post(url, {'image': image})
362362
self.assertEqual(response.status_code, 201, response.data)
363363

364+
# add the required PORT information
365+
url = '/v2/apps/test/config'
366+
body = {'values': json.dumps({'PORT': '80'})}
367+
response = self.client.post(url, body)
368+
self.assertEqual(response.status_code, 201, response.data)
369+
364370
# set some registry information
365371
url = '/v2/apps/test/config'
366372
body = {'registry': json.dumps({'username': 'bob', 'password': 'zoomzoom'})}
367373
response = self.client.post(url, body)
368374
self.assertEqual(response.status_code, 201, response.data)
369375

376+
def test_build_image_in_registry_with_auth_no_port(self, mock_requests):
377+
"""add authentication to the build but with no PORT config"""
378+
self.client.post('/v2/apps', {'id': 'test'})
379+
380+
# post an image as a build using registry hostname
381+
url = "/v2/apps/test/builds"
382+
image = 'autotest/example'
383+
response = self.client.post(url, {'image': image})
384+
self.assertEqual(response.status_code, 201, response.data)
385+
386+
# set some registry information
387+
url = '/v2/apps/test/config'
388+
body = {'registry': json.dumps({'username': 'bob', 'password': 'zoomzoom'})}
389+
response = self.client.post(url, body)
390+
self.assertEqual(response.status_code, 400, response.data)
391+
370392
def test_release_create_failure(self, mock_requests):
371393
"""
372394
Cause an Exception in app.deploy to cause a release.delete in build.create

rootfs/api/tests/test_config.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,18 @@ def test_registry(self, mock_requests):
624624
self.assertIn('registry', response.data)
625625
self.assertEqual(response.data['registry'], {})
626626

627+
# set some registry information without PORT
628+
body = {'registry': json.dumps({'username': 'bob'})}
629+
response = self.client.post(url, body)
630+
self.assertEqual(response.status_code, 400, response.data)
631+
registry1 = response.data
632+
633+
# set required PORT
634+
body = {'values': json.dumps({'PORT': '80'})}
635+
response = self.client.post(url, body)
636+
self.assertEqual(response.status_code, 201, response.data)
637+
registry1 = response.data
638+
627639
# set some registry information
628640
body = {'registry': json.dumps({'username': 'bob'})}
629641
response = self.client.post(url, body)
@@ -693,7 +705,13 @@ def test_registry_deploy(self, mock_requests):
693705
self.assertEqual(response.status_code, 201, response.data)
694706
app_id = response.data['id']
695707

696-
# Set healthcheck URL to get defaults set
708+
# Set mandatory PORT
709+
resp = self.client.post(
710+
'/v2/apps/{app_id}/config'.format(**locals()),
711+
{'values': json.dumps({'PORT': '4999'})}
712+
)
713+
714+
# Set registry information
697715
body = {'registry': json.dumps({
698716
'username': 'bob',
699717
'password': 's3cur3pw1'

0 commit comments

Comments
 (0)