Skip to content

Commit 95f80e5

Browse files
do not filter by specific registries, let api do it (#420)
1 parent 4f3c17b commit 95f80e5

File tree

8 files changed

+38
-47
lines changed

8 files changed

+38
-47
lines changed

lib/interface/cli/commands/image/annotate.cmd.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
const Command = require('../../Command');
2-
const { prepareKeyValueFromCLIEnvOption } = require('../../helpers/general');
32
const { parseFamiliarName } = require('@codefresh-io/docker-reference');
43
const annotateRoot = require('../root/annotate.cmd');
54
const CFError = require('cf-errors');
@@ -33,7 +32,6 @@ const command = new Command({
3332
handler: async (argv) => {
3433
let dockerImageId = argv.id;
3534
const useFullName = dockerImageId.includes(':');
36-
const annotations = prepareKeyValueFromCLIEnvOption(argv.label);
3735

3836
if (useFullName) {
3937
const { repository, tag } = parseFamiliarName(dockerImageId);
@@ -54,7 +52,6 @@ const command = new Command({
5452
dockerImageId = results[0].internalImageId;
5553
}
5654

57-
await sdk.images.upsertMetadata({ dockerImageId }, annotations);
5855
await annotationLogic.createAnnotations({ entityId: dockerImageId, entityType: 'image', labels: argv.label });
5956
console.log('Annotations added successfully');
6057
},

lib/interface/cli/commands/image/get.cmd.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ const command = new Command({
7272
.example('codefresh get images -l key1=value1', "Get all images that are annotated with 'value1' for 'key1'");
7373
},
7474
handler: async (argv) => {
75-
const imageIds = argv.id;
75+
const imageIds = _.uniq(argv.id);
7676
const labels = prepareKeyValueFromCLIEnvOption(argv.label);
7777
const tags = argv.tag;
7878
const sha = argv.sha;
@@ -82,18 +82,24 @@ const command = new Command({
8282
const allRegistries = argv.all;
8383
const offset = (argv.page - 1) * limit;
8484
const imageName = argv['image-name'];
85-
let filterRegistries;
85+
86+
let imageRepo;
8687
if (!allRegistries) {
87-
filterRegistries = DEFAULTS.CODEFRESH_REGISTRIES;
88+
imageRepo = DEFAULTS.INTERNAL_REGISTRY_PREFIX;
8889
}
8990

9091
let images = [];
9192
// TODO:need to decide for one way for error handeling
9293
if (!_.isEmpty(imageIds)) {
93-
images = await Promise.map(imageIds, id => sdk.images.get({
94-
id,
95-
allRegistries,
94+
images = await Promise.map(imageIds, id => sdk.images.list({
95+
filter: { internalImageId: id },
96+
limit: 100,
97+
select: IMAGE_FIELDS_TO_SELECT,
9698
}));
99+
images = _.chain(images)
100+
.map('docs')
101+
.flatten()
102+
.value();
97103
} else {
98104
images = await sdk.images.list({
99105
metadata: labels,
@@ -105,10 +111,11 @@ const command = new Command({
105111
imageDisplayNameRegex: imageName,
106112
offset,
107113
select: IMAGE_FIELDS_TO_SELECT,
114+
...(imageRepo && { imageRepo }),
108115
});
109116
images = images.docs;
110117
}
111-
Output.print(extractImages(images, filterRegistries));
118+
Output.print(extractImages(images));
112119
},
113120
});
114121

lib/interface/cli/commands/image/image.sdk.spec.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,14 @@ describe('image commands', () => {
9898
it('should handle annotating given docker image id', async () => {
9999
const argv = { id: 'some id', label: ['test=test'] };
100100
await annotateCmd.handler(argv);
101-
await verifyResponsesReturned([DEFAULT_RESPONSE, DEFAULT_RESPONSE]); // eslint-disable-line
101+
await verifyResponsesReturned([DEFAULT_RESPONSE]); // eslint-disable-line
102102
});
103103

104104
it('should handle annotating given full image name', async () => {
105105
const argv = { id: 'repo/name:tag', label: ['test=test'] };
106106
const responses = [
107107
{ statusCode: 200, body: [{ internalImageId: 'some id' }] },
108108
DEFAULT_RESPONSE,
109-
DEFAULT_RESPONSE,
110109
];
111110
request.__queueResponses(responses);
112111
await annotateCmd.handler(argv);

lib/interface/cli/defaults.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const DEFAULTS = {
88
GET_LIMIT_RESULTS: 25,
99
GET_ALL_PIPELINES_LIMIT: 10000,
1010
GET_PAGINATED_PAGE: 1,
11-
CODEFRESH_REGISTRIES: ['r.cfcr.io', '192.168.99.100:5000'],
11+
INTERNAL_REGISTRY_PREFIX: 'CFCR',
1212
WATCH_INTERVAL_MS: 3000,
1313
MAX_CONSECUTIVE_ERRORS_LIMIT: 10,
1414
CODEFRESH_PATH: path.resolve(homedir(), '.Codefresh'),

lib/interface/cli/helpers/helpers.unit.spec.js

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -61,26 +61,6 @@ describe('helpers unit tests', () => {
6161
]);
6262
});
6363

64-
it('should filter tags by registries', () => {
65-
expect(extractImages([
66-
{
67-
tags: [
68-
{ tag: 'banana', registry: 'filtered' },
69-
{ tag: 'beer', registry: 'r.cfcr.io' },
70-
],
71-
},
72-
{
73-
tags: [
74-
{ tag: 'banana', registry: 'r.cfcr.io' },
75-
{ tag: 'beer', registry: 'filtered' },
76-
],
77-
},
78-
], ['r.cfcr.io'])).toEqual([
79-
{ tag: 'beer' },
80-
{ tag: 'banana' },
81-
]);
82-
});
83-
8464
it('should filter images tagged as "volume"', () => {
8565
expect(extractImages([
8666
{

lib/interface/cli/helpers/image.js

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ class ImagesHelper {
1414

1515
extractFieldsForImageEntity(image, tag){
1616
const newImage = {
17-
name: image.imageDisplayName,
18-
size: filesize(image.size),
17+
name: image.imageDisplayName || image.imageName,
18+
size: image.size && filesize(image.size),
1919
sha: image.sha,
2020
annotations: _.get(image, 'metadata', {}),
2121
tagId: tag._id,
@@ -33,30 +33,24 @@ class ImagesHelper {
3333
}
3434

3535

36-
extractImages(images, filterRegistries) {
36+
extractImages(images) {
3737
if (!_.isArray(images)) {
3838
images = [images]; // eslint-disable-line no-param-reassign
3939
}
4040
return _.chain(images)
4141
.map((image) => {
4242
const res = [];
43-
let addedCfCrTag = false;
43+
let volumeImage = false;
4444
_.forEach(image.tags, (tag) => {
4545
if (_.isEqual(tag.tag, 'volume')) {
46-
addedCfCrTag = true;
46+
volumeImage = true;
4747
return;
4848
}
49-
// in case we are filtering by registries, ignore the image if it is not from the registires list
50-
if (filterRegistries && !_.includes(filterRegistries, tag.registry)) {
51-
return;
52-
}
53-
if (_.includes(DEFAULTS.CODEFRESH_REGISTRIES, tag.registry)) {
54-
addedCfCrTag = true;
55-
}
49+
5650
const data = this.extractFieldsForImageEntity(image, tag);
5751
res.push(new Image(data));
5852
});
59-
if (_.isEmpty(image.tags) || !addedCfCrTag) {
53+
if (_.isEmpty(image.tags) && !volumeImage) {
6054
const data = this.extractFieldsForImageEntity(image, NONE_TAG);
6155
res.push(new Image(data));
6256
}

openapi.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4862,6 +4862,20 @@
48624862
"schema": {
48634863
"type": "string"
48644864
}
4865+
},
4866+
{
4867+
"in": "query",
4868+
"name": "imageRepo",
4869+
"schema": {
4870+
"type": "string"
4871+
}
4872+
},
4873+
{
4874+
"in": "query",
4875+
"name": "filter",
4876+
"schema": {
4877+
"type": "string"
4878+
}
48654879
}
48664880
],
48674881
"summary": "List",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codefresh",
3-
"version": "0.45.0",
3+
"version": "0.5.0",
44
"description": "Codefresh command line utility",
55
"main": "index.js",
66
"preferGlobal": true,

0 commit comments

Comments
 (0)