Skip to content

Commit 07bab27

Browse files
author
Gabriel Galhari
committed
Receive localstack version as param
1 parent 7bb1211 commit 07bab27

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

src/main/java/xyz/fabiano/spring/localstack/LocalstackDockerBuilder.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ public class LocalstackDockerBuilder {
2828

2929
private boolean cborEnable = false;
3030

31+
private String version = "latest";
32+
3133
private Collection<String> options = new ArrayList<>();
3234

3335
public LocalstackDocker build() {
@@ -44,6 +46,7 @@ public LocalstackDocker build() {
4446

4547
docker.setEnvironmentVariables(environmentVariables);
4648
docker.setOptions(options);
49+
docker.setVersion(version);
4750
return docker;
4851
}
4952

@@ -125,4 +128,10 @@ public LocalstackDockerBuilder withOptions(Collection<String> options) {
125128
this.options = options;
126129
return this;
127130
}
131+
132+
public LocalstackDockerBuilder withVersion(String version) {
133+
this.version = version;
134+
return this;
135+
}
136+
128137
}

src/main/java/xyz/fabiano/spring/localstack/autoconfigure/LocalstackAutoConfiguration.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public class LocalstackAutoConfiguration {
3434
private final String services;
3535
private final boolean autoRemove;
3636
private final String extraOptions;
37+
private final String version;
3738

3839
public LocalstackAutoConfiguration(
3940
@Value("${spring.localstack.async-clients.enabled:false}") boolean asyncClientsEnabled,
@@ -42,14 +43,16 @@ public LocalstackAutoConfiguration(
4243
@Value("${spring.localstack.external-host:localhost}") String externalHost,
4344
@Value("${spring.localstack.services:}") String services,
4445
@Value("${spring.localstack.auto-remove:true}") boolean autoRemove,
45-
@Value("${spring.localstack.extra-options:}") String extraOptions) {
46+
@Value("${spring.localstack.extra-options:}") String extraOptions,
47+
@Value("${spring.localstack.version:latest}") String version) {
4648
this.asyncClientsEnabled = asyncClientsEnabled;
4749
this.pullNewImage = pullNewImage;
4850
this.randomPorts = randomPorts;
4951
this.externalHost = externalHost;
5052
this.services = services;
5153
this.autoRemove = autoRemove;
5254
this.extraOptions = extraOptions;
55+
this.version = version;
5356
}
5457

5558
@Bean
@@ -61,6 +64,7 @@ public LocalstackDocker localstackDocker() {
6164
.disableCBOR()
6265
.withServices(services())
6366
.withOptions(options())
67+
.withVersion(version)
6468
.build();
6569

6670
localstackDocker.startup();

src/main/java/xyz/fabiano/spring/localstack/legacy/Container.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,16 @@ public static Container createLocalstackContainer(String externalHostName,
4848
boolean pullNewImage,
4949
boolean randomizePorts,
5050
Map<String, String> environmentVariables,
51-
Collection<String> options) {
51+
Collection<String> options,
52+
String version) {
53+
String imageName = LOCALSTACK_NAME + ":" + version;
5254

5355
if(pullNewImage) {
5456
LOG.info("Pulling latest image...");
55-
new PullCommand(LOCALSTACK_NAME).execute();
57+
new PullCommand(imageName).execute();
5658
}
5759

58-
String containerId = new RunCommand(LOCALSTACK_NAME)
60+
String containerId = new RunCommand(imageName)
5961
.withOptions(options)
6062
.withExposedPorts(LOCALSTACK_PORTS, randomizePorts)
6163
.withEnvironmentVariable(LOCALSTACK_EXTERNAL_HOSTNAME, externalHostName)

src/main/java/xyz/fabiano/spring/localstack/legacy/LocalstackDocker.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ public class LocalstackDocker {
5555
private Map<String, String> environmentVariables = new HashMap<>();
5656
@Setter
5757
private Collection<String> options = new ArrayList<>();
58+
@Setter
59+
private String version = "latest";
5860

5961
@Getter
6062
private static LocalstackDocker localstackDocker = new LocalstackDocker();
@@ -69,7 +71,7 @@ public void startup() {
6971
locked = true;
7072

7173
try {
72-
localStackContainer = Container.createLocalstackContainer(externalHostName, pullNewImage, randomizePorts, environmentVariables, options);
74+
localStackContainer = Container.createLocalstackContainer(externalHostName, pullNewImage, randomizePorts, environmentVariables, options, version);
7375
loadServiceToPortMap();
7476

7577
LOG.info("Waiting for localstack container to be ready...");

0 commit comments

Comments
 (0)