chore(build): Refactor BuildService and separate Maven/Docker specific parts. - #1116
chore(build): Refactor BuildService and separate Maven/Docker specific parts.#1116rhuss wants to merge 8 commits into
Conversation
| throw new MojoExecutionException("Cannot create archive " + archive, e); | ||
| throw new IOException("Cannot create archive " + archive, e); | ||
| } catch (RuntimeException e) { | ||
| e.printStackTrace(); |
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
|
|
||
| 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 |
| @Parameter | ||
| private int retry; | ||
|
|
||
| public RestartPolicy() {}; |
| return soft; | ||
| } | ||
|
|
||
| Pattern ULIMIT_PATTERN = Pattern.compile("^(?<name>[^=]+)=(?<hard>[^:]*):?(?<soft>[^:]*)$"); |
| return new BZip2CompressorOutputStream(out); | ||
| } | ||
| }; | ||
| none("tar"), |
| } | ||
| }; | ||
| none("tar"), | ||
| gzip("tar.gz"), |
| }; | ||
| none("tar"), | ||
| gzip("tar.gz"), | ||
| bzip2("tar.bz"); |
| private File dockerFileFile, dockerArchiveFile; | ||
|
|
||
| public BuildImageConfiguration() {} | ||
| public BuildConfiguration() {} |
| } | ||
|
|
||
| public String initAndValidate(Logger log) throws IllegalArgumentException { | ||
| public String validate() throws IllegalArgumentException { |
| return build; | ||
| } | ||
|
|
||
| public static class Builder extends ImageConfiguration.Builder { |
| return nocache.length() == 0 || Boolean.valueOf(nocache); | ||
| } else { | ||
| BuildConfiguration buildConfig = imageConfig.getBuildConfiguration(); | ||
| return buildConfig.getNoCache() != null ? buildConfig.getNoCache() : false; |
| 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 { |
| return inline; | ||
| } | ||
|
|
||
| public static class Builder extends AssemblyConfiguration.Builder { |
| return assembly; | ||
| } | ||
|
|
||
| public static class Builder extends BuildConfiguration.Builder { |
| 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);; |
|
|
||
| private List<ImageConfiguration> convertToPlainImageConfigurations(List<MavenImageConfiguration> images) { | ||
| if (images == null) { | ||
| return null; |
|
|
||
| private RunImageConfiguration extractRunConfiguration(ImageConfiguration fromConfig, ValueProvider valueProvider) { | ||
| RunImageConfiguration config = fromConfig.getRunConfiguration(); | ||
| private RunConfiguration extractRunConfiguration(ImageConfiguration fromConfig, ValueProvider valueProvider) { |
| .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)) |
| .permissions(valueProvider.getString(ASSEMBLY_PERMISSIONS, config == null ? null : config.getPermissions() != null ? config.getPermissions().name() : null)) | ||
| .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)) |
| // 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)) |
| */ | ||
| 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) { |
| */ | ||
| 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) |
|
|
||
| // 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 { |
| @Override | ||
| protected void executeInternal(ServiceHub hub) throws DockerAccessException, MojoExecutionException { | ||
| MojoParameters params = createMojoParameters(); | ||
| protected void executeInternal(ServiceHub hub) throws IOException { |
| private String postExec; | ||
|
|
||
| public WatchImageConfiguration() {}; | ||
| public WatchConfiguration() {}; |
| * @deprecated Use <http><url></url></http> instead | ||
| */ | ||
| @Parameter | ||
| private String url; |
There was a problem hiding this comment.


| * | ||
| * Copyright 2014 Roland Huss | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
||
| // 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) |
| import io.fabric8.maven.docker.util.MojoParameters; | ||
| import io.fabric8.maven.docker.util.GavLabel; | ||
| import io.fabric8.maven.docker.util.Logger; | ||
| import io.fabric8.maven.docker.util.StartOrderResolver; |
| if (!runConfig.getNetworkingConfig().isCustomNetwork() && runConfig.getLinks() != null) { | ||
| runConfig.getLinks() | ||
| .stream() | ||
| .map(s -> !s.contains(":") ? s : s.substring(0, s.lastIndexOf(":"))) |
| @Test | ||
| public void testEmpty() throws Exception { | ||
| setupDefaultAuthConfigFactory(); | ||
| executeWithTempHomeDir(homeDir -> assertEquals(factory.createAuthConfig(kind, null, "blubberbla:1611"), RegistryAuth.EMPTY_REGISTRY_AUTH)); |
|
|
||
| executeWithTempHomeDir(homeDir -> { | ||
| setupServers(); | ||
| assertEquals(factory.createAuthConfig(kind, "roland", "another.repo.org"), RegistryAuth.EMPTY_REGISTRY_AUTH); |
| @@ -0,0 +1,95 @@ | |||
| package io.fabric8.maven.docker.build.maven; | |||
|
|
|||
| import java.util.Optional; | |||
| public class RegistryAuthConfig { | ||
|
|
||
| private Map<String, Map<String, String>> handlerConfig = new HashMap<>(); | ||
| private Map<Kind, Map<String, String>> kindConfig = new HashMap<>(); |
| 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); |
| 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); |
| String useOpenAuthMode = registryAuthConfig.extractFromProperties(props, kind, AUTH_USE_OPENSHIFT_AUTH); | ||
| // Check for system property | ||
| if (useOpenAuthMode != null) { | ||
| boolean useOpenShift = Boolean.valueOf(useOpenAuthMode); |
|
|
||
| import java.io.Serializable; | ||
| import java.util.Map; | ||
| import java.util.TreeMap; |
| */ | ||
| public class RegistryAuth { | ||
|
|
||
| public final static RegistryAuth EMPTY_REGISTRY_AUTH = |
| new RegistryAuth.Builder().username("").password("").email("").auth("").build(); | ||
|
|
||
| public static final String USERNAME = "username"; | ||
| public static final String PASSWORD = "password"; |
| 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.








|
|
||
| // ====================================================================================================== | ||
|
|
||
| private String createAuthEncoded() { |
| private RegistryAuth extractAuthConfigFromDocker(JsonObject dockerConfig, String registry) { | ||
| String registryToLookup = registry != null ? registry : DOCKER_LOGIN_DEFAULT_REGISTRY; | ||
|
|
||
| if (dockerConfig.has("credHelpers") || dockerConfig.has("credsStore")) { |
|
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.