-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create
DockerClient
interface (#3703)
Extract `DockerClient` into an interface to allow providing non-CLI implementations. Old `DockerClient` renamed to `CliDockerClient` and used as default implementation.
- Loading branch information
1 parent
a789a11
commit 9027c8d
Showing
21 changed files
with
342 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
jib-core/src/main/java/com/google/cloud/tools/jib/api/DockerClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright 2022 Google LLC. | ||
* | ||
* 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.api; | ||
|
||
import com.google.cloud.tools.jib.image.ImageTarball; | ||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.util.Map; | ||
import java.util.function.Consumer; | ||
|
||
public interface DockerClient { | ||
|
||
/** | ||
* Validate if the DockerClient is supported. | ||
* | ||
* @param parameters to be used by the docker client | ||
* @return true if conditions are met | ||
*/ | ||
boolean supported(Map<String, String> parameters); | ||
|
||
/** | ||
* Loads an image tarball into the Docker daemon. | ||
* | ||
* @see <a | ||
* href="https://docs.docker.com/engine/reference/commandline/load/">https://docs.docker.com/engine/reference/commandline/load</a> | ||
* @param imageTarball the built container tarball | ||
* @param writtenByteCountListener callback to call when bytes are loaded | ||
* @return stdout from {@code docker} | ||
* @throws InterruptedException if the 'docker load' process is interrupted | ||
* @throws IOException if streaming the blob to 'docker load' fails | ||
*/ | ||
String load(ImageTarball imageTarball, Consumer<Long> writtenByteCountListener) | ||
throws InterruptedException, IOException; | ||
|
||
/** | ||
* Saves an image tarball from the Docker daemon. | ||
* | ||
* @see <a | ||
* href="https://docs.docker.com/engine/reference/commandline/save/">https://docs.docker.com/engine/reference/commandline/save</a> | ||
* @param imageReference the image to save | ||
* @param outputPath the destination path to save the output tarball | ||
* @param writtenByteCountListener callback to call when bytes are saved | ||
* @throws InterruptedException if the 'docker save' process is interrupted | ||
* @throws IOException if creating the tarball fails | ||
*/ | ||
void save(ImageReference imageReference, Path outputPath, Consumer<Long> writtenByteCountListener) | ||
throws InterruptedException, IOException; | ||
|
||
/** | ||
* Gets the size, image ID, and diff IDs of an image in the Docker daemon. | ||
* | ||
* @param imageReference the image to inspect | ||
* @return the size, image ID, and diff IDs of the image | ||
* @throws IOException if an I/O exception occurs or {@code docker inspect} failed | ||
* @throws InterruptedException if the {@code docker inspect} process was interrupted | ||
*/ | ||
ImageDetails inspect(ImageReference imageReference) throws IOException, InterruptedException; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
jib-core/src/main/java/com/google/cloud/tools/jib/api/ImageDetails.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright 2022 Google LLC. | ||
* | ||
* 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.api; | ||
|
||
import java.security.DigestException; | ||
import java.util.List; | ||
|
||
public interface ImageDetails { | ||
|
||
long getSize(); | ||
|
||
DescriptorDigest getImageId() throws DigestException; | ||
|
||
List<DescriptorDigest> getDiffIds() throws DigestException; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.