Skip to content

Commit 3ecaead

Browse files
Allow runCmds to change user.
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]>
1 parent fc53963 commit 3ecaead

25 files changed

+390
-196
lines changed

src/main/asciidoc/inc/build/_configuration.adoc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ a| Scan the archive specified in `dockerArchive` and find the actual repository
121121
| Shell to be used for the *runCmds*. It contains *arg* elements which are defining the executable and its params.
122122

123123
| *runCmds*
124-
| 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.
124+
| 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.
125125

126126
| *skip*
127127
| if set to true disables building of the image. This config option is best used together with a maven property
@@ -181,6 +181,8 @@ remote API.
181181
<runCmds>
182182
<run>groupadd -r appUser</run>
183183
<run>useradd -r -g appUser appUser</run>
184+
<user>appUser</user
185+
<run>id</run>
184186
</runCmds>
185187
186188
<entryPoint>

src/main/java/io/fabric8/maven/docker/BuildMojo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
* @author roland
3434
* @since 28.07.14
3535
*/
36-
@Mojo(name = "build", defaultPhase = LifecyclePhase.INSTALL, requiresDependencyResolution = ResolutionScope.TEST)
36+
@Mojo(name = "build", defaultPhase = LifecyclePhase.INSTALL, requiresDependencyResolution = ResolutionScope.TEST, configurator = "fabric8-mojo-configurator")
3737
public class BuildMojo extends AbstractBuildSupportMojo {
3838

3939
public static final String DMP_PLUGIN_DESCRIPTOR = "META-INF/maven/io.fabric8/dmp-plugin";

src/main/java/io/fabric8/maven/docker/CopyMojo.java

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,5 @@
11
package io.fabric8.maven.docker;
22

3-
import java.io.File;
4-
import java.io.IOException;
5-
import java.nio.file.Files;
6-
import java.util.Collection;
7-
import java.util.Collections;
8-
import java.util.List;
9-
import java.util.Properties;
10-
import java.util.regex.Matcher;
11-
12-
import org.apache.maven.plugin.MojoExecutionException;
13-
import org.apache.maven.plugins.annotations.LifecyclePhase;
14-
import org.apache.maven.plugins.annotations.Mojo;
15-
import org.apache.maven.plugins.annotations.Parameter;
16-
173
import io.fabric8.maven.docker.access.DockerAccess;
184
import io.fabric8.maven.docker.config.CopyConfiguration;
195
import io.fabric8.maven.docker.config.CopyConfiguration.Entry;
@@ -28,6 +14,19 @@
2814
import io.fabric8.maven.docker.util.ContainerNamingUtil;
2915
import io.fabric8.maven.docker.util.GavLabel;
3016
import io.fabric8.maven.docker.util.Logger;
17+
import org.apache.maven.plugin.MojoExecutionException;
18+
import org.apache.maven.plugins.annotations.LifecyclePhase;
19+
import org.apache.maven.plugins.annotations.Mojo;
20+
import org.apache.maven.plugins.annotations.Parameter;
21+
22+
import java.io.File;
23+
import java.io.IOException;
24+
import java.nio.file.Files;
25+
import java.util.Collection;
26+
import java.util.Collections;
27+
import java.util.List;
28+
import java.util.Properties;
29+
import java.util.regex.Matcher;
3130

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

4746
private static final String COPY_NAME_PATTERN_CONFIG = "copyNamePattern";

src/main/java/io/fabric8/maven/docker/LogsMojo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* @since 26.03.14
2525
*
2626
*/
27-
@Mojo(name = "logs")
27+
@Mojo(name = "logs", configurator = "fabric8-mojo-configurator")
2828
public class LogsMojo extends AbstractDockerMojo {
2929

3030
// Whether to log infinitely or to show only the logs happened until now.

src/main/java/io/fabric8/maven/docker/PushMojo.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import io.fabric8.maven.docker.access.DockerAccessException;
44
import io.fabric8.maven.docker.service.JibBuildService;
55
import io.fabric8.maven.docker.service.ServiceHub;
6-
76
import io.fabric8.maven.docker.util.MojoParameters;
87
import org.apache.maven.plugin.MojoExecutionException;
98
import org.apache.maven.plugins.annotations.LifecyclePhase;
@@ -15,7 +14,7 @@
1514
*
1615
* @author roland
1716
*/
18-
@Mojo(name = "push", defaultPhase = LifecyclePhase.DEPLOY)
17+
@Mojo(name = "push", defaultPhase = LifecyclePhase.DEPLOY, configurator = "fabric8-mojo-configurator")
1918
public class PushMojo extends AbstractDockerMojo {
2019

2120
// Registry to use for push operations if no registry is specified

src/main/java/io/fabric8/maven/docker/RemoveMojo.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import io.fabric8.maven.docker.service.QueryService;
2121
import io.fabric8.maven.docker.service.ServiceHub;
2222
import io.fabric8.maven.docker.util.ImageName;
23-
2423
import org.apache.maven.plugin.MojoExecutionException;
2524
import org.apache.maven.plugins.annotations.LifecyclePhase;
2625
import org.apache.maven.plugins.annotations.Mojo;
@@ -46,7 +45,7 @@
4645
* @since 23.10.14
4746
*
4847
*/
49-
@Mojo(name = "remove", defaultPhase = LifecyclePhase.POST_INTEGRATION_TEST)
48+
@Mojo(name = "remove", defaultPhase = LifecyclePhase.POST_INTEGRATION_TEST, configurator = "fabric8-mojo-configurator")
5049
public class RemoveMojo extends AbstractDockerMojo {
5150

5251
private static final String REMOVE_NAME_PATTERN_CONFIG = "removeNamePattern";

src/main/java/io/fabric8/maven/docker/RunMojo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* @author roland
2525
* @since 26/04/16
2626
*/
27-
@Mojo(name = "run", defaultPhase = LifecyclePhase.PRE_INTEGRATION_TEST)
27+
@Mojo(name = "run", defaultPhase = LifecyclePhase.PRE_INTEGRATION_TEST, configurator = "fabric8-mojo-configurator")
2828
public class RunMojo extends StartMojo {
2929

3030
@Override

src/main/java/io/fabric8/maven/docker/SaveMojo.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
package io.fabric8.maven.docker;
22

3-
import java.io.File;
4-
import java.util.ArrayList;
5-
import java.util.List;
6-
import java.util.Properties;
7-
3+
import io.fabric8.maven.docker.access.DockerAccessException;
84
import io.fabric8.maven.docker.config.ArchiveCompression;
5+
import io.fabric8.maven.docker.config.ImageConfiguration;
6+
import io.fabric8.maven.docker.service.ServiceHub;
97
import io.fabric8.maven.docker.util.EnvUtil;
108
import io.fabric8.maven.docker.util.ImageName;
119
import org.apache.maven.plugin.MojoExecutionException;
@@ -14,11 +12,12 @@
1412
import org.apache.maven.plugins.annotations.Parameter;
1513
import org.apache.maven.project.MavenProjectHelper;
1614

17-
import io.fabric8.maven.docker.access.DockerAccessException;
18-
import io.fabric8.maven.docker.config.ImageConfiguration;
19-
import io.fabric8.maven.docker.service.ServiceHub;
15+
import java.io.File;
16+
import java.util.ArrayList;
17+
import java.util.List;
18+
import java.util.Properties;
2019

21-
@Mojo(name = "save")
20+
@Mojo(name = "save", configurator = "fabric8-mojo-configurator")
2221
public class SaveMojo extends AbstractDockerMojo {
2322

2423
// Used when not automatically determined

src/main/java/io/fabric8/maven/docker/SourceMojo.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,23 @@
1616
* limitations under the License.
1717
*/
1818

19-
import java.io.File;
20-
import java.util.ArrayList;
21-
import java.util.List;
22-
2319
import io.fabric8.maven.docker.access.DockerAccessException;
2420
import io.fabric8.maven.docker.config.BuildImageConfiguration;
25-
import io.fabric8.maven.docker.config.ImageConfiguration;
2621
import io.fabric8.maven.docker.config.BuildImageSelectMode;
22+
import io.fabric8.maven.docker.config.ImageConfiguration;
2723
import io.fabric8.maven.docker.service.ServiceHub;
2824
import io.fabric8.maven.docker.util.MojoParameters;
29-
3025
import org.apache.maven.plugin.MojoExecutionException;
3126
import org.apache.maven.plugins.annotations.Component;
3227
import org.apache.maven.plugins.annotations.LifecyclePhase;
3328
import org.apache.maven.plugins.annotations.Mojo;
3429
import org.apache.maven.plugins.annotations.Parameter;
3530
import org.apache.maven.project.MavenProjectHelper;
3631

32+
import java.io.File;
33+
import java.util.ArrayList;
34+
import java.util.List;
35+
3736
/**
3837
* Mojo for attaching one more source docker tar file to an artifact.
3938
*
@@ -44,7 +43,7 @@
4443
* @author roland
4544
* @since 25/10/15
4645
*/
47-
@Mojo(name = "source", defaultPhase = LifecyclePhase.PACKAGE)
46+
@Mojo(name = "source", defaultPhase = LifecyclePhase.PACKAGE, configurator = "fabric8-mojo-configurator")
4847
public class SourceMojo extends AbstractBuildSupportMojo {
4948

5049
@Component

src/main/java/io/fabric8/maven/docker/StartMojo.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,6 @@
88
* the License.
99
*/
1010

11-
import java.io.IOException;
12-
import java.util.ArrayDeque;
13-
import java.util.ArrayList;
14-
import java.util.Collections;
15-
import java.util.HashSet;
16-
import java.util.List;
17-
import java.util.Properties;
18-
import java.util.Queue;
19-
import java.util.Set;
20-
import java.util.concurrent.ExecutionException;
21-
import java.util.concurrent.ExecutorCompletionService;
22-
import java.util.concurrent.ExecutorService;
23-
import java.util.concurrent.Executors;
24-
import java.util.concurrent.Future;
25-
import java.util.concurrent.TimeUnit;
26-
2711
import com.google.common.util.concurrent.MoreExecutors;
2812
import io.fabric8.maven.docker.access.DockerAccessException;
2913
import io.fabric8.maven.docker.access.ExecException;
@@ -46,13 +30,29 @@
4630
import org.apache.maven.plugins.annotations.Mojo;
4731
import org.apache.maven.plugins.annotations.Parameter;
4832

33+
import java.io.IOException;
34+
import java.util.ArrayDeque;
35+
import java.util.ArrayList;
36+
import java.util.Collections;
37+
import java.util.HashSet;
38+
import java.util.List;
39+
import java.util.Properties;
40+
import java.util.Queue;
41+
import java.util.Set;
42+
import java.util.concurrent.ExecutionException;
43+
import java.util.concurrent.ExecutorCompletionService;
44+
import java.util.concurrent.ExecutorService;
45+
import java.util.concurrent.Executors;
46+
import java.util.concurrent.Future;
47+
import java.util.concurrent.TimeUnit;
48+
4949

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

5858
@Parameter(property = "docker.showLogs")

0 commit comments

Comments
 (0)