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

#181: Fix bug when authenticating to private registry #220

Closed
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ target/
.classpath
.project
.settings
.*.md.html
7 changes: 7 additions & 0 deletions doc/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# ChangeLog

* **0.13.3**
- Allow dangling images to be cleaned up after build (#20)
- Adapt order of WORKDIR and RUN when building images (#222)
- Allow 'build' and/or 'run' configuration to be skipped (#207)
- Refactored to use 'inspect' instead of 'list' for checking the existence of an image (#230)
- Refactored AppacheHttpClientDelegate to avoid leaking connections (#232)

* **0.13.2**
- "run" directives can be added to the Dockerfile (#191)
- Support user information in wait URL (#211)
Expand Down
4 changes: 2 additions & 2 deletions doc/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ which you can put into your `~/.gitconfig`:
````

When sending pull request we prefer that to be a single commit. So please squash your commits
with an interactive rebase before sending the pull request. And of course your pull request should be
rebased to the current master. All this is nicely explained [here](https://github.com/edx/edx-platform/wiki/How-to-Rebase-a-Pull-Request).
with an interactive rebase before sending the pull request. Also, your pull request should be
rebased to the current branch `integration`. All this is nicely explained [here](https://github.com/edx/edx-platform/wiki/How-to-Rebase-a-Pull-Request).

Said all this, don't hesitate to ask when there are any problems or you have an issue with this process.

23 changes: 13 additions & 10 deletions doc/manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,30 +236,32 @@ of an image configuration. The available subelements are

* **assembly** specifies the assembly configuration as described in
[Build Assembly](#build-assembly)
* **cleanup** indicates if dangling (untagged) images should be cleaned up during each build. Default is `true`
* **cmd** A command to execute by default (i.e. if no command
is provided when a container for this image is started). See
[Start-up Arguments](#start-up-arguments) for details.
* **entrypoint** An entrypoint allows you to configure a container that will run as an executable.
See [Start-up Arguments](#start-up-arguments) for details.
* **workdir** the directory to change to when starting the container.
See [Start-up Arguments](#start-up-arguments) for details.
* **env** holds environments as described in
[Setting Environment Variables and Labels](#setting-environment-variables-and-labels).
* **labels** holds labels as described in
[Setting Environment Variables and Labels](#setting-environment-variables-and-labels).
* **from** specifies the base image which should be used for this
image. If not given this default to `busybox:latest` and is suitable
for a pure data image.
* **labels** holds labels as described in
[Setting Environment Variables and Labels](#setting-environment-variables-and-labels).
* **maintainer** specifies the author (MAINTAINER) field for the generated image
* **ports** describes the exports ports. It contains a list of
`<port>` elements, one for each port to expose.
* **volumes** contains a list of `volume` elements to create a container
volume.
* **tags** contains a list of additional `tag` elements with which an
image is to be tagged after the build.
* **maintainer** specifies the author (MAINTAINER) field for the generated image
* **run** specifies commands to be run during the build process. It contains **run** elements
which are passed to bash. The run commands are inserted right after the assembly but before **workdir** in to the
which are passed to bash. The run commands are inserted right after the assembly and after **workdir** in to the
Dockerfile. This tag is not to be confused with the `<run>` section for this image which specifies the runtime
behaviour when starting containers.
* **skip** if set to true disables building of the image. This config option is best used together with a maven property
* **tags** contains a list of additional `tag` elements with which an
image is to be tagged after the build.
* **volumes** contains a list of `volume` elements to create a container
volume.
* **workdir** the directory to change to when starting the container.

From this configuration this Plugin creates an in-memory Dockerfile,
copies over the assembled files and calls the Docker daemon via its
Expand Down Expand Up @@ -539,6 +541,7 @@ The `<run>` configuration knows the following sub elements:
* **restartPolicy** (*v1.15*) specifies the container restart policy, see
[below](#container-restart-policy)
* **user** (*v1.11*) user used inside the container
* **skip** disable creating and starting of the container. This option is best used together with a configuration option.
* **volumes** for bind configurtion of host directories and from other containers. See "[Volume binding]
(#volume-binding)" for details.
* **wait** specifies condition which must be fulfilled for the startup
Expand Down
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,13 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.10.19</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion samples/data-jolokia-demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

<groupId>org.jolokia</groupId>
<artifactId>docker-jolokia-demo</artifactId>
<version>0.13.2</version>
<version>0.13.3-SNAPSHOT</version>

<url>http://www.jolokia.org</url>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,4 @@
package org.jolokia.docker.maven;/*
*
* Copyright 2014 Roland Huss
*
* 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.
*/

import java.io.File;
package org.jolokia.docker.maven;

import org.apache.maven.archiver.MavenArchiveConfiguration;
import org.apache.maven.execution.MavenSession;
Expand All @@ -33,7 +16,7 @@
* @author roland
* @since 26/06/15
*/
abstract public class AbstractBuildSupporMojo extends AbstractDockerMojo {
abstract public class AbstractBuildSupportMojo extends AbstractDockerMojo {
// ==============================================================================================================
// Parameters required from Maven when building an assembly. They cannot be injected directly
// into DockerAssemblyCreator.
Expand All @@ -50,9 +33,7 @@ abstract public class AbstractBuildSupporMojo extends AbstractDockerMojo {
/** @component */
private MavenReaderFilter mavenFilterReader;

/** @component */
protected DockerAssemblyManager dockerAssemblyManager;


/**
* @parameter default-value="src/main/docker" property="docker.source.dir"
*/
Expand All @@ -76,10 +57,7 @@ protected void buildImage(DockerAccess dockerAccess, String imageName, ImageConf
autoPullBaseImage(dockerAccess, imageConfig);

MojoParameters params = createMojoParameters();
File dockerArchive = dockerAssemblyManager.createDockerTarArchive(imageName, params, imageConfig.getBuildConfiguration());

dockerAccess.buildImage(imageName, dockerArchive);
log.info(imageConfig.getDescription() + ": Build image ");
serviceHub.getBuildService().buildImage(imageConfig, params);
}

private void autoPullBaseImage(DockerAccess dockerAccess, ImageConfiguration imageConfig)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ private DockerAccess createDockerAccess(String baseUrl) throws MojoExecutionExce

return client;
}
catch (IOException | DockerAccessException e) {
catch (IOException e) {
throw new MojoExecutionException("Cannot create docker access object ", e);
}
}
Expand Down
21 changes: 15 additions & 6 deletions src/main/java/org/jolokia/docker/maven/BuildMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* @goal build
* @phase install
*/
public class BuildMojo extends AbstractBuildSupporMojo {
public class BuildMojo extends AbstractBuildSupportMojo {

/**
* @parameter default-value="false" property="docker.skipTags"
Expand All @@ -31,16 +31,25 @@ protected void executeInternal(DockerAccess dockerAccess) throws DockerAccessExc
for (ImageConfiguration imageConfig : getImages()) {
BuildImageConfiguration buildConfig = imageConfig.getBuildConfiguration();
if (buildConfig != null) {
buildConfig.validate();
String imageName = imageConfig.getName();
buildImage(dockerAccess, imageName, imageConfig);
if (!skipTags) {
tagImage(imageName, imageConfig, dockerAccess);
if (buildConfig.skip()) {
log.info(imageConfig.getDescription() + ": Skipped building");
} else {
buildImage(dockerAccess, imageConfig, buildConfig);
}
}
}
}

private void buildImage(DockerAccess dockerAccess, ImageConfiguration imageConfig, BuildImageConfiguration buildConfig)
throws MojoExecutionException, DockerAccessException {
buildConfig.validate();
String imageName = imageConfig.getName();
buildImage(dockerAccess, imageName, imageConfig);
if (!skipTags) {
tagImage(imageName, imageConfig, dockerAccess);
}
}

private void tagImage(String imageName, ImageConfiguration imageConfig, DockerAccess dockerAccess)
throws DockerAccessException, MojoExecutionException {

Expand Down
23 changes: 6 additions & 17 deletions src/main/java/org/jolokia/docker/maven/WatchMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.assembly.InvalidAssemblerConfigurationException;
import org.apache.maven.plugin.assembly.archive.ArchiveCreationException;
import org.apache.maven.plugin.assembly.format.AssemblyFormattingException;
import org.codehaus.plexus.util.StringUtils;
import org.jolokia.docker.maven.access.*;
import org.jolokia.docker.maven.assembly.AssemblyFiles;
import org.jolokia.docker.maven.config.*;
import org.jolokia.docker.maven.service.*;
import org.jolokia.docker.maven.util.*;
import org.jolokia.docker.maven.service.QueryService;
import org.jolokia.docker.maven.service.RunService;
import org.jolokia.docker.maven.util.MojoParameters;
import org.jolokia.docker.maven.util.StartOrderResolver;

import static org.jolokia.docker.maven.config.WatchMode.both;

Expand All @@ -50,7 +49,7 @@
* @author roland
* @since 16/06/15
*/
public class WatchMojo extends AbstractBuildSupporMojo {
public class WatchMojo extends AbstractBuildSupportMojo {

/** @parameter property = "docker.watchMode" default-value="both" **/
private WatchMode watchMode;
Expand Down Expand Up @@ -137,7 +136,7 @@ private Runnable createBuildWatchTask(final DockerAccess docker, final ImageWatc
throws MojoExecutionException {
final ImageConfiguration imageConfig = watcher.getImageConfiguration();
final String name = imageConfig.getName();
final AssemblyFiles files = getAssemblyFiles(name, imageConfig.getBuildConfiguration(), mojoParameters);
final AssemblyFiles files = serviceHub.getBuildService().getAssemblyFiles(name, imageConfig, mojoParameters);
return new Runnable() {
@Override
public void run() {
Expand Down Expand Up @@ -185,16 +184,6 @@ public void run() {
};
}

private AssemblyFiles getAssemblyFiles(String name, BuildImageConfiguration buildConfiguration, MojoParameters mojoParameters)
throws MojoExecutionException {
try {
return dockerAssemblyManager.getAssemblyFiles(name, buildConfiguration, mojoParameters);
} catch (InvalidAssemblerConfigurationException | ArchiveCreationException | AssemblyFormattingException e) {
throw new MojoExecutionException("Cannot extract assembly files for image " + name + ": " + e,e);
}
}


private void restartContainer(ImageWatcher watcher) throws DockerAccessException {
// Stop old one
RunService runService = serviceHub.getRunService();
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/org/jolokia/docker/maven/access/AuthConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,21 @@
*/
public class AuthConfig {

public final static AuthConfig EMPTY_AUTH_CONFIG = new AuthConfig("", "", "", "");
public final static AuthConfig EMPTY_AUTH_CONFIG = new AuthConfig("", "", "", "", "");

private Map<String,String> params;

public AuthConfig(Map<String,String> params) {
this.params = params;
}

public AuthConfig(String user, String password, String email,String auth) {
public AuthConfig(String user, String password, String email, String auth, String registry) {
params = new HashMap<>();
putNonNull(params, "username", user);
putNonNull(params, "password", password);
putNonNull(params, "email", email);
putNonNull(params, "auth", auth);
putNonNull(params, "serveraddress", registry);
}

public String toHeaderValue() {
Expand All @@ -38,6 +39,7 @@ public String toHeaderValue() {
add(ret,"password");
add(ret,"email");
add(ret,"auth");
add(ret,"serveraddress");
try {
return Base64.encodeBase64String(ret.toString().getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) {
Expand Down
53 changes: 17 additions & 36 deletions src/main/java/org/jolokia/docker/maven/access/DockerAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,30 @@ public interface DockerAccess {
*/
Container inspectContainer(String containerId) throws DockerAccessException;

/**
* Check whether the given name exists as image at the docker daemon
*
* @param name image name to check
* @return true if the image exists
*/
boolean hasImage(String name) throws DockerAccessException;

/**
* List images
*
* @param args optional list images args
* @return list of <code>Image<code>objects
* @throws DockerAccessException if the images could not be listed
* Get the image id of a given name or <code>null</code> if no such image exists
*
* @param name name to lookup
* @return the image id or <code>null</code>
*/
List<Image> listImages(ListArg... args) throws DockerAccessException;
String getImageId(String name) throws DockerAccessException;

/**
* List containers
*
* @param args optional list containers args
* @param limit limit of containers to list
* @return list of <code>Container<code> objects
* @throws DockerAccessException if the containers could not be listed
*/
List<Container> listContainers(ListArg... args) throws DockerAccessException;
List<Container> listContainers(int limit) throws DockerAccessException;

/**
* Create a container from the given image.
Expand Down Expand Up @@ -139,9 +145,10 @@ public interface DockerAccess {
*
* @param image name of the image to build or <code>null</code> if none should be used
* @param dockerArchive from which the docker image should be build
* @param forceRemove whether to remove intermediate containers
* @throws DockerAccessException if docker host reports an error during building of an image
*/
void buildImage(String image, File dockerArchive) throws DockerAccessException;
void buildImage(String image, File dockerArchive, boolean forceRemove) throws DockerAccessException;

/**
* Alias an image in the repository with a complete new name. (Note that this maps to a Docker Remote API 'tag'
Expand Down Expand Up @@ -174,30 +181,4 @@ public interface DockerAccess {
* cleaning up things.
*/
void shutdown();

class ListArg {
private final String key;
private final String value;

private ListArg(String key, String value) {
this.key = key;
this.value = value;
}

public String getKey() {
return key;
}

public String getValue() {
return value;
}

public static ListArg filter(String value) {
return new ListArg("filter", value);
}

public static ListArg limit(int value) {
return new ListArg("limit", String.valueOf(value));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package org.jolokia.docker.maven.access;

import java.io.IOException;

/**
* Exception thrown if access to the docker host fails
*
* @author roland
* @since 20.10.14
*/
public class DockerAccessException extends Exception {
public class DockerAccessException extends IOException {

/**
* Constructor
Expand Down
Loading