File tree Expand file tree Collapse file tree 2 files changed +48
-0
lines changed
interface/cli/commands/image Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Original file line number Diff line number Diff line change
1
+ const debug = require ( 'debug' ) ( 'codefresh:cli:logs' ) ;
2
+ const Command = require ( '../../Command' ) ;
3
+ const _ = require ( 'lodash' ) ;
4
+ const CFError = require ( 'cf-errors' ) ;
5
+ const { image } = require ( '../../../../logic' ) . api ;
6
+
7
+
8
+ const tag = new Command ( {
9
+ root : true ,
10
+ command : 'tag <id>' ,
11
+ description : 'Add an image tag' ,
12
+ builder : ( yargs ) => {
13
+ yargs
14
+ . option ( 'tag' , {
15
+ describe : 'image tags' ,
16
+ type : 'array' ,
17
+ require : true ,
18
+ } ) ;
19
+
20
+ return yargs ;
21
+ } ,
22
+ handler : async ( argv ) => {
23
+ const imageId = argv . id ;
24
+ const tags = _ . isArray ( argv . tag ) ? argv . tag : [ argv . tag ] ;
25
+ for ( let i = 0 ; i < tags . length ; i += 1 ) {
26
+ const tag = tags [ i ] ;
27
+ await image . addImageTag ( {
28
+ imageId,
29
+ tag,
30
+ } ) ;
31
+ console . log ( `tag: ${ tag } successfully added to image ${ imageId } ` ) ;
32
+ }
33
+ } ,
34
+ } ) ;
35
+
36
+ module . exports = tag ;
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ const _extractFieldsForImageEntity = (image, tag) => {
11
11
const newImage = {
12
12
name : image . imageDisplayName ,
13
13
size : filesize ( image . size ) ,
14
+ _id : image . _id ,
14
15
} ;
15
16
newImage . image_id = image . internalImageId ? image . internalImageId . substring ( 0 , 12 ) : '\b' ;
16
17
if ( _ . isEqual ( tag , '<none>' ) ) {
@@ -134,9 +135,20 @@ const annotateImage = async (dockerImageId, annotations) => {
134
135
return sendHttpRequest ( options ) ;
135
136
} ;
136
137
138
+ const addImageTag = async ( options ) => {
139
+ const image = await getImageById ( options . imageId ) ;
140
+ const imageId = image [ 0 ] . info . _id ;
141
+ const RequestOptions = {
142
+ url : `/api/images/${ encodeURIComponent ( imageId ) } /tag/${ options . tag } ` ,
143
+ method : 'POST' ,
144
+ } ;
145
+ return sendHttpRequest ( RequestOptions ) ;
146
+ } ;
147
+
137
148
module . exports = {
138
149
annotateImage,
139
150
getDockerImageId,
140
151
getAll,
141
152
getImageById,
153
+ addImageTag,
142
154
} ;
You can’t perform that action at this time.
0 commit comments