Skip to content

Commit 2640802

Browse files
authored
Does not authenticate pull unless the image requires authentication. (GoogleContainerTools#414)
1 parent 5db41a5 commit 2640802

9 files changed

Lines changed: 143 additions & 186 deletions

‎jib-core/src/main/java/com/google/cloud/tools/jib/builder/BuildSteps.java‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,7 @@ public static BuildSteps forBuildToDockerRegistry(
7676
stepsRunner ->
7777
stepsRunner
7878
.runRetrieveTargetRegistryCredentialsStep()
79-
.runRetrieveBaseRegistryCredentialsStep()
8079
.runAuthenticatePushStep()
81-
.runAuthenticatePullStep()
8280
.runPullBaseImageStep()
8381
.runPullAndCacheBaseImageLayersStep()
8482
.runPushBaseImageLayersStep()
@@ -114,8 +112,6 @@ public static BuildSteps forBuildToDockerDaemon(
114112
SUCCESS_MESSAGE_FORMAT_FOR_DOCKER_DAEMON, buildConfiguration.getTargetImageReference()),
115113
stepsRunner ->
116114
stepsRunner
117-
.runRetrieveBaseRegistryCredentialsStep()
118-
.runAuthenticatePullStep()
119115
.runPullBaseImageStep()
120116
.runPullAndCacheBaseImageLayersStep()
121117
.runBuildAndCacheApplicationLayerSteps()

‎jib-core/src/main/java/com/google/cloud/tools/jib/builder/steps/AuthenticatePullStep.java‎

Lines changed: 0 additions & 86 deletions
This file was deleted.

‎jib-core/src/main/java/com/google/cloud/tools/jib/builder/steps/PullAndCacheBaseImageLayerStep.java‎

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,22 @@
1818

1919
import com.google.cloud.tools.jib.Timer;
2020
import com.google.cloud.tools.jib.async.AsyncStep;
21-
import com.google.cloud.tools.jib.async.NonBlockingSteps;
2221
import com.google.cloud.tools.jib.builder.BuildConfiguration;
2322
import com.google.cloud.tools.jib.cache.Cache;
2423
import com.google.cloud.tools.jib.cache.CacheReader;
2524
import com.google.cloud.tools.jib.cache.CacheWriter;
2625
import com.google.cloud.tools.jib.cache.CachedLayer;
26+
import com.google.cloud.tools.jib.http.Authorization;
2727
import com.google.cloud.tools.jib.image.DescriptorDigest;
2828
import com.google.cloud.tools.jib.image.LayerPropertyNotFoundException;
2929
import com.google.cloud.tools.jib.registry.RegistryClient;
3030
import com.google.cloud.tools.jib.registry.RegistryException;
3131
import com.google.common.io.CountingOutputStream;
32-
import com.google.common.util.concurrent.Futures;
3332
import com.google.common.util.concurrent.ListenableFuture;
3433
import com.google.common.util.concurrent.ListeningExecutorService;
3534
import java.io.IOException;
3635
import java.util.concurrent.Callable;
37-
import java.util.concurrent.ExecutionException;
36+
import javax.annotation.Nullable;
3837

3938
/** Pulls and caches a single base image layer. */
4039
class PullAndCacheBaseImageLayerStep implements AsyncStep<CachedLayer>, Callable<CachedLayer> {
@@ -44,7 +43,7 @@ class PullAndCacheBaseImageLayerStep implements AsyncStep<CachedLayer>, Callable
4443
private final BuildConfiguration buildConfiguration;
4544
private final Cache cache;
4645
private final DescriptorDigest layerDigest;
47-
private final AuthenticatePullStep authenticatePullStep;
46+
private final @Nullable Authorization pullAuthorization;
4847

4948
private final ListenableFuture<CachedLayer> listenableFuture;
5049

@@ -53,15 +52,13 @@ class PullAndCacheBaseImageLayerStep implements AsyncStep<CachedLayer>, Callable
5352
BuildConfiguration buildConfiguration,
5453
Cache cache,
5554
DescriptorDigest layerDigest,
56-
AuthenticatePullStep authenticatePullStep) {
55+
@Nullable Authorization pullAuthorization) {
5756
this.buildConfiguration = buildConfiguration;
5857
this.cache = cache;
5958
this.layerDigest = layerDigest;
60-
this.authenticatePullStep = authenticatePullStep;
59+
this.pullAuthorization = pullAuthorization;
6160

62-
listenableFuture =
63-
Futures.whenAllSucceed(authenticatePullStep.getFuture())
64-
.call(this, listeningExecutorService);
61+
listenableFuture = listeningExecutorService.submit(this);
6562
}
6663

6764
@Override
@@ -70,13 +67,12 @@ public ListenableFuture<CachedLayer> getFuture() {
7067
}
7168

7269
@Override
73-
public CachedLayer call()
74-
throws IOException, RegistryException, LayerPropertyNotFoundException, ExecutionException {
70+
public CachedLayer call() throws IOException, RegistryException, LayerPropertyNotFoundException {
7571
try (Timer ignored =
7672
new Timer(buildConfiguration.getBuildLogger(), String.format(DESCRIPTION, layerDigest))) {
7773
RegistryClient registryClient =
7874
new RegistryClient(
79-
NonBlockingSteps.get(authenticatePullStep),
75+
pullAuthorization,
8076
buildConfiguration.getBaseImageRegistry(),
8177
buildConfiguration.getBaseImageRepository());
8278

‎jib-core/src/main/java/com/google/cloud/tools/jib/builder/steps/PullAndCacheBaseImageLayersStep.java‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.google.cloud.tools.jib.async.AsyncStep;
2121
import com.google.cloud.tools.jib.async.NonBlockingSteps;
2222
import com.google.cloud.tools.jib.builder.BuildConfiguration;
23+
import com.google.cloud.tools.jib.builder.steps.PullBaseImageStep.BaseImageWithAuthorization;
2324
import com.google.cloud.tools.jib.cache.Cache;
2425
import com.google.cloud.tools.jib.image.Layer;
2526
import com.google.cloud.tools.jib.image.LayerPropertyNotFoundException;
@@ -39,7 +40,6 @@ class PullAndCacheBaseImageLayersStep
3940

4041
private final BuildConfiguration buildConfiguration;
4142
private final Cache cache;
42-
private final AuthenticatePullStep authenticatePullStep;
4343
private final PullBaseImageStep pullBaseImageStep;
4444

4545
private final ListeningExecutorService listeningExecutorService;
@@ -49,12 +49,10 @@ class PullAndCacheBaseImageLayersStep
4949
ListeningExecutorService listeningExecutorService,
5050
BuildConfiguration buildConfiguration,
5151
Cache cache,
52-
AuthenticatePullStep authenticatePullStep,
5352
PullBaseImageStep pullBaseImageStep) {
5453
this.listeningExecutorService = listeningExecutorService;
5554
this.buildConfiguration = buildConfiguration;
5655
this.cache = cache;
57-
this.authenticatePullStep = authenticatePullStep;
5856
this.pullBaseImageStep = pullBaseImageStep;
5957

6058
listenableFuture =
@@ -70,7 +68,8 @@ public ListenableFuture<ImmutableList<PullAndCacheBaseImageLayerStep>> getFuture
7068
public ImmutableList<PullAndCacheBaseImageLayerStep> call()
7169
throws ExecutionException, LayerPropertyNotFoundException {
7270
try (Timer ignored = new Timer(buildConfiguration.getBuildLogger(), DESCRIPTION)) {
73-
ImmutableList<Layer> baseImageLayers = NonBlockingSteps.get(pullBaseImageStep).getLayers();
71+
BaseImageWithAuthorization pullBaseImageStepResult = NonBlockingSteps.get(pullBaseImageStep);
72+
ImmutableList<Layer> baseImageLayers = pullBaseImageStepResult.getBaseImage().getLayers();
7473

7574
ImmutableList.Builder<PullAndCacheBaseImageLayerStep> pullAndCacheBaseImageLayerStepsBuilder =
7675
ImmutableList.builderWithExpectedSize(baseImageLayers.size());
@@ -81,7 +80,7 @@ public ImmutableList<PullAndCacheBaseImageLayerStep> call()
8180
buildConfiguration,
8281
cache,
8382
layer.getBlobDescriptor().getDigest(),
84-
authenticatePullStep));
83+
pullBaseImageStepResult.getBaseImageAuthorization()));
8584
}
8685

8786
return pullAndCacheBaseImageLayerStepsBuilder.build();

0 commit comments

Comments
 (0)