Skip to content

Commit b52cf8d

Browse files
authored
enable specification of "platform" when configuring container (#50)
1 parent cfd4f59 commit b52cf8d

File tree

8 files changed

+28
-9
lines changed

8 files changed

+28
-9
lines changed

src/main/java/cloud/localstack/Localstack.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ public void startup(LocalstackDockerConfiguration dockerConfiguration) {
7474
dockerConfiguration.getPortElasticSearch(),
7575
dockerConfiguration.getEnvironmentVariables(),
7676
dockerConfiguration.getPortMappings(),
77-
dockerConfiguration.getBindMounts()
77+
dockerConfiguration.getBindMounts(),
78+
dockerConfiguration.getPlatform()
7879
);
7980
loadServiceToPortMap();
8081

src/main/java/cloud/localstack/docker/Container.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import cloud.localstack.Localstack;
44
import cloud.localstack.docker.command.*;
5+
import org.apache.commons.lang3.StringUtils;
56

67
import java.io.IOException;
78
import java.net.InetSocketAddress;
@@ -54,11 +55,12 @@ public class Container {
5455
* @param portMappings
5556
* @param bindMounts Docker host to container volume mapping like /host/dir:/container/dir, be aware that the host
5657
* directory must be an absolute path
58+
* @param platform target platform for the localstack docker image
5759
*/
5860
public static Container createLocalstackContainer(
5961
String externalHostName, boolean pullNewImage, boolean randomizePorts, String imageName, String imageTag, String portEdge,
6062
String portElasticSearch, Map<String, String> environmentVariables, Map<Integer, Integer> portMappings,
61-
Map<String, String> bindMounts) {
63+
Map<String, String> bindMounts, String platform) {
6264

6365
environmentVariables = environmentVariables == null ? Collections.emptyMap() : environmentVariables;
6466
bindMounts = bindMounts == null ? Collections.emptyMap() : bindMounts;
@@ -86,6 +88,9 @@ public static Container createLocalstackContainer(
8688
.withEnvironmentVariables(environmentVariables)
8789
.withBindMountedVolumes(bindMounts);
8890

91+
if(!StringUtils.isEmpty(platform))
92+
runCommand = runCommand.withPlatform(platform);
93+
8994
for (Integer port : portMappings.keySet()) {
9095
runCommand = runCommand.withExposedPorts("" + port, false);
9196
}

src/main/java/cloud/localstack/docker/annotation/LocalstackDockerAnnotationProcessor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ private LocalstackDockerConfiguration processDockerPropertiesAnnotation(Localsta
4343
.portEdge(getEnvOrDefault("LOCALSTACK_EDGE_PORT", properties.portEdge()))
4444
.portElasticSearch(getEnvOrDefault("LOCALSTACK_ELASTICSEARCH_PORT", properties.portElasticSearch()))
4545
.useSingleDockerContainer(properties.useSingleDockerContainer())
46+
.platform(StringUtils.isEmpty(properties.platform()) ? null : properties.platform())
4647
.build();
4748
}
4849

src/main/java/cloud/localstack/docker/annotation/LocalstackDockerConfiguration.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public class LocalstackDockerConfiguration {
2727

2828
private final String imageName;
2929
private final String imageTag;
30+
private final String platform;
3031

3132
@Builder.Default
3233
private final String portEdge = "4566";

src/main/java/cloud/localstack/docker/annotation/LocalstackDockerProperties.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,10 @@
9292
* This can be used to run tests with an existing LocalStack container running on the host.
9393
*/
9494
boolean ignoreDockerRunErrors() default false;
95+
96+
/**
97+
* Specifies a target platform for the localstack docker image. Value is used by the --platform flag in the
98+
* docker run command
99+
*/
100+
String platform() default "";
95101
}

src/main/java/cloud/localstack/docker/command/RunCommand.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ public RunCommand withEnvironmentVariables(Map<String, String> environmentVariab
5959
return this;
6060
}
6161

62+
public RunCommand withPlatform(String platform) {
63+
addOptions("--platform", platform);
64+
return this;
65+
}
66+
6267
private void addEnvOption(String name, String value) {
6368
addOptions("-e", String.format("%s=%s", name, value));
6469
}

src/test/java/cloud/localstack/deprecated/PortBindingTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public void testAccessPredefinedPort() {
3535
@Test
3636
public void createLocalstackContainerWithRandomPorts() throws Exception {
3737
Container container = Container.createLocalstackContainer(
38-
EXTERNAL_HOST_NAME, pullNewImage, true, null, null, null, null, null, null, null);
38+
EXTERNAL_HOST_NAME, pullNewImage, true, null, null, null, null, null, null, null, null);
3939

4040
try {
4141
container.waitForAllPorts(EXTERNAL_HOST_NAME);
@@ -53,7 +53,7 @@ public void createLocalstackContainerWithRandomPorts() throws Exception {
5353
@Test
5454
public void createLocalstackContainerWithStaticPorts() throws Exception {
5555
Container container = Container.createLocalstackContainer(
56-
EXTERNAL_HOST_NAME, pullNewImage, false, null, null, null, null, null, null, null);
56+
EXTERNAL_HOST_NAME, pullNewImage, false, null, null, null, null, null, null, null, null);
5757

5858
try {
5959
container.waitForAllPorts(EXTERNAL_HOST_NAME);

src/test/java/cloud/localstack/docker/ContainerTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public void createLocalstackContainer() throws Exception {
3232
HashMap<String, String> environmentVariables = new HashMap<>();
3333
environmentVariables.put(MY_PROPERTY, MY_VALUE);
3434
Container localStackContainer = Container.createLocalstackContainer(
35-
EXTERNAL_HOST_NAME, pullNewImage, false, null, null, null, null, environmentVariables, null, null);
35+
EXTERNAL_HOST_NAME, pullNewImage, false, null, null, null, null, environmentVariables, null, null, null);
3636

3737
try {
3838
localStackContainer.waitForAllPorts(EXTERNAL_HOST_NAME);
@@ -60,7 +60,7 @@ public void createLocalstackContainerWithFullImage() {
6060

6161
String customImageName = "localstack/localstack-full";
6262
Container localStackContainer = Container.createLocalstackContainer(
63-
EXTERNAL_HOST_NAME, pullNewImage, false, customImageName, null, null, null, null, null, null);
63+
EXTERNAL_HOST_NAME, pullNewImage, false, customImageName, null, null, null, null, null, null, null);
6464

6565
try {
6666
localStackContainer.waitForAllPorts(EXTERNAL_HOST_NAME);
@@ -81,7 +81,7 @@ public void createLocalstackContainerWithScriptMounted() {
8181

8282
Container localStackContainer = Container.createLocalstackContainer(
8383
EXTERNAL_HOST_NAME, pullNewImage, false, null, null, null, null, null, null,
84-
Collections.singletonMap(testFile("echo testmarker"), Localstack.INIT_SCRIPTS_PATH + "/test.sh"));
84+
Collections.singletonMap(testFile("echo testmarker"), Localstack.INIT_SCRIPTS_PATH + "/test.sh"), null);
8585

8686
try {
8787
localStackContainer.waitForAllPorts(EXTERNAL_HOST_NAME);
@@ -109,7 +109,7 @@ static String testFile(String content) {
109109
@Test
110110
public void createLocalstackContainerWithCustomPorts() throws Exception {
111111
Container localStackContainer = Container.createLocalstackContainer(
112-
EXTERNAL_HOST_NAME, pullNewImage, false, null, null, "45660", "45710", null, null, null);
112+
EXTERNAL_HOST_NAME, pullNewImage, false, null, null, "45660", "45710", null, null, null, null);
113113

114114
try {
115115
localStackContainer.waitForAllPorts(EXTERNAL_HOST_NAME);
@@ -126,7 +126,7 @@ public void createLocalstackContainerWithCustomPorts() throws Exception {
126126
@Test
127127
public void createLocalstackContainerWithRandomPorts() throws Exception {
128128
Container localStackContainer = Container.createLocalstackContainer(
129-
EXTERNAL_HOST_NAME, pullNewImage, false, null, null, ":4566", ":4571", null, null, null);
129+
EXTERNAL_HOST_NAME, pullNewImage, false, null, null, ":4566", ":4571", null, null, null, null);
130130

131131
try {
132132
localStackContainer.waitForAllPorts(EXTERNAL_HOST_NAME);

0 commit comments

Comments
 (0)