public DockerRegistryEndpoint getRegistry() { if (registry == null) { registry = new DockerRegistryEndpoint(null, pullCredentialsId); } return registry; }
private Object readResolve() { if (pushOnSuccess && registry == null) { registry = new DockerRegistryEndpoint(null, null); } return this; } }
/** * For testing * * @param dockerLabel the docker label to use * @param url The registry URL * @param creds the registry credentials ID */ public FolderConfig(String dockerLabel, String url, String creds) { this.dockerLabel = dockerLabel; this.registry = new DockerRegistryEndpoint(url, creds); }
public DockerRegistryEndpoint getRegistry(Identifier identifier) { if (registry == null) { registry = new DockerRegistryEndpoint(null, pushCredentialsId); } return registry; }
public DockerRegistryEndpoint getRegistry() { if (registry == null) { registry = new DockerRegistryEndpoint(null, pullCredentialsId); } return registry; }
private Object readResolve() { if (pushCredentialsId == null && registry != null) { pushCredentialsId = registry.getCredentialsId(); } if (pullCredentialsId != null) { fromRegistry = new DockerRegistryEndpoint(null, pullCredentialsId); } return this; } }
@Override public Step newInstance(Map<String, Object> arguments) throws Exception { arguments = new HashMap<>(arguments); if (arguments.containsKey("url") || arguments.containsKey("credentialsId")) { if (arguments.containsKey("registry")) { throw new IllegalArgumentException("cannot mix url/credentialsId with registry"); } arguments.put("registry", new DockerRegistryEndpoint((String) arguments.remove("url"), (String) arguments.remove("credentialsId"))); } else if (!arguments.containsKey("registry")) { throw new IllegalArgumentException("must specify url/credentialsId (or registry)"); } return super.newInstance(arguments); }
@DataBoundConstructor public DockerBuilder(String repoName) { this.server = new DockerServerEndpoint(null, null); this.registry = new DockerRegistryEndpoint(null, null); this.repoName = repoName; }
/** * Parse the registry endpoint out of a registry:port/namespace/name:tag string as created by * {@link #imageName(String)}. Credentials are set to the id passed. The url is built from registry:port into * https://registry:port, the same way docker push does. * * @param s * @param credentialsId * passed to the constructor, can be null * @throws IllegalArgumentException * if string can't be parsed * @return The DockerRegistryEndpoint corresponding to the registry:port part of the string */ public static DockerRegistryEndpoint fromImageName(String s, @CheckForNull String credentialsId) { Matcher matcher = DOCKER_REGISTRY_PATTERN.matcher(s); if (!matcher.matches() || matcher.groupCount() < 7) { throw new IllegalArgumentException(s + " does not match regex " + DOCKER_REGISTRY_PATTERN); } String url; try { // docker push always uses https url = matcher.group(2) == null ? null : new URL("https://" + matcher.group(2)).toString(); } catch (MalformedURLException e) { throw new IllegalArgumentException(s + " can not be parsed as URL: " + e.getMessage()); } // not used, but could be /*String namespace = matcher.group(4); String repoName = matcher.group(5); String tag = matcher.group(7);*/ return new DockerRegistryEndpoint(url, credentialsId); }
/** * Parse the registry endpoint out of a registry:port/namespace/name:tag string as created by * {@link #imageName(String)}. Credentials are set to the id passed. The url is built from registry:port into * https://registry:port, the same way docker push does. * * @param s * @param credentialsId * passed to the constructor, can be null * @throws IllegalArgumentException * if string can't be parsed * @return The DockerRegistryEndpoint corresponding to the registry:port part of the string */ public static DockerRegistryEndpoint fromImageName(String s, @CheckForNull String credentialsId) { Matcher matcher = DOCKER_REGISTRY_PATTERN.matcher(s); if (!matcher.matches() || matcher.groupCount() < 7) { throw new IllegalArgumentException(s + " does not match regex " + DOCKER_REGISTRY_PATTERN); } String url; try { // docker push always uses https url = matcher.group(2) == null ? null : new URL("https://" + matcher.group(2)).toString(); } catch (MalformedURLException e) { throw new IllegalArgumentException(s + " can not be parsed as URL: " + e.getMessage()); } // not used, but could be /*String namespace = matcher.group(4); String repoName = matcher.group(5); String tag = matcher.group(7);*/ return new DockerRegistryEndpoint(url, credentialsId); }
@SuppressWarnings("deprecation") protected Object readResolve() { if (dockerCredentials != null) { this.dockerRegistryEndpoint = new DockerRegistryEndpoint(dockerCredentials.getServerAddress(), dockerCredentials.getCredentialsId()); this.dockerCredentials = null; } return this; }
@DataBoundSetter public void setDockerCredentials(List<DockerRegistryEndpoint> dockerCredentials) { List<DockerRegistryEndpoint> endpoints = new ArrayList<>(); for (DockerRegistryEndpoint endpoint : dockerCredentials) { String credentialsId = org.apache.commons.lang.StringUtils.trimToNull(endpoint.getCredentialsId()); if (credentialsId == null) { // no credentials item is selected, skip this endpoint continue; } String registryUrl = org.apache.commons.lang.StringUtils.trimToNull(endpoint.getUrl()); // null URL results in "https://index.docker.io/v1/" effectively if (registryUrl != null) { // It's common that the user omits the scheme prefix, we add http:// as default. // Otherwise it will cause MalformedURLException when we call endpoint.getEffectiveURL(); if (!Constants.URI_SCHEME_PREFIX.matcher(registryUrl).find()) { registryUrl = "http://" + registryUrl; } } endpoints.add(new DockerRegistryEndpoint(registryUrl, credentialsId)); } this.dockerCredentials = endpoints; }
public Docker(DockerServerEndpoint dockerHost, String dockerInstallation, String credentialsId, AbstractBuild build, Launcher launcher, TaskListener listener, boolean verbose, boolean privileged) throws IOException, InterruptedException { this.dockerHost = dockerHost; this.dockerExecutable = DockerTool.getExecutable(dockerInstallation, Computer.currentComputer().getNode(), listener, build.getEnvironment(listener)); this.registryEndpoint = new DockerRegistryEndpoint(null, credentialsId); this.launcher = launcher; this.listener = listener; this.build = build; this.verbose = verbose | debug; this.privileged = privileged; }
new DockerRegistryEndpoint(registry, pushCredentialsId), run.getParent().getParent()); cmd.exec(resultCallback).awaitSuccess();
@Test public void plainSystemConfig() throws Exception { GlobalConfig.get().setDockerLabel("config_docker"); GlobalConfig.get().setRegistry(new DockerRegistryEndpoint("https://docker.registry", globalCred.getId())); expect("declarativeDockerConfig") .logContains("Docker Label is: config_docker", "Registry URL is: https://docker.registry", "Registry Creds ID is: " + globalCred.getId()).go(); }
@Test public void directParentNotSystem() throws Exception { GlobalConfig.get().setDockerLabel("config_docker"); GlobalConfig.get().setRegistry(new DockerRegistryEndpoint("https://docker.registry", globalCred.getId())); Folder folder = j.createProject(Folder.class); getFolderStore(folder).addCredentials(Domain.global(), folderCred); folder.addProperty(new FolderConfig("folder_docker", "https://folder.registry", folderCred.getId())); expect("declarativeDockerConfig") .inFolder(folder) .runFromRepo(false) .logContains("Docker Label is: folder_docker", "Registry URL is: https://folder.registry", "Registry Creds ID is: " + folderCred.getId()) .logNotContains("Docker Label is: config_docker", "Registry URL is: https://docker.registry", "Registry Creds ID is: " + globalCred.getId()).go(); }