-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
attempt to use OOTB service connection for S3
- Loading branch information
1 parent
b0372ae
commit 8f34249
Showing
6 changed files
with
71 additions
and
54 deletions.
There are no files selected for viewing
7 changes: 5 additions & 2 deletions
7
aws-s3-project/src/test/java/com/learning/awspring/TestS3Application.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
package com.learning.awspring; | ||
|
||
import com.learning.awspring.common.ContainerConfig; | ||
import com.learning.awspring.common.LocalStackContainerConfig; | ||
import com.learning.awspring.common.SQLContainerConfig; | ||
import org.springframework.boot.SpringApplication; | ||
|
||
public class TestS3Application { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.from(S3Application::main).with(ContainerConfig.class).run(args); | ||
SpringApplication.from(S3Application::main) | ||
.with(SQLContainerConfig.class, LocalStackContainerConfig.class) | ||
.run(args); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 0 additions & 45 deletions
45
aws-s3-project/src/test/java/com/learning/awspring/common/ContainerConfig.java
This file was deleted.
Oops, something went wrong.
23 changes: 23 additions & 0 deletions
23
aws-s3-project/src/test/java/com/learning/awspring/common/LocalStackContainerConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.learning.awspring.common; | ||
|
||
import org.springframework.boot.test.context.TestConfiguration; | ||
import org.springframework.boot.testcontainers.service.connection.ServiceConnection; | ||
import org.springframework.context.annotation.Bean; | ||
import org.testcontainers.containers.localstack.LocalStackContainer; | ||
import org.testcontainers.containers.wait.strategy.Wait; | ||
import org.testcontainers.utility.DockerImageName; | ||
import org.testcontainers.utility.MountableFile; | ||
|
||
@TestConfiguration(proxyBeanMethods = false) | ||
public class LocalStackContainerConfig { | ||
|
||
@Bean | ||
@ServiceConnection | ||
LocalStackContainer localstackContainer() { | ||
return new LocalStackContainer( | ||
DockerImageName.parse("localstack/localstack").withTag("4.0.3")) | ||
.withCopyFileToContainer( | ||
MountableFile.forHostPath(".localstack/"), "/etc/localstack/init/ready.d/") | ||
.waitingFor(Wait.forLogMessage(".*LocalStack initialized successfully\n", 1)); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
aws-s3-project/src/test/java/com/learning/awspring/common/SQLContainerConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.learning.awspring.common; | ||
|
||
import org.springframework.boot.devtools.restart.RestartScope; | ||
import org.springframework.boot.test.context.TestConfiguration; | ||
import org.springframework.boot.testcontainers.service.connection.ServiceConnection; | ||
import org.springframework.context.annotation.Bean; | ||
import org.testcontainers.containers.PostgreSQLContainer; | ||
import org.testcontainers.utility.DockerImageName; | ||
|
||
@TestConfiguration(proxyBeanMethods = false) | ||
public class SQLContainerConfig { | ||
|
||
@Bean | ||
@ServiceConnection | ||
@RestartScope | ||
PostgreSQLContainer<?> postgresContainer() { | ||
return new PostgreSQLContainer<>(DockerImageName.parse("postgres:17.2-alpine")) | ||
.withReuse(true); | ||
} | ||
|
||
// @Bean | ||
// DynamicPropertyRegistrar dynamicPropertyRegistrar(LocalStackContainer localStackContainer) { | ||
// return registry -> { | ||
// registry.add( | ||
// "spring.cloud.aws.credentials.access-key", | ||
// localStackContainer::getAccessKey); | ||
// registry.add( | ||
// "spring.cloud.aws.credentials.secret-key", | ||
// localStackContainer::getSecretKey); | ||
// registry.add("spring.cloud.aws.region.static", localStackContainer::getRegion); | ||
// registry.add("spring.cloud.aws.endpoint", localStackContainer::getEndpoint); | ||
// }; | ||
// } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters