Skip to content

Commit bc71a33

Browse files
authored
allow overwriting the port binding via environment variables (#37)
1 parent e3ac0b3 commit bc71a33

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,16 @@ private LocalstackDockerConfiguration processDockerPropertiesAnnotation(Localsta
3636
.ignoreDockerRunErrors(properties.ignoreDockerRunErrors())
3737
.randomizePorts(properties.randomizePorts())
3838
.imageTag(StringUtils.isEmpty(properties.imageTag()) ? null : properties.imageTag())
39-
.portEdge(properties.portEdge())
40-
.portElasticSearch(properties.portElasticSearch())
39+
.portEdge(getEnvOrDefault("LOCALSTACK_EDGE_PORT", properties.portEdge()))
40+
.portElasticSearch(getEnvOrDefault("LOCALSTACK_ELASTICSEARCH_PORT", properties.portElasticSearch()))
4141
.useSingleDockerContainer(properties.useSingleDockerContainer())
4242
.build();
4343
}
4444

45+
private String getEnvOrDefault(final String environmentVariable, final String defaultValue) {
46+
return System.getenv().getOrDefault(environmentVariable, defaultValue);
47+
}
48+
4549
private Map<Integer, Integer> getCustomPortMappings(final LocalstackDockerProperties properties) {
4650
final Map<Integer, Integer> portMappings = new HashMap<>();
4751
for (String service : properties.services()) {

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,14 @@
5252
String imageTag() default "";
5353

5454
/**
55-
* Port number for the edge service, the main entry point for all API invocations
55+
* Port number for the edge service, the main entry point for all API invocations. Alternatively, use the
56+
* LOCALSTACK_EDGE_PORT environment variable.
5657
*/
5758
String portEdge() default "4566";
5859

5960
/**
60-
* Port number for the elasticsearch service
61+
* Port number for the elasticsearch service. Alternatively, use the LOCALSTACK_ELASTICSEARCH_PORT environment
62+
* variable.
6163
*/
6264
String portElasticSearch() default "4571";
6365

0 commit comments

Comments
 (0)