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

Make intermediate build config available #2115

Merged
merged 6 commits into from
Nov 1, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions jib-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ All notable changes to this project will be documented in this file.

### Added

- New method: `JibContainerBuilder#describeContainer` which returns new class: `JibContainerDescription`, containing a selection of information used for the Jib build. ([#2115](https://github.com/GoogleContainerTools/jib/issues/2115))

### Changed

### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
import java.nio.file.attribute.PosixFilePermission;
import java.util.Set;

/** Represents read/write/execute file permissions for owner, group, and others. */
/**
* Represents read/write/execute file permissions for owner, group, and others.
*
* <p>This class is immutable and thread-safe.
*/
public class FilePermissions {

/** Default permissions for files added to the container. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,16 @@ public JibContainer containerize(Containerizer containerizer)
return containerize(containerizer, Executors::newCachedThreadPool);
}

/**
* Describes the container contents and configuration without actually physically building a
* container.
*
* @return a description of the container being built
*/
public JibContainerDescription describeContainer() {
return new JibContainerDescription(layerConfigurations);
}

@VisibleForTesting
JibContainer containerize(
Containerizer containerizer, Supplier<ExecutorService> defaultExecutorServiceFactory)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright 2019 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;
chanseokoh marked this conversation as resolved.
Show resolved Hide resolved

import com.google.cloud.tools.jib.configuration.ContainerConfiguration;
import com.google.common.collect.ImmutableList;
import java.util.List;

/**
* A class containing the representation of the contents of a container. Currently only exposes
* "layers", but can be extended to expose {@link ContainerConfiguration}, {@link ImageReference} of
* the base image, or other informational classes.
*
* <p>This class is immutable and thread-safe.
*/
public class JibContainerDescription {

private final ImmutableList<LayerConfiguration> layers;

JibContainerDescription(List<LayerConfiguration> layers) {
this.layers = ImmutableList.copyOf(layers);
}

/**
* Returns a list of "user configured" layers, does *not* include base layer information.
*
* @return An {@link ImmutableList} of {@link LayerConfiguration}s
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't ./gradlew javadoc complain how having a newline before @return? And did you consider the name getAddedLayers()? I think it's lower the chance to mistakenly assume they include base image layers.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I guess I hadn't rebased by then.

*/
public List<LayerConfiguration> getLayers() {
return layers;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
/**
* Represents an entry in the layer. A layer consists of many entries that can be converted into tar
* archive entries.
*
* <p>This class is immutable and thread-safe.
*/
public class LayerEntry {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,24 +176,12 @@ public static JibBuildRunner createJibBuildRunnerForRegistryImage(
static JibContainerBuilder processCommonConfiguration(
RawConfiguration rawConfiguration,
InferredAuthProvider inferredAuthProvider,
ProjectProperties projectProperties,
Containerizer containerizer)
throws InvalidImageReferenceException, MainClassInferenceException, InvalidAppRootException,
IOException, InvalidWorkingDirectoryException, InvalidContainerVolumeException,
IncompatibleBaseImageJavaVersionException, NumberFormatException,
InvalidContainerizingModeException, InvalidFilesModificationTimeException,
ProjectProperties projectProperties)
throws InvalidFilesModificationTimeException, InvalidAppRootException,
IncompatibleBaseImageJavaVersionException, IOException, InvalidImageReferenceException,
InvalidContainerizingModeException, MainClassInferenceException,
InvalidContainerVolumeException, InvalidWorkingDirectoryException,
InvalidCreationTimeException {
JibSystemProperties.checkHttpTimeoutProperty();
JibSystemProperties.checkProxyPortProperty();

if (JibSystemProperties.sendCredentialsOverHttp()) {
projectProperties.log(
LogEvent.warn(
"Authentication over HTTP is enabled. It is strongly recommended that you do not "
+ "enable this on a public network!"));
}

configureContainerizer(containerizer, rawConfiguration, projectProperties);

// Create and configure JibContainerBuilder
BiFunction<Path, AbsoluteUnixPath, Instant> modificationTimeProvider =
Expand Down Expand Up @@ -240,6 +228,32 @@ static JibContainerBuilder processCommonConfiguration(
return jibContainerBuilder;
}

@VisibleForTesting
static JibContainerBuilder processCommonConfiguration(
RawConfiguration rawConfiguration,
InferredAuthProvider inferredAuthProvider,
ProjectProperties projectProperties,
Containerizer containerizer)
throws InvalidImageReferenceException, MainClassInferenceException, InvalidAppRootException,
IOException, InvalidWorkingDirectoryException, InvalidContainerVolumeException,
IncompatibleBaseImageJavaVersionException, NumberFormatException,
InvalidContainerizingModeException, InvalidFilesModificationTimeException,
InvalidCreationTimeException {
JibSystemProperties.checkHttpTimeoutProperty();
JibSystemProperties.checkProxyPortProperty();

if (JibSystemProperties.sendCredentialsOverHttp()) {
projectProperties.log(
LogEvent.warn(
"Authentication over HTTP is enabled. It is strongly recommended that you do not "
+ "enable this on a public network!"));
}

configureContainerizer(containerizer, rawConfiguration, projectProperties);

return processCommonConfiguration(rawConfiguration, inferredAuthProvider, projectProperties);
}

/**
* Returns a {@link JavaContainerBuilder} with the correctly parsed base image configuration.
*
Expand Down