Polish "Add option to create tags for a built image"

See gh-27613
This commit is contained in:
Scott Frederick
2021-09-28 15:31:38 -05:00
parent 66f44b0c7f
commit 64c49003aa
8 changed files with 26 additions and 26 deletions

View File

@@ -91,7 +91,7 @@ public abstract class AbstractBuildLog implements BuildLog {
}
@Override
public void createdTag(ImageReference tag) {
public void taggedImage(ImageReference tag) {
log("Successfully created image tag '" + tag + "'");
log();
}

View File

@@ -104,7 +104,7 @@ public interface BuildLog {
* Log that a tag has been created.
* @param tag the tag reference
*/
void createdTag(ImageReference tag);
void taggedImage(ImageReference tag);
/**
* Factory method that returns a {@link BuildLog} the outputs to {@link System#out}.

View File

@@ -111,10 +111,9 @@ public class Builder {
this.docker.image().load(ephemeralBuilder.getArchive(), UpdateListener.none());
try {
executeLifecycle(request, ephemeralBuilder);
createTags(request.getName(), request.getTags());
tagImage(request.getName(), request.getTags());
if (request.isPublish()) {
pushImage(request.getName());
pushTags(request.getTags());
pushImages(request.getName(), request.getTags());
}
}
finally {
@@ -153,6 +152,20 @@ public class Builder {
}
}
private void tagImage(ImageReference sourceReference, List<ImageReference> tags) throws IOException {
for (ImageReference tag : tags) {
this.docker.image().tag(sourceReference, tag);
this.log.taggedImage(tag);
}
}
private void pushImages(ImageReference name, List<ImageReference> tags) throws IOException {
pushImage(name);
for (ImageReference tag : tags) {
pushImage(tag);
}
}
private void pushImage(ImageReference reference) throws IOException {
Consumer<TotalProgressEvent> progressConsumer = this.log.pushingImage(reference);
TotalProgressPushListener listener = new TotalProgressPushListener(progressConsumer);
@@ -160,19 +173,6 @@ public class Builder {
this.log.pushedImage(reference);
}
private void createTags(ImageReference sourceReference, List<ImageReference> tags) throws IOException {
for (ImageReference tag : tags) {
this.docker.image().tag(sourceReference, tag);
this.log.createdTag(tag);
}
}
private void pushTags(List<ImageReference> tags) throws IOException {
for (ImageReference tag : tags) {
pushImage(tag);
}
}
private String getBuilderAuthHeader() {
return (this.dockerConfiguration != null && this.dockerConfiguration.getBuilderRegistryAuthentication() != null)
? this.dockerConfiguration.getBuilderRegistryAuthentication().getAuthHeader() : null;

View File

@@ -284,7 +284,7 @@ public class DockerApi {
Assert.notNull(reference, "Reference must not be null");
Collection<String> params = force ? FORCE_PARAMS : Collections.emptySet();
URI uri = buildUrl("/images/" + reference, params);
http().delete(uri);
http().delete(uri).close();
}
/**
@@ -305,7 +305,7 @@ public class DockerApi {
Assert.notNull(sourceReference, "SourceReference must not be null");
Assert.notNull(targetReference, "TargetReference must not be null");
URI uri = buildUrl("/images/" + sourceReference + "/tag", "repo", targetReference.toString());
http().post(uri);
http().post(uri).close();
}
}
@@ -356,7 +356,7 @@ public class DockerApi {
public void start(ContainerReference reference) throws IOException {
Assert.notNull(reference, "Reference must not be null");
URI uri = buildUrl("/containers/" + reference + "/start");
http().post(uri);
http().post(uri).close();
}
/**
@@ -404,7 +404,7 @@ public class DockerApi {
Assert.notNull(reference, "Reference must not be null");
Collection<String> params = force ? FORCE_PARAMS : Collections.emptySet();
URI uri = buildUrl("/containers/" + reference, params);
http().delete(uri);
http().delete(uri).close();
}
}
@@ -427,7 +427,7 @@ public class DockerApi {
Assert.notNull(name, "Name must not be null");
Collection<String> params = force ? FORCE_PARAMS : Collections.emptySet();
URI uri = buildUrl("/volumes/" + name, params);
http().delete(uri);
http().delete(uri).close();
}
}

View File

@@ -76,7 +76,7 @@ class PrintStreamBuildLogTests {
phase2Consumer.accept(mockLogEvent("spring"));
phase2Consumer.accept(mockLogEvent("boot"));
log.executedLifecycle(request);
log.createdTag(tag);
log.taggedImage(tag);
String expected = FileCopyUtils.copyToString(new InputStreamReader(
getClass().getResourceAsStream("print-stream-build-log.txt"), StandardCharsets.UTF_8));
assertThat(out.toString()).isEqualToIgnoringNewLines(expected);

View File

@@ -178,7 +178,7 @@ The value supplied will be passed unvalidated to Docker when creating the builde
| `tags`
|
| Multiple {spring-boot-api}/buildpack/platform/docker/type/ImageReference.html#of-java.lang.String-[tag names] to be created for the generated image.
| A list of one or more additional tags to apply to the generated image.
|
|===

View File

@@ -184,7 +184,7 @@ The value supplied will be passed unvalidated to Docker when creating the builde
| `false`
| `tags`
| Multiple {spring-boot-api}/buildpack/platform/docker/type/ImageReference.html#of-java.lang.String-[tag names] to be created for the generated image.
| One or more additional tags to apply to the generated image.
|
|===