Skip to content

Commit

Permalink
Allow runCmds to change user.
Browse files Browse the repository at this point in the history
As discussed in #913 (comment), except the user tag is not limited to the first entry.
A user tag will however disable the optimize option.

Signed-off-by: Jens Andersen <[email protected]>
  • Loading branch information
JensGroenborgAndersen committed Mar 19, 2024
1 parent fc53963 commit 3ecaead
Show file tree
Hide file tree
Showing 25 changed files with 390 additions and 196 deletions.
4 changes: 3 additions & 1 deletion src/main/asciidoc/inc/build/_configuration.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ a| Scan the archive specified in `dockerArchive` and find the actual repository
| Shell to be used for the *runCmds*. It contains *arg* elements which are defining the executable and its params.

| *runCmds*
| Commands to be run during the build process. It contains *run* elements which are passed to the shell. Whitespace is trimmed from each element and empty elements are ignored. The run commands are inserted right after the assembly and after *workdir* into the Dockerfile. This tag is not to be confused with the `<run>` section for this image which specifies the runtime behaviour when starting containers.
| Commands to be run during the build process. It contains *run* elements which are passed to the shell. You may also change user with a *user* element, but beware this will overwrite default user from the parent image, so you should supply a user for the image if you do. Whitespace is trimmed from each element and empty elements are ignored. The run commands are inserted right after the assembly and after *workdir* into 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
Expand Down Expand Up @@ -181,6 +181,8 @@ remote API.
<runCmds>
<run>groupadd -r appUser</run>
<run>useradd -r -g appUser appUser</run>
<user>appUser</user
<run>id</run>
</runCmds>
<entryPoint>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/fabric8/maven/docker/BuildMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* @author roland
* @since 28.07.14
*/
@Mojo(name = "build", defaultPhase = LifecyclePhase.INSTALL, requiresDependencyResolution = ResolutionScope.TEST)
@Mojo(name = "build", defaultPhase = LifecyclePhase.INSTALL, requiresDependencyResolution = ResolutionScope.TEST, configurator = "fabric8-mojo-configurator")
public class BuildMojo extends AbstractBuildSupportMojo {

public static final String DMP_PLUGIN_DESCRIPTOR = "META-INF/maven/io.fabric8/dmp-plugin";
Expand Down
29 changes: 14 additions & 15 deletions src/main/java/io/fabric8/maven/docker/CopyMojo.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
package io.fabric8.maven.docker;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Properties;
import java.util.regex.Matcher;

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

import io.fabric8.maven.docker.access.DockerAccess;
import io.fabric8.maven.docker.config.CopyConfiguration;
import io.fabric8.maven.docker.config.CopyConfiguration.Entry;
Expand All @@ -28,6 +14,19 @@
import io.fabric8.maven.docker.util.ContainerNamingUtil;
import io.fabric8.maven.docker.util.GavLabel;
import io.fabric8.maven.docker.util.Logger;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Properties;
import java.util.regex.Matcher;

/**
* <p>Mojo for copying file or directory from container.<p/>
Expand All @@ -41,7 +40,7 @@
* matching images configured in the project are searched and the copying is performed from the found containers
* only.</p>
*/
@Mojo(name = "copy", defaultPhase = LifecyclePhase.POST_INTEGRATION_TEST)
@Mojo(name = "copy", defaultPhase = LifecyclePhase.POST_INTEGRATION_TEST, configurator = "fabric8-mojo-configurator")
public class CopyMojo extends AbstractDockerMojo {

private static final String COPY_NAME_PATTERN_CONFIG = "copyNamePattern";
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/fabric8/maven/docker/LogsMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* @since 26.03.14
*
*/
@Mojo(name = "logs")
@Mojo(name = "logs", configurator = "fabric8-mojo-configurator")
public class LogsMojo extends AbstractDockerMojo {

// Whether to log infinitely or to show only the logs happened until now.
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/io/fabric8/maven/docker/PushMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import io.fabric8.maven.docker.access.DockerAccessException;
import io.fabric8.maven.docker.service.JibBuildService;
import io.fabric8.maven.docker.service.ServiceHub;

import io.fabric8.maven.docker.util.MojoParameters;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
Expand All @@ -15,7 +14,7 @@
*
* @author roland
*/
@Mojo(name = "push", defaultPhase = LifecyclePhase.DEPLOY)
@Mojo(name = "push", defaultPhase = LifecyclePhase.DEPLOY, configurator = "fabric8-mojo-configurator")
public class PushMojo extends AbstractDockerMojo {

// Registry to use for push operations if no registry is specified
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/io/fabric8/maven/docker/RemoveMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
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.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
Expand All @@ -46,7 +45,7 @@
* @since 23.10.14
*
*/
@Mojo(name = "remove", defaultPhase = LifecyclePhase.POST_INTEGRATION_TEST)
@Mojo(name = "remove", defaultPhase = LifecyclePhase.POST_INTEGRATION_TEST, configurator = "fabric8-mojo-configurator")
public class RemoveMojo extends AbstractDockerMojo {

private static final String REMOVE_NAME_PATTERN_CONFIG = "removeNamePattern";
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/fabric8/maven/docker/RunMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* @author roland
* @since 26/04/16
*/
@Mojo(name = "run", defaultPhase = LifecyclePhase.PRE_INTEGRATION_TEST)
@Mojo(name = "run", defaultPhase = LifecyclePhase.PRE_INTEGRATION_TEST, configurator = "fabric8-mojo-configurator")
public class RunMojo extends StartMojo {

@Override
Expand Down
17 changes: 8 additions & 9 deletions src/main/java/io/fabric8/maven/docker/SaveMojo.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package io.fabric8.maven.docker;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

import io.fabric8.maven.docker.access.DockerAccessException;
import io.fabric8.maven.docker.config.ArchiveCompression;
import io.fabric8.maven.docker.config.ImageConfiguration;
import io.fabric8.maven.docker.service.ServiceHub;
import io.fabric8.maven.docker.util.EnvUtil;
import io.fabric8.maven.docker.util.ImageName;
import org.apache.maven.plugin.MojoExecutionException;
Expand All @@ -14,11 +12,12 @@
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProjectHelper;

import io.fabric8.maven.docker.access.DockerAccessException;
import io.fabric8.maven.docker.config.ImageConfiguration;
import io.fabric8.maven.docker.service.ServiceHub;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

@Mojo(name = "save")
@Mojo(name = "save", configurator = "fabric8-mojo-configurator")
public class SaveMojo extends AbstractDockerMojo {

// Used when not automatically determined
Expand Down
13 changes: 6 additions & 7 deletions src/main/java/io/fabric8/maven/docker/SourceMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,23 @@
* limitations under the License.
*/

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import io.fabric8.maven.docker.access.DockerAccessException;
import io.fabric8.maven.docker.config.BuildImageConfiguration;
import io.fabric8.maven.docker.config.ImageConfiguration;
import io.fabric8.maven.docker.config.BuildImageSelectMode;
import io.fabric8.maven.docker.config.ImageConfiguration;
import io.fabric8.maven.docker.service.ServiceHub;
import io.fabric8.maven.docker.util.MojoParameters;

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProjectHelper;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
* Mojo for attaching one more source docker tar file to an artifact.
*
Expand All @@ -44,7 +43,7 @@
* @author roland
* @since 25/10/15
*/
@Mojo(name = "source", defaultPhase = LifecyclePhase.PACKAGE)
@Mojo(name = "source", defaultPhase = LifecyclePhase.PACKAGE, configurator = "fabric8-mojo-configurator")
public class SourceMojo extends AbstractBuildSupportMojo {

@Component
Expand Down
34 changes: 17 additions & 17 deletions src/main/java/io/fabric8/maven/docker/StartMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,6 @@
* the License.
*/

import java.io.IOException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Properties;
import java.util.Queue;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorCompletionService;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

import com.google.common.util.concurrent.MoreExecutors;
import io.fabric8.maven.docker.access.DockerAccessException;
import io.fabric8.maven.docker.access.ExecException;
Expand All @@ -46,13 +30,29 @@
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

import java.io.IOException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Properties;
import java.util.Queue;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorCompletionService;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;


/**
* Goal for creating and starting a docker container. This goal evaluates the image configuration
*
* @author roland
*/
@Mojo(name = "start", defaultPhase = LifecyclePhase.PRE_INTEGRATION_TEST)
@Mojo(name = "start", defaultPhase = LifecyclePhase.PRE_INTEGRATION_TEST, configurator = "fabric8-mojo-configurator")
public class StartMojo extends AbstractDockerMojo {

@Parameter(property = "docker.showLogs")
Expand Down
33 changes: 16 additions & 17 deletions src/main/java/io/fabric8/maven/docker/StopMojo.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,5 @@
package io.fabric8.maven.docker;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

import io.fabric8.maven.docker.access.DockerAccessException;
import io.fabric8.maven.docker.access.ExecException;
import io.fabric8.maven.docker.config.ImageConfiguration;
Expand All @@ -28,6 +12,21 @@
import io.fabric8.maven.docker.service.ServiceHub;
import io.fabric8.maven.docker.util.ContainerNamingUtil;
import io.fabric8.maven.docker.util.GavLabel;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;


/**
Expand All @@ -43,7 +42,7 @@
* @since 26.03.14
*
*/
@Mojo(name = "stop", defaultPhase = LifecyclePhase.POST_INTEGRATION_TEST)
@Mojo(name = "stop", defaultPhase = LifecyclePhase.POST_INTEGRATION_TEST, configurator = "fabric8-mojo-configurator")
public class StopMojo extends AbstractDockerMojo {

private static final String STOP_NAME_PATTERN_CONFIG = "stopNamePattern";
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/fabric8/maven/docker/TagMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* Goal for Tagging an image so that it becomes part of a repository.
*
*/
@Mojo(name = "tag", defaultPhase = LifecyclePhase.INSTALL)
@Mojo(name = "tag", defaultPhase = LifecyclePhase.INSTALL, configurator = "fabric8-mojo-configurator")
public class TagMojo extends AbstractDockerMojo {
@Parameter(property = "docker.skip.tag", defaultValue = "false")
private boolean skipTag;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* @author Tom Burton
* @version Dec 15, 2016
*/
@Mojo(name = "volume-create", defaultPhase = LifecyclePhase.PRE_INTEGRATION_TEST)
@Mojo(name = "volume-create", defaultPhase = LifecyclePhase.PRE_INTEGRATION_TEST, configurator = "fabric8-mojo-configurator")
public class VolumeCreateMojo extends AbstractDockerMojo {

@Override
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/io/fabric8/maven/docker/VolumeRemoveMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import io.fabric8.maven.docker.config.VolumeConfiguration;
import io.fabric8.maven.docker.service.ServiceHub;
import io.fabric8.maven.docker.service.VolumeService;

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
Expand All @@ -15,7 +14,7 @@
*
* @author Tom Burton
*/
@Mojo(name = "volume-remove", defaultPhase = LifecyclePhase.POST_INTEGRATION_TEST)
@Mojo(name = "volume-remove", defaultPhase = LifecyclePhase.POST_INTEGRATION_TEST, configurator = "fabric8-mojo-configurator")
public class VolumeRemoveMojo extends AbstractDockerMojo {

@Override
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/io/fabric8/maven/docker/WatchMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
* limitations under the License.
*/

import java.io.IOException;

import io.fabric8.maven.docker.config.WatchMode;
import io.fabric8.maven.docker.service.BuildService;
import io.fabric8.maven.docker.service.ServiceHub;
Expand All @@ -26,6 +24,8 @@
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

import java.io.IOException;

/**
* Mojo for watching source code changes.
*
Expand All @@ -40,7 +40,7 @@
* @author roland
* @since 16/06/15
*/
@Mojo(name = "watch")
@Mojo(name = "watch", configurator = "fabric8-mojo-configurator")
public class WatchMojo extends AbstractBuildSupportMojo {

/**
Expand Down Expand Up @@ -112,4 +112,4 @@ private String showLogs() {
private boolean follow() {
return Boolean.valueOf(System.getProperty("docker.follow", "false"));
}
}
}
Loading

0 comments on commit 3ecaead

Please sign in to comment.