Skip to content

Commit 5d1cda0

Browse files
committed
Merge pull request #92 from vincent99/registry
Private Registry support
2 parents ebf5274 + 1b05283 commit 5d1cda0

41 files changed

Lines changed: 898 additions & 16 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app/pods/authenticated/route.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,17 @@ export default Ember.Route.extend(AuthenticatedRouteMixin, {
215215
mounts.pushObject(mount);
216216
}
217217
}
218+
},
219+
220+
registryCredentialChanged: function(change) {
221+
// @TODO Change to registryId when the backend changes
222+
var key = 'registryId';
223+
if ( Object.keys(change.data.resource).indexOf(key) === -1 )
224+
{
225+
key = 'storagePoolId';
226+
}
227+
228+
this._includeChanged('registry', 'credentials', key, change.data.resource);
218229
}
219230
},
220231

@@ -335,10 +346,22 @@ export default Ember.Route.extend(AuthenticatedRouteMixin, {
335346
// IDs the resource should be on
336347
var expectedIds = [];
337348
var expected = changed.get(expectedProperty)||[];
349+
if ( !Ember.isArray(expected) )
350+
{
351+
expected = [expected];
352+
}
353+
338354
if ( changed.get('state') !== 'purged' )
339355
{
340356
expectedIds = expected.map(function(item) {
341-
return item.get('id');
357+
if ( typeof item === 'object' )
358+
{
359+
return item.get('id');
360+
}
361+
else
362+
{
363+
return item;
364+
}
342365
});
343366
}
344367

app/pods/components/page-nav/template.hbs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
<label>Volumes</label>
1616
{{/link-to}}
1717

18+
{{#link-to "registries" title="API" classNames="nav-api"}}
19+
<i class="ss-bookmark fa-lg"></i>
20+
<label>Registries</label>
21+
{{/link-to}}
22+
1823
{{#link-to "apikeys" title="API" classNames="nav-api"}}
1924
<i class="fa fa-code fa-lg"></i>
2025
<label>API</label>

app/pods/container/model.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ var Container = Cattle.TransitioningResource.extend({
1010
// Container-specific
1111
type: 'container',
1212
imageUuid: null,
13+
registryCredentialId: null,
1314
command: null,
1415
commandArgs: null,
1516
environment: null,

app/pods/container/template.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
{{transitioningMessage}}
1818
</div>
1919
<div class="instance-actions">
20-
{{resource-actions model=this isDetail=true choices=availableActions colors=false}}
20+
{{resource-actions model=this choices=availableActions}}
2121
</div>
2222
</div>
2323
</div>

app/pods/containers/new/controller.js

Lines changed: 84 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,35 @@ export default Ember.ObjectController.extend(NewOrEditContainer, {
7878
removeDevice: function(obj) {
7979
this.get('devicesArray').removeObject(obj);
8080
},
81+
82+
chooseRegistry: function(registry) {
83+
var found = false;
84+
this.get('registryChoices').forEach((choice) => {
85+
var prefix = choice.get('serverAddress')+':';
86+
87+
if ( registry && choice.get('id') === registry.get('id') )
88+
{
89+
found = true;
90+
choice.set('active', true);
91+
this.set('displayPrefix', prefix);
92+
this.set('selectedRegistry', choice);
93+
this.set('credentialChoices', choice.get('credentials'));
94+
}
95+
else
96+
{
97+
choice.set('active', false);
98+
}
99+
});
100+
101+
if (!found)
102+
{
103+
this.set('displayPrefix', 'docker:');
104+
this.set('selectedRegistry', null);
105+
this.set('credentialChoices', null);
106+
}
107+
108+
this.set('registryCredentialId', this.get('credentialChoices.firstObject.id'));
109+
},
81110
},
82111

83112
validate: function() {
@@ -213,21 +242,70 @@ export default Ember.ObjectController.extend(NewOrEditContainer, {
213242
}.observes('linksArray.@each.{linkName,targetInstanceId}'),
214243

215244
// Image
245+
registryChoices: null,
246+
displayPrefix: 'docker:',
216247
userImageUuid: 'ubuntu:14.04.1',
248+
credentialChoices: null,
249+
showCredentials: Ember.computed.gt('credentialChoices.length',1),
217250
userImageUuidDidChange: function() {
218-
var image = this.get('userImageUuid');
219-
if ( image.indexOf('docker:') === 0 )
251+
var input = this.get('userImageUuid');
252+
var choices = this.get('registryChoices')||[];
253+
254+
// Look for a private registry with the matching prefix
255+
var prefix, choice, found=false;
256+
for ( var i = 0 ; i < choices.get('length') ; i++ )
220257
{
221-
this.set('userImageUuid', image.replace(/^docker:/,''));
258+
choice = choices.objectAt(i);
259+
prefix = choice.get('serverAddress')+':';
260+
choice.set('selected', false);
261+
if ( input.indexOf(prefix) === 0 )
262+
{
263+
this.set('userImageUuid', input.substr(prefix.length));
264+
this.send('chooseRegistry', choice);
265+
}
222266
}
223-
else
267+
268+
if ( found )
224269
{
225-
image = 'docker:' + image;
270+
return;
226271
}
227272

228-
this.set('imageUuid', image);
273+
prefix = 'docker:';
274+
if ( input.indexOf(prefix) === 0 )
275+
{
276+
this.set('userImageUuid', input.substr(prefix.length));
277+
this.send('chooseRegistry', null);
278+
}
229279
}.observes('userImageUuid'),
230280

281+
updateImageUuid: function() {
282+
var uuid = 'docker:';
283+
var registry = this.get('selectedRegistry.serverAddress');
284+
if ( registry )
285+
{
286+
uuid += registry + '/';
287+
}
288+
uuid += this.get('userImageUuid');
289+
290+
this.set('imageUuid', uuid);
291+
}.observes('selectedRegistry.serverAddress','userImageUuid'),
292+
293+
credentialChoicesChanged: function() {
294+
var found = false;
295+
var id = this.get('registryCredentialId');
296+
(this.get('credentialChoices')||[]).forEach((choice) => {
297+
if ( choice.get('id') === id )
298+
{
299+
found = true;
300+
}
301+
});
302+
303+
if ( !found )
304+
{
305+
this.set('registryCredentialId',null);
306+
}
307+
}.observes('credentialChoices.@each.id','registryCredentialId'),
308+
231309
// Volumes
232310
volumesArray: null,
233311
initVolumes: function() {

app/pods/containers/new/route.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import Ember from 'ember';
22

33
export default Ember.Route.extend({
4+
networkChoices: null,
5+
registryChoices: null,
6+
47
activate: function() {
58
this.send('setPageLayout', {label: 'Back', backPrevious: true});
69
},
@@ -16,13 +19,21 @@ export default Ember.Route.extend({
1619

1720
var dependencies = [
1821
this.get('store').find('network'),
19-
this.get('store').find('host')
22+
this.get('store').find('host'),
23+
this.get('store').find('registry'),
2024
];
2125

2226
return Ember.RSVP.all(dependencies, 'Load container dependencies').then(function(results) {
23-
var networks = results[0].sortBy('name','id');
27+
var networks = results[0].sortBy('name','id').filter((network) => {
28+
return network.get('state') === 'active';
29+
});
30+
31+
var registries = results[2].sortBy('serverAddress').filter((registry) => {
32+
return registry.get('state') === 'active';
33+
});
2434

2535
self.set('networkChoices', networks);
36+
self.set('registryChoices', registries);
2637

2738
var networkId = self.get('lastNetworkId');
2839
if ( !networkId )
@@ -52,6 +63,7 @@ export default Ember.Route.extend({
5263
setupController: function(controller, model) {
5364
model.set('requestedHostId', controller.get('hostId'));
5465
controller.set('networkChoices', this.get('networkChoices'));
66+
controller.set('registryChoices', this.get('registryChoices'));
5567
controller.set('originalModel', null);
5668
controller.set('model', model);
5769
controller.initFields();

app/pods/containers/new/template.hbs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,47 @@
5151

5252
<div class="form-group">
5353
<div class="input-group">
54-
<span class="input-group-addon">docker:</span>
54+
<div class="input-group-btn">
55+
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false"><span class="caret"></span> {{displayPrefix}}</button>
56+
<ul class="dropdown-menu" role="menu">
57+
<li {{action "chooseRegistry" null}}><a>Docker</a></li>
58+
{{#if registryChoices}}
59+
<li class="divider"></li>
60+
{{#each choice in registryChoices itemController="registry"}}
61+
<li {{action "chooseRegistry" choice}} {{bind-attr class="choice.active:active"}}>
62+
<a>{{choice.displayName}}</a>
63+
</li>
64+
{{/each}}
65+
{{/if}}
66+
</ul>
67+
</div>
5568
{{input id="userImageUuid" disabled=isRancher type="text" class="form-control" value=userImageUuid placeholder="e.g. stackbrew/ubuntu:14.04"}}
5669
</div>
5770
</div>
5871
</div>
5972
</div>
6073

74+
{{#if showCredentials}}
75+
<div class="row">
76+
<div class="col-sm-12 col-md-2 form-label">
77+
<label for="registryCredentialId" class="form-control-static">Credential</label>
78+
</div>
79+
<div class="col-sm-12 col-md-8">
80+
<div class="form-group">
81+
{{view "select"
82+
class="form-control"
83+
id="registryCredentialId"
84+
content=credentialChoices
85+
optionLabelPath="content.publicValue"
86+
optionValuePath="content.id"
87+
value=registryCredentialId
88+
prompt="None"
89+
}}
90+
</div>
91+
</div>
92+
</div>
93+
{{/if}}
94+
6195
<div class="row">
6296
<div class="col-xs-10 col-xs-offset-1">
6397
<hr/>

app/pods/containers/new/view.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function addAction(action, selector) {
1111

1212
export default Ember.View.extend({
1313
actions: {
14-
addEnvironment: addAction('addEnvironment', '.environment-nam'),
14+
addEnvironment: addAction('addEnvironment', '.environment-name'),
1515
addPort: addAction('addPort', '.port-public'),
1616
addLink: addAction('addLink', '.link-container'),
1717
addVolume: addAction('addVolume', '.volume-path'),

app/pods/hosts/setup/route.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ export default OverlayRoute.extend({
66
return this.get('store').find('setting', C.SETTING_API_HOST);
77
},
88

9+
setupController: function(controller, model) {
10+
controller.set('model', model);
11+
var value = model.get('value');
12+
controller.set('customValue', value);
13+
},
14+
915
renderTemplate: function() {
1016
this.render({into: 'application', outlet: 'overlay'});
1117
},

app/pods/hosts/setup/template.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
<code class="form-control-static">{{thisPage}}</code>
1515
</div>
1616

17-
<div>
17+
<div style="margin-top: 10px;">
1818
<label>{{radio-button selection=customRadio value="yes"}} Something else:</label>
19-
{{input type="text" class="form-control" value=customValue placeholder="e.g. rancher.mydomain.com"}}
19+
{{input type="text" class="form-control" value=customValue placeholder="e.g. rancher.mydomain.com" style="max-width: 300px; display: inline-block;"}}
2020
</div>
2121

2222
{{#unless looksPublic}}

0 commit comments

Comments
 (0)