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

Use docker.skip.tag property on push and remove #954

Merged
merged 2 commits into from
Apr 3, 2018
Merged
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 doc/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* **0.24-SNAPSHOT**
- Fix possible NPE when logging to a file and the parent directory does not exist yet (#911) (#940)
- Change content type to "application/json" when talking to the Docker daemon (#945)
- Use docker.skip.tag property on push and remove (#954) ([#869](https://github.com/fabric8io/docker-maven-plugin/issues/869))
- Property placeholders are not interpolated when they are the only thing in the XML element value (#960)
- Fix deadlock waiting on docker log pattern to match (#767, #981, #947)

Expand Down
11 changes: 10 additions & 1 deletion src/main/asciidoc/inc/_docker-remove.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
This goal can be used to clean up images and containers. By default all images with a build configuration are removed.
You can tune this by setting the property `removeMode` (property: `docker.removeMode`) to one of the following values:

[[config-image-build]]
.removeMode Values
[cols="1,5"]
|===
Expand Down Expand Up @@ -34,3 +33,13 @@ Considering three images 'db','tomcat' and 'data' where 'data' is the only image
* `mvn -Ddocker.removeMode=all {plugin}:remove` will remove all three images
* `mvn -Ddocker.filter=data,tomcat {plugin}:remove` will remove 'data'
* `mvn -Ddocker.filter=data,tomcat -Ddocker.removeMode=all {plugin}:remove` will remove 'data' and 'tomcat'

.Remove options
[cols="1,5,1"]
|===
| Element | Description | Property

| *skipTag*
| If set to `true` this plugin won't remove any tags
| `docker.skip.tag`
|===
4 changes: 3 additions & 1 deletion src/main/asciidoc/inc/_global-configuration.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ By default a progress meter is printed out on the console, which is omitted when
| `docker.skip.run`

| *skipTag*
| If set to `true` this plugin won't add any tags to images that have been built with `{plugin}:build`
| If set to `true` this plugin won't add any tags to images that have been built with `{plugin}:build`. +
If set to `true` this plugin won't push any tags with `{plugin}:push`. +
If set to `true` this plugin won't remove any tags with `{plugin}:remove`. +
| `docker.skip.tag`

| *skipMachine*
Expand Down
3 changes: 3 additions & 0 deletions src/main/asciidoc/inc/build/_configuration.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ A provided `<from>` takes precedence over the name given here. This tag is usefu
| *skip*
| if set to true disables building of the image. This config option is best used together with a maven property

| *skipTag*
| If set to `true` this plugin won't add any tags to images. Property: `docker.skip.tag`

| *tags*
| List of additional `tag` elements with which an image is to be tagged after the build. Whitespace is trimmed from each element and empty elements are ignored.

Expand Down
4 changes: 4 additions & 0 deletions src/main/asciidoc/inc/push/_configuration.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
| If set to `true` the plugin won't push any images that have been built.
| `docker.skip.push`

| *skipTag*
| If set to `true` this plugin won't push any tags
| `docker.skip.tag`

| *pushRegistry*
| The registry to use when pushing the image. See <<registry,Registry Handling>> for
more details.
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/io/fabric8/maven/docker/BuildMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import io.fabric8.maven.docker.service.ImagePullManager;
import io.fabric8.maven.docker.service.ServiceHub;
import io.fabric8.maven.docker.util.EnvUtil;
import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
Expand All @@ -25,11 +24,14 @@
@Mojo(name = "build", defaultPhase = LifecyclePhase.INSTALL)
public class BuildMojo extends AbstractBuildSupportMojo {

@Parameter(property = "docker.skip.tag", defaultValue = "false")
private boolean skipTag;

@Parameter(property = "docker.skip.build", defaultValue = "false")
protected boolean skipBuild;

/**
* Skip building tags
*/
@Parameter(property = "docker.skip.tag", defaultValue = "false")
protected boolean skipTag;

@Override
protected void executeInternal(ServiceHub hub) throws DockerAccessException, MojoExecutionException {
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/io/fabric8/maven/docker/PushMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ public class PushMojo extends AbstractDockerMojo {

@Parameter(property = "docker.skip.push", defaultValue = "false")
private boolean skipPush;


/**
* Skip building tags
*/
@Parameter(property = "docker.skip.tag", defaultValue = "false")
private boolean skipTag;

@Parameter(property = "docker.push.retries", defaultValue = "0")
private int retries;

Expand All @@ -35,6 +41,6 @@ public void executeInternal(ServiceHub hub) throws DockerAccessException, MojoEx
return;
}

hub.getRegistryService().pushImages(getResolvedImages(), retries, getRegistryConfig(pushRegistry));
hub.getRegistryService().pushImages(getResolvedImages(), retries, getRegistryConfig(pushRegistry), skipTag);
}
}
18 changes: 13 additions & 5 deletions src/main/java/io/fabric8/maven/docker/RemoveMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
import io.fabric8.maven.docker.config.ImageConfiguration;
import io.fabric8.maven.docker.service.QueryService;
import io.fabric8.maven.docker.service.ServiceHub;
import io.fabric8.maven.docker.util.ImageName;

import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

Expand Down Expand Up @@ -52,7 +52,13 @@ public class RemoveMojo extends AbstractDockerMojo {

@Parameter(property = "docker.removeMode")
private String removeMode;


/**
* Skip building tags
*/
@Parameter(property = "docker.skip.tag", defaultValue = "false")
private boolean skipTag;

@Override
protected void executeInternal(ServiceHub hub) throws DockerAccessException {
for (ImageConfiguration image : getResolvedImages()) {
Expand All @@ -61,9 +67,11 @@ protected void executeInternal(ServiceHub hub) throws DockerAccessException {
if (imageShouldBeRemoved(image)) {
removeImage(hub, name);

// Remove any tagged images
for (String tag: getImageBuildTags(image)){
removeImage(hub, name + ":" + tag);
if(!skipTag) {
// Remove any tagged images
for (String tag: getImageBuildTags(image)){
removeImage(hub, new ImageName(name, tag).getFullName());
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ public class RegistryService {
* @param imageConfigs images to push (but only if they have a build configuration)
* @param retries how often to retry
* @param registryConfig a global registry configuration
* @param skipTag flag to skip pushing tagged images
* @throws DockerAccessException
* @throws MojoExecutionException
*/
public void pushImages(Collection<ImageConfiguration> imageConfigs,
int retries, RegistryConfig registryConfig) throws DockerAccessException, MojoExecutionException {
int retries, RegistryConfig registryConfig, boolean skipTag) throws DockerAccessException, MojoExecutionException {
for (ImageConfiguration imageConfig : imageConfigs) {
BuildImageConfiguration buildConfig = imageConfig.getBuildConfiguration();
String name = imageConfig.getName();
Expand All @@ -58,9 +59,11 @@ public void pushImages(Collection<ImageConfiguration> imageConfigs,
docker.pushImage(name, authConfig, configuredRegistry, retries);
log.info("Pushed %s in %s", name, EnvUtil.formatDurationTill(start));

for (String tag : imageConfig.getBuildConfiguration().getTags()) {
if (tag != null) {
docker.pushImage(new ImageName(name, tag).getFullName(), authConfig, configuredRegistry, retries);
if (!skipTag) {
for (String tag : imageConfig.getBuildConfiguration().getTags()) {
if (tag != null) {
docker.pushImage(new ImageName(name, tag).getFullName(), authConfig, configuredRegistry, retries);
}
}
}
}
Expand Down