Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not authenticate pull unless the image requires authentication. #414

Merged
merged 7 commits into from
Jun 19, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ public static BuildSteps forBuildToDockerRegistry(
stepsRunner ->
stepsRunner
.runRetrieveTargetRegistryCredentialsStep()
.runRetrieveBaseRegistryCredentialsStep()
.runAuthenticatePushStep()
.runAuthenticatePullStep()
.runPullBaseImageStep()
.runPullAndCacheBaseImageLayersStep()
.runPushBaseImageLayersStep()
Expand Down Expand Up @@ -114,8 +112,6 @@ public static BuildSteps forBuildToDockerDaemon(
SUCCESS_MESSAGE_FORMAT_FOR_DOCKER_DAEMON, buildConfiguration.getTargetImageReference()),
stepsRunner ->
stepsRunner
.runRetrieveBaseRegistryCredentialsStep()
.runAuthenticatePullStep()
.runPullBaseImageStep()
.runPullAndCacheBaseImageLayersStep()
.runBuildAndCacheApplicationLayerSteps()
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,22 @@

import com.google.cloud.tools.jib.Timer;
import com.google.cloud.tools.jib.async.AsyncStep;
import com.google.cloud.tools.jib.async.NonBlockingSteps;
import com.google.cloud.tools.jib.builder.BuildConfiguration;
import com.google.cloud.tools.jib.cache.Cache;
import com.google.cloud.tools.jib.cache.CacheReader;
import com.google.cloud.tools.jib.cache.CacheWriter;
import com.google.cloud.tools.jib.cache.CachedLayer;
import com.google.cloud.tools.jib.http.Authorization;
import com.google.cloud.tools.jib.image.DescriptorDigest;
import com.google.cloud.tools.jib.image.LayerPropertyNotFoundException;
import com.google.cloud.tools.jib.registry.RegistryClient;
import com.google.cloud.tools.jib.registry.RegistryException;
import com.google.common.io.CountingOutputStream;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import java.io.IOException;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import javax.annotation.Nullable;

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

private final ListenableFuture<CachedLayer> listenableFuture;

Expand All @@ -53,15 +52,13 @@ class PullAndCacheBaseImageLayerStep implements AsyncStep<CachedLayer>, Callable
BuildConfiguration buildConfiguration,
Cache cache,
DescriptorDigest layerDigest,
AuthenticatePullStep authenticatePullStep) {
@Nullable Authorization pullAuthorization) {
this.buildConfiguration = buildConfiguration;
this.cache = cache;
this.layerDigest = layerDigest;
this.authenticatePullStep = authenticatePullStep;
this.pullAuthorization = pullAuthorization;

listenableFuture =
Futures.whenAllSucceed(authenticatePullStep.getFuture())
.call(this, listeningExecutorService);
listenableFuture = listeningExecutorService.submit(this);
}

@Override
Expand All @@ -70,13 +67,12 @@ public ListenableFuture<CachedLayer> getFuture() {
}

@Override
public CachedLayer call()
throws IOException, RegistryException, LayerPropertyNotFoundException, ExecutionException {
public CachedLayer call() throws IOException, RegistryException, LayerPropertyNotFoundException {
try (Timer ignored =
new Timer(buildConfiguration.getBuildLogger(), String.format(DESCRIPTION, layerDigest))) {
RegistryClient registryClient =
new RegistryClient(
NonBlockingSteps.get(authenticatePullStep),
pullAuthorization,
buildConfiguration.getBaseImageRegistry(),
buildConfiguration.getBaseImageRepository());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class PullAndCacheBaseImageLayersStep

private final BuildConfiguration buildConfiguration;
private final Cache cache;
private final AuthenticatePullStep authenticatePullStep;
private final PullBaseImageStep pullBaseImageStep;

private final ListeningExecutorService listeningExecutorService;
Expand All @@ -49,12 +48,10 @@ class PullAndCacheBaseImageLayersStep
ListeningExecutorService listeningExecutorService,
BuildConfiguration buildConfiguration,
Cache cache,
AuthenticatePullStep authenticatePullStep,
PullBaseImageStep pullBaseImageStep) {
this.listeningExecutorService = listeningExecutorService;
this.buildConfiguration = buildConfiguration;
this.cache = cache;
this.authenticatePullStep = authenticatePullStep;
this.pullBaseImageStep = pullBaseImageStep;

listenableFuture =
Expand All @@ -70,7 +67,8 @@ public ListenableFuture<ImmutableList<PullAndCacheBaseImageLayerStep>> getFuture
public ImmutableList<PullAndCacheBaseImageLayerStep> call()
throws ExecutionException, LayerPropertyNotFoundException {
try (Timer ignored = new Timer(buildConfiguration.getBuildLogger(), DESCRIPTION)) {
ImmutableList<Layer> baseImageLayers = NonBlockingSteps.get(pullBaseImageStep).getLayers();
PullBaseImageStep.Result pullBaseImageStepResult = NonBlockingSteps.get(pullBaseImageStep);
ImmutableList<Layer> baseImageLayers = pullBaseImageStepResult.getBaseImage().getLayers();

ImmutableList.Builder<PullAndCacheBaseImageLayerStep> pullAndCacheBaseImageLayerStepsBuilder =
ImmutableList.builderWithExpectedSize(baseImageLayers.size());
Expand All @@ -81,7 +79,7 @@ public ImmutableList<PullAndCacheBaseImageLayerStep> call()
buildConfiguration,
cache,
layer.getBlobDescriptor().getDigest(),
authenticatePullStep));
pullBaseImageStepResult.getBaseImageAuthorization()));
}

return pullAndCacheBaseImageLayerStepsBuilder.build();
Expand Down
Loading