Skip to content

Commit 72b7367

Browse files
committed
Merge pull request #346 from helgi/slug_url
feat(builder): add the ability to optionally pass in slug_url in build hook
2 parents 9663e35 + 015e400 commit 72b7367

7 files changed

Lines changed: 62 additions & 13 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# -*- coding: utf-8 -*-
2+
# Generated by Django 1.9.1 on 2016-02-08 21:56
3+
from __future__ import unicode_literals
4+
5+
from django.db import migrations, models
6+
7+
8+
class Migration(migrations.Migration):
9+
10+
dependencies = [
11+
('api', '0004_auto_20160124_2134'),
12+
]
13+
14+
operations = [
15+
migrations.AlterField(
16+
model_name='build',
17+
name='image',
18+
field=models.TextField(),
19+
),
20+
]

rootfs/api/models/app.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,16 +149,19 @@ def scale(self, user, structure): # noqa
149149
"""Scale containers up or down to match requested structure."""
150150
if self.release_set.latest().build is None:
151151
raise EnvironmentError('No build associated with this release')
152+
152153
requested_structure = structure.copy()
153154
release = self.release_set.latest()
154155
# test for available process types
155156
available_process_types = release.build.procfile or {}
156157
for container_type in requested_structure:
157158
if container_type == 'cmd':
158159
continue # allow docker cmd types in case we don't have the image source
160+
159161
if container_type not in available_process_types:
160162
raise EnvironmentError(
161163
'Container type {} does not exist in application'.format(container_type))
164+
162165
msg = '{} scaled containers '.format(user.username) + ' '.join(
163166
"{}={}".format(k, v) for k, v in list(requested_structure.items()))
164167
log_event(self, msg)
@@ -177,12 +180,14 @@ def scale(self, user, structure): # noqa
177180
diff = requested - len(containers)
178181
if diff == 0:
179182
continue
183+
180184
changed = True
181185
scale_types[container_type] = requested
182186
while diff < 0:
183187
c = containers.pop()
184188
to_remove.append(c)
185189
diff += 1
190+
186191
while diff > 0:
187192
# create a database record
188193
c = Container.objects.create(owner=self.owner,
@@ -200,8 +205,10 @@ def scale(self, user, structure): # noqa
200205
else:
201206
if to_add:
202207
self._start_containers(to_add)
208+
203209
if to_remove:
204210
self._destroy_containers(to_remove)
211+
205212
# save new structure to the database
206213
vals = self.container_set.exclude(type='run').values(
207214
'type').annotate(Count('pk')).order_by()

rootfs/api/models/build.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Build(UuidAuditedModel):
1212

1313
owner = models.ForeignKey(settings.AUTH_USER_MODEL)
1414
app = models.ForeignKey('App')
15-
image = models.CharField(max_length=256)
15+
image = models.TextField()
1616

1717
# optional fields populated by builder
1818
sha = models.CharField(max_length=40, blank=True)

rootfs/api/models/release.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,15 @@ def __str__(self):
3232

3333
@property
3434
def image(self):
35-
if not self.build.dockerfile and not self.build.sha:
36-
return '{}:v{}'.format(self.app.id, str(self.version))
35+
if not self.build.dockerfile:
36+
# Deis Pull
37+
if not self.build.sha:
38+
return '{}:v{}'.format(self.app.id, str(self.version))
39+
else:
40+
# Build Pack
41+
return self.build.image
42+
43+
# DockerFile
3744
return '{}:git-{}'.format(self.app.id, str(self.build.sha))
3845

3946
def new(self, user, config, build, summary=None, source_version='latest'):

rootfs/api/tests/test_hooks.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,30 @@ def test_build_hook(self):
192192
self.assertIn('release', response.data)
193193
self.assertIn('version', response.data['release'])
194194

195+
@mock.patch('requests.post', mock_status_ok)
196+
def test_build_hook_slug_url(self):
197+
"""Test creating a slug_url build via an API Hook"""
198+
url = '/v2/apps'
199+
response = self.client.post(url, HTTP_AUTHORIZATION='token {}'.format(self.token))
200+
self.assertEqual(response.status_code, 201)
201+
app_id = response.data['id']
202+
build = {'username': 'autotest', 'app': app_id}
203+
url = '/v2/hooks/builds'.format(**locals())
204+
body = {'receive_user': 'autotest',
205+
'receive_repo': app_id,
206+
'image': 'http://example.com/slugs/foo-12345354.tar.gz'}
207+
208+
# post the build without an auth token
209+
response = self.client.post(url, json.dumps(body), content_type='application/json')
210+
self.assertEqual(response.status_code, 401)
211+
212+
# post the build with the builder auth key
213+
response = self.client.post(url, json.dumps(body), content_type='application/json',
214+
HTTP_X_DEIS_BUILDER_AUTH=settings.BUILDER_KEY)
215+
self.assertEqual(response.status_code, 200)
216+
self.assertIn('release', response.data)
217+
self.assertIn('version', response.data['release'])
218+
195219
def test_build_hook_procfile(self):
196220
"""Test creating a Procfile build via an API Hook"""
197221
url = '/v2/apps'

rootfs/deis/settings.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -273,12 +273,6 @@
273273
REGISTRY_PORT = os.environ.get('DEIS_REGISTRY_SERVICE_PORT', 5000)
274274
REGISTRY_URL = '{}:{}'.format(REGISTRY_HOST, REGISTRY_PORT)
275275

276-
BUILDER_HOST = os.environ.get('DEIS_BUILDER_SERVICE_HOST', '127.0.0.1')
277-
MINIO_HOST = os.environ.get('DEIS_MINIO_SERVICE_HOST', BUILDER_HOST)
278-
MINIO_PORT = os.environ.get('DEIS_MINIO_SERVICE_PORT', 3000)
279-
S3EP_HOST = os.environ.get('DEIS_OUTSIDE_STORAGE_HOST', MINIO_HOST)
280-
S3EP_PORT = os.environ.get('DEIS_OUTSIDE_STORAGE_PORT', MINIO_PORT)
281-
S3EP = '{}:{}'.format(S3EP_HOST, S3EP_PORT)
282276
# logger settings
283277
LOGGER_HOST = os.environ.get('DEIS_LOGGER_SERVICE_HOST', '127.0.0.1')
284278
LOGGER_PORT = os.environ.get('DEIS_LOGGER_PORT_8088_TCP_PORT', 8088)

rootfs/scheduler/__init__.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -605,11 +605,8 @@ def _create_rc(self, name, image, command, **kwargs): # noqa
605605
TEMPLATE = RCD_TEMPLATE
606606

607607
# Check if it is a slug builder image.
608-
# Example format: golden-earrings:git-5450cbcdaaf9afe6fadd219c94ac9c449bd62413s
609608
if kwargs.get('build_type') == "buildpack":
610-
imgurl = 'http://{}/git/home/{}/push/slug.tgz'.format(
611-
settings.S3EP,
612-
image)
609+
imgurl = image
613610
TEMPLATE = RCB_TEMPLATE
614611

615612
l = {

0 commit comments

Comments
 (0)