Skip to content

Commit 8c5ccba

Browse files
authored
Revert "feat(ecr): support retagging in push task (#570)" (#573)
* Revert "feat(ecr): support retagging in push task (#570)" This reverts commit 7c033fc due to #572 * update changelog
1 parent 5a215a4 commit 8c5ccba

File tree

6 files changed

+37
-109
lines changed

6 files changed

+37
-109
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Removal",
3+
"description": "ECR: Remove image retagging option due to breaking change."
4+
}

src/tasks/ECRPushImage/TaskOperations.ts

Lines changed: 13 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import tl = require('azure-pipelines-task-lib/task')
88
import { DockerHandler } from 'lib/dockerUtils'
99
import { constructTaggedImageName, getEcrAuthorizationData, loginToRegistry } from 'lib/ecrUtils'
1010
import { parse } from 'url'
11-
import { imageNameSource, retagSource, TaskParameters } from './TaskParameters'
11+
import { imageNameSource, TaskParameters } from './TaskParameters'
1212

1313
export class TaskOperations {
1414
private dockerPath = ''
@@ -63,76 +63,30 @@ export class TaskOperations {
6363
proxyEndpoint = authData.proxyEndpoint
6464
}
6565

66-
const targetRepositoryName = this.taskParameters.repositoryName
66+
if (this.taskParameters.autoCreateRepository) {
67+
await this.createRepositoryIfNeeded(this.taskParameters.repositoryName)
68+
}
69+
6770
const targetImageName = constructTaggedImageName(
6871
this.taskParameters.repositoryName,
69-
this.taskParameters.targetTag
72+
this.taskParameters.pushTag
7073
)
7174
const targetImageRef = `${endpoint}/${targetImageName}`
75+
await this.tagImage(sourceImageRef, targetImageRef)
7276

73-
// Retag an image without pushing the complete image from docker.
74-
if (this.taskParameters.imageSource === retagSource) {
75-
const images = (
76-
await this.ecrClient
77-
.batchGetImage({
78-
repositoryName: targetRepositoryName,
79-
imageIds: [{ imageTag: this.taskParameters.targetTag }]
80-
})
81-
.promise()
82-
).images
83-
84-
if (!images || !images[0]) {
85-
throw new Error(
86-
tl.loc(
87-
'FailureToFindExistingImage',
88-
this.taskParameters.targetTag,
89-
this.taskParameters.repositoryName
90-
)
91-
)
92-
}
93-
94-
const manifest = images[0].imageManifest
95-
if (manifest) {
96-
try {
97-
await this.ecrClient
98-
.putImage({
99-
imageTag: this.taskParameters.newTag,
100-
repositoryName: targetRepositoryName,
101-
imageManifest: manifest
102-
})
103-
.promise()
104-
} catch (err) {
105-
if (err.code !== 'ImageAlreadyExistsException') {
106-
// Thrown when manifest and tag already exist in ECR.
107-
// Do not block if the tag already exists on the target image.
108-
throw err
109-
}
110-
console.log(err.message)
111-
}
112-
} else {
113-
throw new Error('batchGetImage did not return an image manifest.')
114-
}
115-
} else {
116-
if (this.taskParameters.autoCreateRepository) {
117-
await this.createRepositoryIfNeeded(this.taskParameters.repositoryName)
118-
}
119-
120-
await this.tagImage(sourceImageRef, targetImageRef)
77+
await loginToRegistry(this.dockerHandler, this.dockerPath, authToken, proxyEndpoint)
12178

122-
await loginToRegistry(this.dockerHandler, this.dockerPath, authToken, proxyEndpoint)
123-
124-
await this.pushImageToECR(targetImageRef)
125-
126-
if (this.taskParameters.removeDockerImage) {
127-
await this.removeDockerImage(sourceImageRef)
128-
}
129-
}
79+
await this.pushImageToECR(targetImageRef)
13080

13181
if (this.taskParameters.outputVariable) {
13282
console.log(tl.loc('SettingOutputVariable', this.taskParameters.outputVariable, targetImageRef))
13383
tl.setVariable(this.taskParameters.outputVariable, targetImageRef)
13484
}
13585

86+
if (this.taskParameters.removeDockerImage) {
87+
await this.removeDockerImage(sourceImageRef)
88+
}
89+
13690
console.log(tl.loc('TaskCompleted'))
13791
}
13892

src/tasks/ECRPushImage/TaskParameters.ts

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { getInputOrEmpty, getInputRequired } from 'lib/vstsUtils'
99

1010
export const imageNameSource = 'imagename'
1111
export const imageIdSource = 'imageid'
12-
export const retagSource = 'retag'
1312

1413
export interface TaskParameters {
1514
awsConnectionParameters: AWSConnectionParameters
@@ -18,8 +17,7 @@ export interface TaskParameters {
1817
sourceImageTag: string
1918
sourceImageId: string
2019
repositoryName: string
21-
targetTag: string
22-
newTag: string
20+
pushTag: string
2321
autoCreateRepository: boolean
2422
forceDockerNamingConventions: boolean
2523
removeDockerImage: boolean
@@ -31,37 +29,24 @@ export function buildTaskParameters(): TaskParameters {
3129
awsConnectionParameters: buildConnectionParameters(),
3230
imageSource: getInputRequired('imageSource'),
3331
repositoryName: getInputRequired('repositoryName'),
34-
targetTag: getInputOrEmpty('targetTag'),
32+
pushTag: getInputOrEmpty('pushTag'),
3533
autoCreateRepository: tl.getBoolInput('autoCreateRepository', false),
3634
forceDockerNamingConventions: tl.getBoolInput('forceDockerNamingConventions', false),
3735
removeDockerImage: tl.getBoolInput('removeDockerImage', false),
3836
outputVariable: getInputOrEmpty('outputVariable'),
3937
sourceImageName: '',
4038
sourceImageId: '',
41-
sourceImageTag: '',
42-
newTag: ''
39+
sourceImageTag: ''
4340
}
4441

45-
switch (parameters.imageSource) {
46-
case imageNameSource:
47-
parameters.sourceImageName = getInputRequired('sourceImageName')
48-
parameters.sourceImageTag = getInputOrEmpty('sourceImageTag')
49-
if (!parameters.sourceImageTag) {
50-
parameters.sourceImageTag = 'latest'
51-
}
52-
break
53-
case imageIdSource:
54-
parameters.sourceImageId = getInputRequired('sourceImageId')
55-
break
56-
case retagSource:
57-
parameters.newTag = getInputRequired('newTag')
58-
break
59-
default:
60-
throw new Error(`Unknown imageSource specified: ${parameters.imageSource}`)
61-
}
62-
63-
if (!parameters.targetTag) {
64-
parameters.targetTag = 'latest'
42+
if (parameters.imageSource === imageNameSource) {
43+
parameters.sourceImageName = getInputRequired('sourceImageName')
44+
parameters.sourceImageTag = getInputOrEmpty('sourceImageTag')
45+
if (!parameters.sourceImageTag) {
46+
parameters.sourceImageTag = 'latest'
47+
}
48+
} else {
49+
parameters.sourceImageId = getInputRequired('sourceImageId')
6550
}
6651

6752
return parameters

src/tasks/ECRPushImage/task.json

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,10 @@
4949
"label": "Image Identity",
5050
"required": true,
5151
"defaultValue": "imagename",
52-
"helpMarkDown": "How the image to be pushed is identified. You can select from either the image ID or the image name. If image name is selected a tag can also be specified. Alternatively, you can opt to retag an image in ECR by specifying an existing tag in the target repository. [Retagging](https://docs.aws.amazon.com/AmazonECR/latest/userguide/image-retag.html) saves bandwidth by not re-pushing the image to ECR.",
52+
"helpMarkDown": "How the image to be pushed is identified. You can select from either the image ID or the image name. If image name is selected a tag can also be specified",
5353
"options": {
5454
"imagename": "Image name with optional tag",
55-
"imageid": "Image ID",
56-
"retag": "Retag pushed image"
55+
"imageid": "Image ID"
5756
},
5857
"properties": {
5958
"EditableOptions": "False"
@@ -95,48 +94,36 @@
9594
"helpMarkDown": "The name of the repository to which the image will be pushed."
9695
},
9796
{
98-
"name": "targetTag",
97+
"name": "pushTag",
9998
"label": "Target Repository Tag",
10099
"type": "string",
101100
"required": false,
102101
"defaultValue": "latest",
103-
"helpMarkDown": "Optional tag for the image in the remote repository. If not specified, ECR will assume 'latest'."
104-
},
105-
{
106-
"name": "newTag",
107-
"label": "New Tag",
108-
"type": "string",
109-
"required": true,
110-
"defaultValue": "",
111-
"helpMarkDown": "Tag to add to the target image.",
112-
"visibleRule": "imageSource = retag"
102+
"helpMarkDown": "Optional tag for the new image in the repository. If not specified, ECR will assume 'latest'."
113103
},
114104
{
115105
"name": "autoCreateRepository",
116106
"label": "Create repository if it does not exist",
117107
"type": "boolean",
118108
"defaultValue": false,
119109
"required": false,
120-
"helpMarkDown": "If selected the task will attempt to create the repository if it does not exist.",
121-
"visibleRule": "imageSource != retag"
110+
"helpMarkDown": "If selected the task will attempt to create the repository if it does not exist."
122111
},
123112
{
124113
"name": "forceDockerNamingConventions",
125114
"label": "Force repository name to follow Docker naming conventions",
126115
"type": "boolean",
127116
"defaultValue": false,
128117
"required": false,
129-
"helpMarkDown": "If enabled, the Docker repository name will be modified to follow Docker naming conventions. Converts upper case characters to lower case. Removes all characters except 0-9, -, . and _ .",
130-
"visibleRule": "imageSource != retag"
118+
"helpMarkDown": "If enabled, the Docker repository name will be modified to follow Docker naming conventions. Converts upper case characters to lower case. Removes all characters except 0-9, -, . and _ ."
131119
},
132120
{
133121
"name": "removeDockerImage",
134122
"label": "Remove Docker image after ECR push",
135123
"type": "boolean",
136124
"defaultValue": false,
137125
"required": false,
138-
"helpMarkDown": "If enabled, this command removes the image and untags any references to it",
139-
"visibleRule": "imageSource != retag"
126+
"helpMarkDown": "If enabled, this command removes the image and untags any references to it"
140127
},
141128
{
142129
"name": "outputVariable",
@@ -185,7 +172,6 @@
185172
"SettingOutputVariable": "Setting output variable %s with the pushed image tag %s",
186173
"TaskCompleted": "Successfully completed sending the message",
187174
"FailureToObtainAuthToken": "Failed to obtain auth token!",
188-
"FailureToFindExistingImage": "Failed to find image with tag '%s' in target repository '%s'",
189175
"NoValidEndpoint": "Failed to get endpoint of repository %s. Check your credentials and if the endpoint exists!"
190176
}
191177
}

tests/endToEndTests/ecr-push-image-should-fail-no-docker.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"sourceImageTag": "latest",
4242
"sourceImageId": "",
4343
"repositoryName": "test-repo",
44-
"targetTag": "latest",
44+
"pushTag": "latest",
4545
"autoCreateRepository": "false",
4646
"outputVariable": "",
4747
"logRequest": "false",

tests/taskTests/ecrPushImage/ecrPushImage-test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ const defaultTaskParameters: TaskParameters = {
1919
sourceImageTag: '',
2020
sourceImageId: '',
2121
repositoryName: '',
22-
targetTag: '',
23-
newTag: '',
22+
pushTag: '',
2423
autoCreateRepository: false,
2524
forceDockerNamingConventions: false,
2625
removeDockerImage: false,

0 commit comments

Comments
 (0)