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

Check if file exists when executable path is passed in through jib dockerClient.executable #3744

Merged
merged 3 commits into from Aug 25, 2022

Conversation

mpeddada1
Copy link
Contributor

@mpeddada1 mpeddada1 commented Aug 25, 2022

Currently, in order to verify if the docker path provided (either default or specified by the user) is installed correctly, we actually run the executable. The side effect of this is that any arbitrary executable can be executed by Jib.

This PR avoids the need to run the executable by using Files.isExecutable which verifies if the path provided exists and the JVM has the correct permissions to execute the path. However in the case of verifying whether docker is on PATH, running the docker command seems unavoidable at the moment. Reasoning in #3744 (comment)

Verified with ./gradlew jib-gradle-plugin:integrationTest

*
* @return {@code true} if Docker is installed on the user's system and accessible
*/
public static boolean isDefaultDockerInstalled() {
return isDockerInstalled(DEFAULT_DOCKER_CLIENT);
try {
new ProcessBuilder(DEFAULT_DOCKER_CLIENT.toString()).start();
Copy link
Contributor Author

@mpeddada1 mpeddada1 Aug 25, 2022

Choose a reason for hiding this comment

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

Some background of this change: Checking for existence of the default docker command when it is on PATH has been a little tricky. There can be several places where docker could be installed on a system and this also differs from OS to OS. For checking whether the path passed through jib.dockerClient.executable is installed correctly, however, we no longer run executable itself.

Copy link
Contributor

Choose a reason for hiding this comment

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

oh, that's a good idea.

@sonarcloud
Copy link

sonarcloud bot commented Aug 25, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

20.0% 20.0% Coverage
0.0% 0.0% Duplication

*
* @return {@code true} if Docker is installed on the user's system and accessible
*/
public static boolean isDefaultDockerInstalled() {
return isDockerInstalled(DEFAULT_DOCKER_CLIENT);
try {
new ProcessBuilder(DEFAULT_DOCKER_CLIENT.toString()).start();
Copy link
Contributor

Choose a reason for hiding this comment

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

oh, that's a good idea.

This was referenced Aug 25, 2022
@mpeddada1 mpeddada1 marked this pull request as ready for review August 25, 2022 19:20
@mpeddada1
Copy link
Contributor Author

Thank you for the review @elefeint! Changes also succeeded on continuous build. The integration tests cover both scenarios: when default docker is installed and when docker executable is provided. Will be merging this PR.

@mpeddada1 mpeddada1 merged commit 67fa40b into master Aug 25, 2022
@mpeddada1 mpeddada1 deleted the check-permissions branch August 25, 2022 20:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants