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

Unbreak setting of entrypoint in exec form when property mode is enabled #1020

Merged
merged 1 commit into from
May 16, 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
Original file line number Diff line number Diff line change
Expand Up @@ -413,9 +413,9 @@ public Builder labels(Map<String, String> labels) {
return this;
}

public Builder cmd(String cmd) {
public Builder cmd(Arguments cmd) {
if (cmd != null) {
config.cmd = new Arguments(cmd);
config.cmd = cmd;
}
return this;
}
Expand Down Expand Up @@ -444,9 +444,9 @@ public Builder optimise(Boolean optimise) {
return this;
}

public Builder entryPoint(String entryPoint) {
public Builder entryPoint(Arguments entryPoint) {
if (entryPoint != null) {
config.entryPoint = new Arguments(entryPoint);
config.entryPoint = entryPoint;
}
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ public Builder startPeriod(String startPeriod) {
return this;
}

public Builder cmd(String command) {
public Builder cmd(Arguments command) {
if (command != null) {
config.cmd = new Arguments(command);
config.cmd = command;
}
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,13 +400,6 @@ public Builder domainname(String domainname) {
return this;
}

public Builder entrypoint(String entrypoint) {
if (entrypoint != null) {
config.entrypoint = new Arguments(entrypoint);
}
return this;
}

public Builder entrypoint(Arguments args) {
config.entrypoint = args;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@
import io.fabric8.maven.docker.config.*;
import io.fabric8.maven.docker.config.handler.ExternalConfigHandler;
import io.fabric8.maven.docker.util.EnvUtil;
import com.google.common.base.Function;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.CollectionUtils;

import javax.annotation.Nullable;

import static io.fabric8.maven.docker.config.handler.property.ConfigKey.*;

/**
Expand Down Expand Up @@ -220,13 +223,13 @@ private List<String> extractPortValues(List<String> config, ValueProvider valueP
return ret;
}

private String extractArguments(ValueProvider valueProvider, ConfigKey configKey, Arguments alternative) {
String rawAlternative = null;
if (alternative != null) {
rawAlternative = alternative.getShell();
}

return valueProvider.getString(configKey, rawAlternative);
private Arguments extractArguments(ValueProvider valueProvider, ConfigKey configKey, Arguments alternative) {
return valueProvider.getObject(configKey, alternative, new Function<String, Arguments>() {
@Override
public Arguments apply(@Nullable String raw) {
return raw != null ? new Arguments(raw) : null;
}
});
}

private RestartPolicy extractRestartPolicy(RestartPolicy config, ValueProvider valueProvider) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,16 @@ public Map<String, String> getMap(ConfigKey key, Map<String, String> fromConfig)
return mapValueExtractor.getFromPreferredSource(prefix, key, fromConfig);
}

public <T> T getObject(ConfigKey key, T fromConfig, final com.google.common.base.Function<String, T> converter) {
ValueExtractor<T> arbitraryExtractor = new ValueExtractor<T>() {
@Override
protected T withPrefix(String prefix, ConfigKey key, Properties properties) {
return converter.apply(properties.getProperty(key.asPropertyKey(prefix)));
}
};

return arbitraryExtractor.getFromPreferredSource(prefix, key, fromConfig);
}

/**
* Helper base class for picking values out of the the Properties class and/or config value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@
import java.util.*;
import java.util.regex.Pattern;

import io.fabric8.maven.docker.config.*;
import com.google.common.collect.ImmutableMap;
import io.fabric8.maven.docker.config.Arguments;
import io.fabric8.maven.docker.config.HealthCheckConfiguration;
import io.fabric8.maven.docker.config.HealthCheckMode;

import org.apache.commons.io.IOUtils;
import org.junit.Test;

Expand Down Expand Up @@ -182,7 +179,7 @@ public void testEntryPointParams() {

@Test
public void testHealthCheckCmdParams() {
HealthCheckConfiguration hc = new HealthCheckConfiguration.Builder().cmd("echo hello").interval("5s").timeout("3s").startPeriod("30s").retries(4).build();
HealthCheckConfiguration hc = new HealthCheckConfiguration.Builder().cmd(new Arguments("echo hello")).interval("5s").timeout("3s").startPeriod("30s").retries(4).build();
String dockerfileContent = new DockerFileBuilder().healthCheck(hc).content();
assertThat(dockerfileToMap(dockerfileContent), hasEntry("HEALTHCHECK", "--interval=5s --timeout=3s --start-period=30s --retries=4 CMD echo hello"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ public class HealthCheckConfigTest {
@Test
public void testGoodHealthCheck1() {
new HealthCheckConfiguration.Builder()
.cmd("exit 0")
.cmd(new Arguments("exit 0"))
.build()
.validate();
}

@Test
public void testGoodHealthCheck2() {
new HealthCheckConfiguration.Builder()
.cmd("exit 0")
.cmd(new Arguments("exit 0"))
.retries(1)
.build()
.validate();
Expand All @@ -27,7 +27,7 @@ public void testGoodHealthCheck2() {
@Test
public void testGoodHealthCheck3() {
new HealthCheckConfiguration.Builder()
.cmd("exit 0")
.cmd(new Arguments("exit 0"))
.retries(1)
.interval("2s")
.build()
Expand All @@ -37,7 +37,7 @@ public void testGoodHealthCheck3() {
@Test
public void testGoodHealthCheck4() {
new HealthCheckConfiguration.Builder()
.cmd("exit 0")
.cmd(new Arguments("exit 0"))
.retries(1)
.interval("2s")
.timeout("3s")
Expand All @@ -48,7 +48,8 @@ public void testGoodHealthCheck4() {
@Test
public void testGoodHealthCheck5() {
new HealthCheckConfiguration.Builder()
.cmd("exit 0")
.mode(HealthCheckMode.cmd)
.cmd(new Arguments("exit 0"))
.retries(1)
.interval("2s")
.timeout("3s")
Expand All @@ -61,7 +62,7 @@ public void testGoodHealthCheck5() {
public void testGoodHealthCheck6() {
new HealthCheckConfiguration.Builder()
.mode(HealthCheckMode.cmd)
.cmd("exit 0")
.cmd(new Arguments("exit 0"))
.retries(1)
.interval("2s")
.timeout("3s")
Expand Down Expand Up @@ -110,6 +111,7 @@ public void testBadHealthCheck4() {
new HealthCheckConfiguration.Builder()
.mode(HealthCheckMode.none)
.startPeriod("30s")
.cmd(new Arguments("echo a"))
.build()
.validate();
}
Expand All @@ -118,7 +120,7 @@ public void testBadHealthCheck4() {
public void testBadHealthCheck5() {
new HealthCheckConfiguration.Builder()
.mode(HealthCheckMode.none)
.cmd("echo a")
.cmd(new Arguments("echo a"))
.build()
.validate();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,43 @@ public void testRunCommandsFromConfigAndProperties() {
assertArrayEquals(new String[]{"some", "configured", "value"}, runCommands);
}

@Test
public void testEntrypoint() {
List<ImageConfiguration> configs = resolveImage(
imageConfiguration,props(
"docker.from", "base",
"docker.name","demo",
"docker.entrypoint", "/entrypoint.sh --from-property")
);

assertEquals(1, configs.size());

BuildImageConfiguration buildConfig = configs.get(0).getBuildConfiguration();
assertArrayEquals(new String[]{"/entrypoint.sh", "--from-property"}, buildConfig.getEntryPoint().asStrings().toArray());
}

@Test
public void testEntrypointExecFromConfig() {
imageConfiguration = new ImageConfiguration.Builder()
.externalConfig(externalConfigMode(PropertyMode.Fallback))
.buildConfig(new BuildImageConfiguration.Builder()
.entryPoint(new Arguments(Arrays.asList("/entrypoint.sh", "--from-property")))
.build()
)
.build();

List<ImageConfiguration> configs = resolveImage(
imageConfiguration,props(
"docker.from", "base",
"docker.name","demo")
);

assertEquals(1, configs.size());

BuildImageConfiguration buildConfig = configs.get(0).getBuildConfiguration();
assertArrayEquals(new String[]{"/entrypoint.sh", "--from-property"}, buildConfig.getEntryPoint().asStrings().toArray());
}

@Test
public void testDefaultLogEnabledConfiguration() {
imageConfiguration = new ImageConfiguration.Builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ private void givenARunConfiguration() {
.memorySwap(1L)
.env(env())
.cmd("date")
.entrypoint("entrypoint")
.entrypoint(new Arguments("entrypoint"))
.extraHosts(extraHosts())
.ulimits(ulimits())
.workingDir("/foo")
Expand Down