-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Break apart container configuration build and push step #252
Changes from 2 commits
8a8117b
995c3aa
b71b3a1
c6fba8c
cb89a3b
dc784ff
c6fae59
6a1b591
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright 2018 Google LLC. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
|
||
package com.google.cloud.tools.jib.blob; | ||
|
||
/** Struct for pairing a Blob and its digest. */ | ||
public class BlobAndDigest { | ||
private Blob blob; | ||
private BlobDescriptor blobDescriptor; | ||
|
||
public BlobAndDigest(Blob blob, BlobDescriptor blobDescriptor) { | ||
this.blob = blob; | ||
this.blobDescriptor = blobDescriptor; | ||
} | ||
|
||
public Blob getBlob() { | ||
return blob; | ||
} | ||
|
||
public BlobDescriptor getBlobDescriptor() { | ||
return blobDescriptor; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
package com.google.cloud.tools.jib.builder; | ||
|
||
import com.google.cloud.tools.jib.Timer; | ||
import com.google.cloud.tools.jib.blob.BlobAndDigest; | ||
import com.google.cloud.tools.jib.blob.BlobDescriptor; | ||
import com.google.cloud.tools.jib.cache.Cache; | ||
import com.google.cloud.tools.jib.cache.CacheDirectoryNotOwnedException; | ||
|
@@ -144,13 +145,13 @@ public void run() | |
listeningExecutorService) | ||
.call(); | ||
|
||
timer2.lap("Setting up container configuration push"); | ||
// Builds and pushes the container configuration. | ||
ListenableFuture<ListenableFuture<BlobDescriptor>> | ||
buildAndPushContainerConfigurationFutureFuture = | ||
timer2.lap("Setting up build container configuration"); | ||
// Builds the container configuration. | ||
ListenableFuture<ListenableFuture<BlobAndDigest>> | ||
buildContainerConfigurationFutureFuture = | ||
Futures.whenAllSucceed(pullBaseImageLayerFuturesFuture) | ||
.call( | ||
new BuildAndPushContainerConfigurationStep( | ||
new BuildContainerConfigurationStep( | ||
buildConfiguration, | ||
listeningExecutorService, | ||
authenticatePushFuture, | ||
|
@@ -159,6 +160,19 @@ public void run() | |
entrypoint), | ||
listeningExecutorService); | ||
|
||
timer2.lap("Setting up container configuration push"); | ||
// Pushes the container configuration. | ||
ListenableFuture<ListenableFuture<BlobDescriptor>> | ||
pushContainerConfigurationFutureFuture = | ||
Futures.whenAllSucceed(buildContainerConfigurationFutureFuture) | ||
.call( | ||
new PushContainerConfigurationStep( | ||
buildConfiguration, | ||
authenticatePushFuture, | ||
buildContainerConfigurationFutureFuture.get(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This call to get would be executed before anything is run, which would cause race conditions and blocking. Any |
||
listeningExecutorService), | ||
listeningExecutorService); | ||
|
||
timer2.lap("Setting up application layer push"); | ||
// Pushes the application layers. | ||
List<ListenableFuture<Void>> pushApplicationLayersFuture = | ||
|
@@ -173,8 +187,7 @@ public void run() | |
// Pushes the new image manifest. | ||
ListenableFuture<Void> pushImageFuture = | ||
Futures.whenAllSucceed( | ||
pushBaseImageLayerFuturesFuture, | ||
buildAndPushContainerConfigurationFutureFuture) | ||
pushBaseImageLayerFuturesFuture, pushContainerConfigurationFutureFuture) | ||
.call( | ||
new PushImageStep( | ||
buildConfiguration, | ||
|
@@ -184,7 +197,7 @@ public void run() | |
buildAndCacheApplicationLayerFutures, | ||
pushBaseImageLayerFuturesFuture, | ||
pushApplicationLayersFuture, | ||
buildAndPushContainerConfigurationFutureFuture), | ||
pushContainerConfigurationFutureFuture), | ||
listeningExecutorService); | ||
|
||
timer2.lap("Running push new image"); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright 2018 Google LLC. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
|
||
package com.google.cloud.tools.jib.builder; | ||
|
||
import com.google.cloud.tools.jib.Timer; | ||
import com.google.cloud.tools.jib.blob.BlobAndDigest; | ||
import com.google.cloud.tools.jib.blob.BlobDescriptor; | ||
import com.google.cloud.tools.jib.http.Authorization; | ||
import com.google.cloud.tools.jib.registry.RegistryClient; | ||
import com.google.common.util.concurrent.ListenableFuture; | ||
import com.google.common.util.concurrent.ListeningExecutorService; | ||
import java.util.concurrent.Callable; | ||
|
||
class PushContainerConfigurationStep implements Callable<ListenableFuture<BlobDescriptor>> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Short javadoc here |
||
|
||
private static final String DESCRIPTION = "Pushing container configuration"; | ||
|
||
private final BuildConfiguration buildConfiguration; | ||
private final ListenableFuture<Authorization> pushAuthorizationFuture; | ||
private final ListenableFuture<BlobAndDigest> blobAndDigestFuture; | ||
private final ListeningExecutorService listeningExecutorService; | ||
|
||
PushContainerConfigurationStep( | ||
BuildConfiguration buildConfiguration, | ||
ListenableFuture<Authorization> pushAuthorizationFuture, | ||
ListenableFuture<BlobAndDigest> blobAndDigestFuture, | ||
ListeningExecutorService listeningExecutorService) { | ||
this.buildConfiguration = buildConfiguration; | ||
this.pushAuthorizationFuture = pushAuthorizationFuture; | ||
this.blobAndDigestFuture = blobAndDigestFuture; | ||
this.listeningExecutorService = listeningExecutorService; | ||
} | ||
|
||
@Override | ||
public ListenableFuture<BlobDescriptor> call() { | ||
return listeningExecutorService.submit( | ||
() -> { | ||
try (Timer timer = new Timer(buildConfiguration.getBuildLogger(), DESCRIPTION)) { | ||
RegistryClient registryClient = | ||
new RegistryClient( | ||
NonBlockingFutures.get(pushAuthorizationFuture), | ||
buildConfiguration.getTargetRegistry(), | ||
buildConfiguration.getTargetRepository()) | ||
.setTimer(timer); | ||
|
||
// TODO: Use PushBlobStep. | ||
// Pushes the container configuration. | ||
BlobAndDigest blobAndDigest = blobAndDigestFuture.get(); | ||
registryClient.pushBlob( | ||
blobAndDigest.getBlobDescriptor().getDigest(), blobAndDigest.getBlob()); | ||
return blobAndDigest.getBlobDescriptor(); | ||
} | ||
}); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could probably avoid creating a new tuple class
BlobAndDigest
by just returning theBlob
here and generating theDigest
in the push step.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, I wasn't sure if the Digest generation should be kept in the build step.