File tree Expand file tree Collapse file tree 3 files changed +61
-1
lines changed
interface/cli/commands/image Expand file tree Collapse file tree 3 files changed +61
-1
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 untag = new Command ( {
9
+ root : true ,
10
+ command : 'untag <id> [tags..]' ,
11
+ category : 'Images' ,
12
+ description : 'Untag an image' ,
13
+ webDocs : {
14
+ category : 'Images' ,
15
+ title : 'Untag Image' ,
16
+ } ,
17
+ builder : ( yargs ) => {
18
+ yargs
19
+ . positional ( 'id' , {
20
+ description : 'Docker image id' ,
21
+ } )
22
+ . positional ( 'names' , {
23
+ description : 'Tag names' ,
24
+ } )
25
+ . example ( 'codefresh untag 2dfacdaad466 1.0.0' , "Remove tag '1.0.0' from image '2dfacdaad466'" )
26
+ . example ( 'codefresh untag 2dfacdaad466 1.0.0 my-tag' , "Remove tags '1.0.0' and 'my-tag' from image'2dfacdaad466'" ) ;
27
+
28
+ return yargs ;
29
+ } ,
30
+ handler : async ( argv ) => {
31
+ const imageId = argv . id ;
32
+ const tags = argv . tags ;
33
+ for ( let i = 0 ; i < tags . length ; i += 1 ) {
34
+ const tag = tags [ i ] ;
35
+ await image . untagImage ( {
36
+ imageId,
37
+ tag,
38
+ } ) ;
39
+ console . log ( `Tag: ${ tag } was successfully removed from image: ${ imageId } ` ) ;
40
+ }
41
+ } ,
42
+ } ) ;
43
+
44
+ module . exports = untag ;
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ const _extractFieldsForImageEntity = (image, tag) => {
13
13
size : filesize ( image . size ) ,
14
14
_id : image . _id ,
15
15
annotations : _ . get ( image , 'metadata' , { } ) ,
16
+ tagId : tag . _id ,
16
17
} ;
17
18
newImage . image_id = image . internalImageId ? image . internalImageId . substring ( 0 , 12 ) : '\b' ;
18
19
if ( _ . isEqual ( tag , '<none>' ) ) {
@@ -147,10 +148,25 @@ const addImageTag = async (options) => {
147
148
return sendHttpRequest ( RequestOptions ) ;
148
149
} ;
149
150
151
+ const untagImage = async ( options ) => {
152
+ const images = await getImageById ( { imageId : options . imageId } ) ;
153
+ const imageId = images [ 0 ] . info . _id ;
154
+ const image = _ . find ( images , currimage => _ . isEqual ( currimage . info . tag , options . tag ) ) ;
155
+ if ( image ) {
156
+ const RequestOptions = {
157
+ url : `/api/images/${ encodeURIComponent ( imageId ) } /tag/${ image . info . tagId } ` ,
158
+ method : 'DELETE' ,
159
+ } ;
160
+ return sendHttpRequest ( RequestOptions ) ;
161
+ }
162
+ throw new CFError ( `Error from server (NotFound): Tag ${ options . tag } not found` ) ;
163
+ } ;
164
+
150
165
module . exports = {
151
166
annotateImage,
152
167
getDockerImageId,
153
168
getAll,
154
169
getImageById,
155
170
addImageTag,
171
+ untagImage,
156
172
} ;
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " codefresh" ,
3
- "version" : " 0.8.21 " ,
3
+ "version" : " 0.8.22 " ,
4
4
"description" : " Codefresh command line utility" ,
5
5
"main" : " index.js" ,
6
6
"preferGlobal" : true ,
You can’t perform that action at this time.
0 commit comments