Skip to content

Commit 27d992d

Browse files
Migrate aws-s3 project from Localstack to Floci
1 parent e2e1a46 commit 27d992d

3 files changed

Lines changed: 32 additions & 24 deletions

File tree

aws2-s3/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
</dependency>
101101
<dependency>
102102
<groupId>org.testcontainers</groupId>
103-
<artifactId>testcontainers-localstack</artifactId>
103+
<artifactId>testcontainers</artifactId>
104104
</dependency>
105105
</dependencies>
106106

aws2-s3/src/main/resources/application.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ camel.component.aws2-s3.region=${AWS_REGION}
2424
cq.aws2-s3.example.bucketName=${AWS_BUCKET_NAME}
2525

2626
#docker image for mocked tests
27-
localstack.container.image=mirror.gcr.io/localstack/localstack:4.13.0
27+
floci.container.image=mirror.gcr.io/floci/floci:1.5.28

aws2-s3/src/test/java/org/acme/aws2/s3/Aws2S3TestResource.java

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717
package org.acme.aws2.s3;
1818

19+
import java.net.URI;
1920
import java.util.Collections;
2021
import java.util.Locale;
2122
import java.util.Map;
@@ -27,8 +28,9 @@
2728
import org.eclipse.microprofile.config.ConfigProvider;
2829
import org.slf4j.Logger;
2930
import org.slf4j.LoggerFactory;
31+
import org.testcontainers.containers.GenericContainer;
3032
import org.testcontainers.containers.output.Slf4jLogConsumer;
31-
import org.testcontainers.localstack.LocalStackContainer;
33+
import org.testcontainers.containers.wait.strategy.Wait;
3234
import org.testcontainers.utility.DockerImageName;
3335
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
3436
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
@@ -39,8 +41,12 @@
3941

4042
public class Aws2S3TestResource implements QuarkusTestResourceLifecycleManager {
4143
private static final Logger LOG = LoggerFactory.getLogger(Aws2S3TestResource.class);
44+
private static final int FLOCI_PORT = 4566;
45+
private static final String ACCESS_KEY = "testAccessKeyId";
46+
private static final String SECRET_KEY = "testSecretKeyId";
47+
private static final String REGION = "us-east-1";
4248

43-
private LocalStackContainer localstack;
49+
private GenericContainer<?> floci;
4450

4551
@Override
4652
public Map<String, String> start() {
@@ -54,39 +60,41 @@ public Map<String, String> start() {
5460
final boolean realCredentialsProvided = accessKey.isPresent() && secretKey.isPresent() && region.isPresent()
5561
&& bucketName.isPresent();
5662

57-
//do not start a localstack, when real credentials are provided
5863
if (realCredentialsProvided) {
5964
LOG.info("Real backend will be used");
6065
return Collections.emptyMap();
6166
}
6267
LOG.info("Mock backend will be used");
6368

6469
DockerImageName imageName = DockerImageName
65-
.parse(config.getValue("localstack.container.image", String.class))
66-
.asCompatibleSubstituteFor("localstack/localstack");
67-
localstack = new LocalStackContainer(imageName)
68-
.withServices("s3")
69-
.withEnv("LS_LOG", "info")
70-
.withEnv("AWS_ACCESS_KEY_ID", "testAccessKeyId")
71-
.withEnv("AWS_SECRET_ACCESS_KEY", "testSecretKeyId")
70+
.parse(config.getValue("floci.container.image", String.class));
71+
floci = new GenericContainer<>(imageName)
72+
.withExposedPorts(FLOCI_PORT)
73+
.waitingFor(Wait.forHttp("/_floci/health").forPort(FLOCI_PORT))
74+
.withEnv("AWS_ACCESS_KEY_ID", ACCESS_KEY)
75+
.withEnv("AWS_SECRET_ACCESS_KEY", SECRET_KEY)
7276
.withLogConsumer(new Slf4jLogConsumer(LOG));
73-
localstack.start();
77+
floci.start();
7478

75-
return Map.of("camel.component.aws2-s3.accessKey", localstack.getAccessKey(),
76-
"camel.component.aws2-s3.secretKey", localstack.getSecretKey(),
77-
"camel.component.aws2-s3.region", localstack.getRegion(),
79+
String endpoint = String.format("http://%s:%d", floci.getHost(), floci.getMappedPort(FLOCI_PORT));
80+
81+
return Map.of("camel.component.aws2-s3.accessKey", ACCESS_KEY,
82+
"camel.component.aws2-s3.secretKey", SECRET_KEY,
83+
"camel.component.aws2-s3.region", REGION,
7884
"camel.component.aws2-s3.override-endpoint", "true",
79-
"camel.component.aws2-s3.uri-endpoint-override", localstack.getEndpoint().toString(),
80-
"cq.aws2-s3.example.bucketName", createBucket());
85+
"camel.component.aws2-s3.uri-endpoint-override", endpoint,
86+
"camel.component.aws2-s3.force-path-style", "true",
87+
"cq.aws2-s3.example.bucketName", createBucket(endpoint));
8188
}
8289

83-
private String createBucket() {
90+
private String createBucket(String endpoint) {
8491
S3ClientBuilder clientBuilder = S3Client.builder();
8592
clientBuilder
8693
.credentialsProvider(StaticCredentialsProvider
87-
.create(AwsBasicCredentials.create(localstack.getAccessKey(), localstack.getSecretKey())))
88-
.endpointOverride(localstack.getEndpoint())
89-
.region(Region.of(localstack.getRegion()));
94+
.create(AwsBasicCredentials.create(ACCESS_KEY, SECRET_KEY)))
95+
.endpointOverride(URI.create(endpoint))
96+
.forcePathStyle(true)
97+
.region(Region.of(REGION));
9098
final S3Client s3Client = clientBuilder.build();
9199

92100
final String bucketName = "camel-quarkus-" + RandomStringUtils.secure().nextAlphanumeric(49).toLowerCase(Locale.ROOT);
@@ -96,8 +104,8 @@ private String createBucket() {
96104

97105
@Override
98106
public void stop() {
99-
if (localstack != null) {
100-
localstack.stop();
107+
if (floci != null) {
108+
floci.stop();
101109
}
102110
}
103111
}

0 commit comments

Comments
 (0)