Skip to content

Commit

Permalink
feat(titus): manually sort docker registry tags on manual trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaslin committed Apr 7, 2017
1 parent 4e1c052 commit 5e39e13
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 20 deletions.
6 changes: 6 additions & 0 deletions app/scripts/modules/core/image/image.reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ export interface IFindImageParams {
count?: number;
}

export interface IFindTagsParams {
provider: string;
account: string;
repository: string;
}

// marker interface
export interface IImage {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</ui-select-match>
<ui-select-choices repeat="tag in vm.tags | filter: $select.search"
refresh-delay="0"
refresh="vm.searchTags($select.search)">
>
<span ng-bind-html="tag | highlight: $select.search"></span>
</ui-select-choices>
</ui-select>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

import {Observable, Subject} from 'rxjs';
import _ from 'lodash';

import {DOCKER_IMAGE_READER} from 'docker/image/docker.image.reader.service';

Expand Down Expand Up @@ -34,7 +33,7 @@ module.exports = angular
};

let tagLoadSuccess = (tags) => {
this.tags = tags.map((val) => val.tag ).sort();
this.tags = tags;
if (this.tags.length) {
let defaultSelection = this.tags[0];
this.viewState.selectedTag = defaultSelection;
Expand All @@ -57,13 +56,13 @@ module.exports = angular
this.searchTags();
};

let handleQuery = (q) => {
let handleQuery = () => {
return Observable.fromPromise(
dockerImageReader.findImages({
provider: 'dockerRegistry',
account: this.command.trigger.account,
q: ( this.command.trigger.organization ? this.command.trigger.organization + '/' : '' ) + q,
count: 50 }));
dockerImageReader.findTags({
provider: 'dockerRegistry',
account: this.command.trigger.account,
repository: this.command.trigger.repository,
}));
};

this.updateSelectedTag = (item) => {
Expand All @@ -79,16 +78,7 @@ module.exports = angular

this.searchTags = (query = '') => {
this.tags = [`<span>Finding tags${query && ` matching ${query}`}...</span>`];
queryStream.next(formatQuery(query));
};

let formatQuery = (query) => {
let repository = _.get(this, 'command.trigger.repository');
if (repository) {
return `${this.command.trigger.repository.split('/').pop()}:${query}`;
} else {
return query;
}
queryStream.next();
};

$scope.$watch(() => this.command.trigger, initialize);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {module} from 'angular';
import {API_SERVICE, Api} from 'core/api/api.service';
import {RETRY_SERVICE, RetryService} from 'core/retry/retry.service';
import {IImageReader, IImage, IFindImageParams} from 'core/image/image.reader';
import {IImageReader, IImage, IFindImageParams, IFindTagsParams} from 'core/image/image.reader';

export interface IDockerImage extends IImage {
account: string;
Expand Down Expand Up @@ -32,6 +32,13 @@ export class DockerImageReaderService implements IImageReader {
.then((results: IDockerImage[]) => results)
.catch((): IDockerImage[] => []);
}

public findTags(params: IFindTagsParams): ng.IPromise<string[]> {
return this.retryService.buildRetrySequence<String[]>(() => this.API.all('images/tags')
.getList(params), (results: string[]) => (results.length > 0), 10, 1000)
.then((results: string[]) => results)
.catch((): string[] => []);
}
}

export const DOCKER_IMAGE_READER = 'spinnaker.docker.image.reader';
Expand Down

0 comments on commit 5e39e13

Please sign in to comment.