Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6de4ff6

Browse files
committed
fix(d2g): duplicate image with separate IDs get handled properly
1 parent d7fbf0e commit 6de4ff6

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

changelog/issue-7969.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
audience: users
2+
level: patch
3+
reference: issue 7969
4+
---
5+
D2G: fixes issue with loading the docker image artifact if the image already exists with a separate ID, causing the following output to be improperly parsed by D2G: `The image <imageName> already exists, renaming the old one with ID <sha> to empty string`.

workers/generic-worker/d2g_feature.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ func (dtf *D2GTaskFeature) Start() *CommandExecutionError {
9292
cmd, err = process.NewCommandNoOutputStreams([]string{
9393
"docker",
9494
"load",
95+
"--quiet",
9596
"--input",
9697
"dockerimage",
9798
}, taskContext.TaskDir, []string{}, dtf.task.pd)
@@ -111,12 +112,26 @@ func (dtf *D2GTaskFeature) Start() *CommandExecutionError {
111112
return executionError(internalError, errored, fmt.Errorf("[d2g] could not load docker image: %v\n%v", err, string(out)))
112113
}
113114

114-
// Only use the first line of output for image name
115-
// as docker load can output multiple tags for the
115+
// Default to use the first line of output for image
116+
// name as docker load can output multiple tags for the
116117
// same image (see https://github.com/taskcluster/taskcluster/issues/7967)
117-
imageName := strings.Split(strings.TrimSpace(string(out)), "\n")[0]
118+
lines := strings.Split(strings.TrimSpace(string(out)), "\n")
119+
imageName := lines[0]
118120
if isImageArtifact {
119-
imageName = strings.TrimPrefix(imageName, "Loaded image: ")
121+
imageNameFound := false
122+
// Find the first line with "Loaded image: " prefix
123+
// (see https://github.com/taskcluster/taskcluster/issues/7969)
124+
for _, line := range lines {
125+
if name, found := strings.CutPrefix(line, "Loaded image: "); found {
126+
imageName = name
127+
imageNameFound = true
128+
break
129+
}
130+
}
131+
132+
if !imageNameFound {
133+
return executionError(internalError, errored, fmt.Errorf("[d2g] could not determine docker image name from docker load output:\n%v", string(out)))
134+
}
120135
}
121136
imageID := imageName
122137

0 commit comments

Comments
 (0)