cloud.localstack.docker.command.RunCommand Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of localstack-utils Show documentation
Show all versions of localstack-utils Show documentation
Java utilities for the LocalStack platform.
package cloud.localstack.docker.command;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class RunCommand extends Command {
private final String imageName;
public RunCommand(String imageName) {
this.imageName = imageName;
}
public String execute() {
List args = new ArrayList<>();
args.add("run");
args.add("-d");
args.addAll(options);
args.add(imageName);
return dockerExe.execute(args);
}
public RunCommand withExposedPorts(String portsToExpose, boolean randomize) {
String portsOption = String.format("%s:%s", randomize ? "" : portsToExpose, portsToExpose );
addOptions("-p", portsOption);
return this;
}
public RunCommand withEnvironmentVariable(String name, String value) {
addEnvOption(name, value);
return this;
}
public RunCommand withEnvironmentVariables(Map environmentVariables) {
environmentVariables.forEach((name, value) -> addEnvOption(name, value));
return this;
}
private void addEnvOption(String name, String value) {
addOptions("-e", String.format("%s=%s", name, value));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy