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

docker:build - add support for WORKDIR #204

Closed
wants to merge 3 commits into from
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
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ DockerFileBuilder createDockerFileBuilder(BuildImageConfiguration buildConfig, A
if (buildConfig.getMaintainer() != null) {
builder.maintainer(buildConfig.getMaintainer());
}
if (buildConfig.getWorkdir() != null) {
builder.workdir(buildConfig.getWorkdir());
}
if (assemblyConfig != null) {
builder.add("maven", "")
.basedir(assemblyConfig.getBasedir())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public class DockerFileBuilder {
// Maintainer of this image
private String maintainer = "docker-maven-plugin@jolokia.org";

// Workdir
private String workdir = null;

// Basedir to be export
private String basedir = "/maven";

Expand All @@ -42,7 +45,7 @@ public class DockerFileBuilder {
private List<AddEntry> addEntries = new ArrayList<>();

// list of ports to expose and environments to use
private List<Integer> ports = new ArrayList<>();
private List<String> ports = new ArrayList<>();
private Map<String,String> envEntries = new HashMap<>();

// exposed volumes
Expand Down Expand Up @@ -73,11 +76,11 @@ public String content() throws IllegalArgumentException {

b.append("FROM ").append(baseImage != null ? baseImage : DockerAssemblyManager.DEFAULT_DATA_BASE_IMAGE).append("\n");
b.append("MAINTAINER ").append(maintainer).append("\n");

addEnv(b);
addPorts(b);
addVolumes(b);
addEntries(b);
if (workdir != null) b.append("WORKDIR ").append(workdir).append("\n");
addCmd(b);
addEntryPoint(b);

Expand Down Expand Up @@ -138,7 +141,7 @@ private void addEnv(StringBuilder b) {
private void addPorts(StringBuilder b) {
if (ports.size() > 0) {
b.append("EXPOSE");
for (Integer port : ports) {
for (String port : ports) {
b.append(" ").append(port);
}
b.append("\n");
Expand Down Expand Up @@ -181,6 +184,11 @@ public DockerFileBuilder maintainer(String maintainer) {
return this;
}

public DockerFileBuilder workdir(String workdir) {
this.workdir = workdir;
return this;
}

public DockerFileBuilder basedir(String dir) {
if (dir != null) {
basedir = dir;
Expand Down Expand Up @@ -214,7 +222,7 @@ public DockerFileBuilder expose(List<String> ports) {
if (ports != null) {
for (String port : ports) {
if (port != null) {
this.ports.add(Integer.parseInt(port));
this.ports.add(port);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ public class BuildImageConfiguration {
*/
private String command;

/**
* @parameter
*/
private String workdir;

/**
* @parameter
*/
Expand All @@ -81,6 +86,10 @@ public String getMaintainer() {
return maintainer;
}

public String getWorkdir() {
return workdir;
}

public AssemblyConfiguration getAssemblyConfiguration() {
return assembly;
}
Expand Down Expand Up @@ -132,6 +141,11 @@ public Builder maintainer(String maintainer) {
return this;
}

public Builder workdir(String workdir) {
config.workdir = workdir;
return this;
}

public Builder assembly(AssemblyConfiguration assembly) {
config.assembly = assembly;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public enum ConfigKey {
VOLUMES,
TAGS,
MAINTAINER,
WORKDIR,
VOLUMES_FROM,
WAIT_LOG("wait.log"),
WAIT_TIME("wait.time"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ private BuildImageConfiguration extractBuildConfiguration(String prefix, Propert
.volumes(listWithPrefix(prefix, VOLUMES, properties))
.tags(listWithPrefix(prefix, TAGS, properties))
.maintainer(withPrefix(prefix, MAINTAINER, properties))
.workdir(withPrefix(prefix, WORKDIR, properties))
.build();
}

Expand Down