-
Notifications
You must be signed in to change notification settings - Fork 643
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
chore(build): Refactor BuildService and separate Maven/Docker specific parts. #1116
base: master
Are you sure you want to change the base?
Conversation
} catch (IOException e) { | ||
throw new MojoExecutionException("Cannot create archive " + archive, e); | ||
throw new IOException("Cannot create archive " + archive, e); | ||
} catch (RuntimeException e) { | ||
e.printStackTrace(); |
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.
Codecov Report
@@ Coverage Diff @@
## master #1116 +/- ##
============================================
+ Coverage 52.31% 52.48% +0.16%
+ Complexity 1473 1469 -4
============================================
Files 150 161 +11
Lines 7854 7934 +80
Branches 1168 1150 -18
============================================
+ Hits 4109 4164 +55
- Misses 3343 3348 +5
- Partials 402 422 +20
|
42077e8
to
c7c06c6
Compare
@@ -54,8 +58,8 @@ public WatchService(ArchiveService archiveService, BuildService buildService, Do | |||
this.log = log; | |||
} | |||
|
|||
public synchronized void watch(WatchContext context, BuildService.BuildContext buildContext, List<ImageConfiguration> images) throws DockerAccessException, | |||
MojoExecutionException { | |||
public synchronized void watch(WatchContext watchContext, MavenBuildContext buildContext, List<ImageConfiguration> images) throws |
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.
private String name; | ||
|
||
@Parameter | ||
private int retry; | ||
|
||
public RestartPolicy() {}; |
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.
return soft; | ||
} | ||
|
||
Pattern ULIMIT_PATTERN = Pattern.compile("^(?<name>[^=]+)=(?<hard>[^:]*):?(?<soft>[^:]*)$"); |
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.
return new BZip2CompressorOutputStream(out); | ||
} | ||
}; | ||
none("tar"), |
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.
} | ||
}; | ||
none("tar"), | ||
gzip("tar.gz"), |
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.
}; | ||
none("tar"), | ||
gzip("tar.gz"), | ||
bzip2("tar.bz"); |
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.
private File dockerFileFile, dockerArchiveFile; | ||
|
||
public BuildImageConfiguration() {} | ||
public BuildConfiguration() {} |
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.
return config; | ||
} | ||
} | ||
|
||
public String initAndValidate(Logger log) throws IllegalArgumentException { | ||
public String validate() throws IllegalArgumentException { |
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.
return build; | ||
} | ||
|
||
public static class Builder extends ImageConfiguration.Builder { |
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.
return nocache.length() == 0 || Boolean.valueOf(nocache); | ||
} else { | ||
BuildConfiguration buildConfig = imageConfig.getBuildConfiguration(); | ||
return buildConfig.getNoCache() != null ? buildConfig.getNoCache() : false; |
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.
public Object handleResponse(HttpResponse response) throws IOException { | ||
try (InputStream stream = response.getEntity().getContent(); | ||
OutputStream out = compression.wrapOutputStream(new FileOutputStream(filename))) { | ||
private ResponseHandler<Object> getImageResponseHandler(final String filename) throws FileNotFoundException { |
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.
return inline; | ||
} | ||
|
||
public static class Builder extends AssemblyConfiguration.Builder { |
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.
return assembly; | ||
} | ||
|
||
public static class Builder extends BuildConfiguration.Builder { |
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.
AssemblyConfiguration config = new AssemblyConfiguration.Builder().ignorePermissions(false).permissions("ignore").build(); | ||
assertTrue(config.isIgnorePermissions());; | ||
AssemblyConfiguration config = new AssemblyConfiguration.Builder().permissions("ignore").build(); | ||
assertSame(config.getPermissions(), AssemblyConfiguration.PermissionMode.ignore);; |
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.
@@ -237,6 +244,13 @@ public void execute() throws MojoExecutionException, MojoFailureException { | |||
} | |||
} | |||
|
|||
private List<ImageConfiguration> convertToPlainImageConfigurations(List<MavenImageConfiguration> images) { | |||
if (images == null) { | |||
return null; |
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.
.user(valueProvider.getString(USER, config == null ? null : config.getUser())) | ||
.healthCheck(extractHealthCheck(config == null ? null : config.getHealthCheck(), valueProvider)) | ||
.build(); | ||
} | ||
|
||
private RunImageConfiguration extractRunConfiguration(ImageConfiguration fromConfig, ValueProvider valueProvider) { | ||
RunImageConfiguration config = fromConfig.getRunConfiguration(); | ||
private RunConfiguration extractRunConfiguration(ImageConfiguration fromConfig, ValueProvider valueProvider) { |
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.
.exportBasedir(valueProvider.getBoolean(ASSEMBLY_EXPORT_BASEDIR, config == null ? null : config.getExportTargetDir())) | ||
.ignorePermissions(valueProvider.getBoolean(ASSEMBLY_IGNORE_PERMISSIONS, config == null ? null : config.getIgnorePermissions())) | ||
.permissions(valueProvider.getString(ASSEMBLY_PERMISSIONS, config == null ? null : config.getPermissionsRaw())) | ||
.permissions(valueProvider.getString(ASSEMBLY_PERMISSIONS, config == null ? null : config.getPermissions() != null ? config.getPermissions().name() : null)) |
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.
.user(valueProvider.getString(ASSEMBLY_USER, config == null ? null : config.getUser())) | ||
.mode(valueProvider.getString(ASSEMBLY_MODE, config == null ? null : config.getModeRaw())) | ||
.mode(valueProvider.getString(ASSEMBLY_MODE, config == null ? null : config.getMode() != null ? config.getMode().name() : null)) |
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.
Logger log) { | ||
// Init and validate configs. After this step, getResolvedImages() contains the valid configuration. | ||
for (ImageConfiguration imageConfiguration : images) { | ||
apiVersion = EnvUtil.extractLargerVersion(apiVersion, imageConfiguration.initAndValidate(nameFormatter, log)); | ||
for (String version : imageConfiguration.validate(nameFormatter)) |
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.
@@ -118,11 +122,12 @@ public static String getExternalConfigActivationProperty(MavenProject project) { | |||
* @param log a logger for printing out diagnostic messages | |||
* @return the minimal API Docker API required to be used for the given configuration. | |||
*/ | |||
public static String initAndValidate(List<ImageConfiguration> images, String apiVersion, NameFormatter nameFormatter, | |||
public static String initAndValidate(List<ImageConfiguration> images, String apiVersion, ImageConfiguration.NameFormatter nameFormatter, | |||
Logger log) { |
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.
* @param finalCustomizer finalCustomizer to be applied to the tar archive | ||
* @return file holding the path to the created assembly tar file | ||
* @throws MojoExecutionException | ||
*/ | ||
public File createDockerTarArchive(String imageName, final MojoParameters params, final BuildImageConfiguration buildConfig, Logger log, ArchiverCustomizer finalCustomizer) | ||
throws MojoExecutionException { | ||
public File createDockerTarArchive(String imageName, final MavenBuildContext context, final BuildConfiguration buildConfig, ArchiverCustomizer finalCustomizer, Logger log) |
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.
@@ -202,7 +183,7 @@ private void interpolateDockerfile(File dockerFile, BuildDirs params, FixedStrin | |||
} | |||
|
|||
// visible for testing | |||
void verifyGivenDockerfile(File dockerFile, BuildImageConfiguration buildConfig, FixedStringSearchInterpolator interpolator, Logger log) throws IOException { | |||
void verifyGivenDockerfile(File dockerFile, BuildConfiguration buildConfig, Function<String, String> interpolator, Logger log) throws IOException { |
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.
@@ -65,13 +63,13 @@ | |||
private BuildImageSelectMode sourceMode = BuildImageSelectMode.first; | |||
|
|||
@Override | |||
protected void executeInternal(ServiceHub hub) throws DockerAccessException, MojoExecutionException { | |||
MojoParameters params = createMojoParameters(); | |||
protected void executeInternal(ServiceHub hub) throws IOException { |
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.
private String postExec; | ||
|
||
public WatchImageConfiguration() {}; | ||
public WatchConfiguration() {}; |
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.
private Integer time; | ||
|
||
/** | ||
* @deprecated Use <http><url></url></http> instead | ||
*/ | ||
@Parameter | ||
private String url; |
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.
Add the missing @deprecated annotation.
Do not forget to remove this deprecated code someday.
package io.fabric8.maven.docker.config.build; | ||
|
||
/* | ||
* | ||
* Copyright 2014 Roland Huss | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); |
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.
@@ -327,25 +329,33 @@ private void startImage(final ImageConfiguration imageConfig, | |||
return ret; | |||
} | |||
|
|||
|
|||
// Prepare start like creating custom networks, auto pull images, map aliases and return the list of images | |||
// to start in the correct order | |||
private Queue<ImageConfiguration> prepareStart(ServiceHub hub, QueryService queryService, RunService runService, Set<String> imageAliases) |
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.
if (!runConfig.getNetworkingConfig().isCustomNetwork() && runConfig.getLinks() != null) { | ||
runConfig.getLinks() | ||
.stream() | ||
.map(s -> !s.contains(":") ? s : s.substring(0, s.lastIndexOf(":"))) |
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.
@Test | ||
public void testEmpty() throws Exception { | ||
setupDefaultAuthConfigFactory(); | ||
executeWithTempHomeDir(homeDir -> assertEquals(factory.createAuthConfig(kind, null, "blubberbla:1611"), RegistryAuth.EMPTY_REGISTRY_AUTH)); |
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.
|
||
executeWithTempHomeDir(homeDir -> { | ||
setupServers(); | ||
assertEquals(factory.createAuthConfig(kind, "roland", "another.repo.org"), RegistryAuth.EMPTY_REGISTRY_AUTH); |
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.
@@ -0,0 +1,95 @@ | |||
package io.fabric8.maven.docker.build.maven; | |||
|
|||
import java.util.Optional; |
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.
public class RegistryAuthConfig { | ||
|
||
private Map<String, Map<String, String>> handlerConfig = new HashMap<>(); | ||
private Map<Kind, Map<String, String>> kindConfig = new HashMap<>(); |
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.
try { | ||
JsonObject creds = new GetCommand().getCredentialNode(registryToLookup); | ||
if (creds == null) { | ||
creds = new GetCommand().getCredentialNode(EnvUtil.ensureRegistryHttpUrl(registryToLookup)); | ||
} | ||
return toAuthConfig(creds); | ||
} catch (IOException e) { | ||
throw new MojoExecutionException("Error getting the credentials for " + registryToLookup + " from the configured credential helper",e); | ||
throw new RuntimeException("Error getting the credentials for " + registryToLookup + " from the configured credential helper",e); |
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.
try { | ||
return new VersionCommand().getVersion(); | ||
} catch (IOException e) { | ||
throw new MojoExecutionException("Error getting the version of the configured credential helper",e); | ||
throw new RuntimeException("Error getting the version of the configured credential helper",e); |
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.
String useOpenAuthMode = registryAuthConfig.extractFromProperties(props, kind, AUTH_USE_OPENSHIFT_AUTH); | ||
// Check for system property | ||
if (useOpenAuthMode != null) { | ||
boolean useOpenShift = Boolean.valueOf(useOpenAuthMode); |
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.
|
||
import java.io.Serializable; | ||
import java.util.Map; | ||
import java.util.TreeMap; |
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.
*/ | ||
public class RegistryAuth { | ||
|
||
public final static RegistryAuth EMPTY_REGISTRY_AUTH = |
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.
new RegistryAuth.Builder().username("").password("").email("").auth("").build(); | ||
|
||
public static final String USERNAME = "username"; | ||
public static final String PASSWORD = "password"; |
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.
public static final String EMAIL = "email"; | ||
public static final String AUTH = "authToken"; | ||
|
||
private String username, password, email, auth, authEncoded; |
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.
Rename field "username" to prevent any misunderstanding/clash with field "USERNAME" defined on line 22.
Rename field "password" to prevent any misunderstanding/clash with field "PASSWORD" defined on line 23.
Rename field "email" to prevent any misunderstanding/clash with field "EMAIL" defined on line 24.
Rename field "auth" to prevent any misunderstanding/clash with field "AUTH" defined on line 25.
Declare "password" on a separate line.
Declare "email" on a separate line.
Declare "auth" on a separate line.
Declare "authEncoded" on a separate line.
|
||
// ====================================================================================================== | ||
|
||
private String createAuthEncoded() { |
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.
private RegistryAuth extractAuthConfigFromDocker(JsonObject dockerConfig, String registry) { | ||
String registryToLookup = registry != null ? registry : DOCKER_LOGIN_DEFAULT_REGISTRY; | ||
|
||
if (dockerConfig.has("credHelpers") || dockerConfig.has("credsStore")) { |
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.
SonarQube analysis reported 153 issues Watch the comments in this conversation to review them. Top 10 extra issuesNote: The following issues were found on lines that were not modified in the pull request. Because these issues can't be reported as line comments, they are summarized here:
|
1898156
to
9969472
Compare
…c parts. This is part of a larger refactoring story described in fabric8io#1115.
9969472
to
90e9dbd
Compare
No description provided.