Skip to content

Commit

Permalink
Bump spring boot to 3.2.5
Browse files Browse the repository at this point in the history
- update storages to call same signature convert method as canConvert
- update s3 tests and ci to use real S3, localstack is no longer working with later versions of s3 sdk
  • Loading branch information
paulcwarren committed May 1, 2024
1 parent 8c87e7c commit 451f7f8
Show file tree
Hide file tree
Showing 9 changed files with 1,172 additions and 1,106 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ jobs:

- name: Build and Test
run: |
export AWS_REGION=us-west-1
mvn -B -P tests -Dmaven.javadoc.skip=true install jacoco:report --file pom.xml
bash <(curl -s https://codecov.io/bash)
env:
AWS_REGION: {{ secrets.AWS_REGION }}
AWS_ACCESS_KEY: {{ secrets.AWS_ACCESS_KEY_ID_ID_ID_ID_ID }}
AWS_SECRET_KEY: {{ secrets.AWS_SECRET_KEY }}

- name: Publish JARs
run: |
Expand All @@ -56,6 +59,9 @@ jobs:
CI_DEPLOY_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}
GPG_KEY_NAME: ${{ secrets.GPG_KEY_NAME }}
GPG_PASSPHASE: ${{ secrets.GPG_PASSPHRASE }}
AWS_REGION: {{ secrets.AWS_REGION }}
AWS_ACCESS_KEY: {{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_KEY: {{ secrets.AWS_SECRET_KEY }}

- name: Publish Docs
run: |
Expand Down
18 changes: 15 additions & 3 deletions .github/workflows/prs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,20 @@ jobs:
server-password: MAVEN_PASSWORD
gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }}
gpg-passphrase: MAVEN_GPG_PASSPHRASE

- name: Build and Test
id: build
run: |
export AWS_REGION=us-west-1
pushd spring-content
mvn -B -P tests -Dmaven.javadoc.skip=true install --file pom.xml
project_version=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
echo "spring_content_version=${project_version}" >> $GITHUB_OUTPUT
popd
env:
AWS_REGION: {{ secrets.AWS_REGION }}
AWS_ACCESS_KEY: {{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_KEY: {{ secrets.AWS_SECRET_KEY }}

- name: Save Maven Cache
id: cache-maven-save
uses: actions/cache/save@v3
Expand Down Expand Up @@ -64,12 +69,16 @@ jobs:
ref: refs/heads/main
- name: Validate against Examples
run: |
export AWS_REGION=us-west-1
pushd spring-content-examples
git fetch --all
git checkout main
SPRING_CONTENT_VERSION=${{ needs.build.outputs.spring_content_version }} mvn -B clean install
popd
env:
AWS_REGION: {{ secrets.AWS_REGION }}
AWS_ACCESS_KEY: {{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_KEY: {{ secrets.AWS_SECRET_KEY }}

# - name: Setup tmate session if anything fails
# if: ${{ failure() }}
# uses: mxschmitt/action-tmate@v3
Expand Down Expand Up @@ -100,7 +109,10 @@ jobs:
ref: refs/heads/feat/content-preservation
- name: Validate against Getting Started Guides
run: |
export AWS_REGION=us-west-1
pushd spring-content-gettingstarted
SPRING_CONTENT_VERSION=${{ needs.build.outputs.spring_content_version }} mvn -B clean install
popd
env:
AWS_REGION: {{ secrets.AWS_REGION }}
AWS_ACCESS_KEY: {{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_KEY: {{ secrets.AWS_SECRET_KEY }}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Integrates with Spring Data, Spring Data REST and Apache Solr</description>

<spring-content.version>${project.version}</spring-content.version>
<ginkgo4j-version>1.0.15</ginkgo4j-version>
<springboot-version>3.2.0</springboot-version>
<springboot-version>3.2.5</springboot-version>
<spring-cloud.version>2023.0.0</spring-cloud.version>
<commonsio-version>2.15.1</commonsio-version>
<commons-lang.version>2.6</commons-lang.version>
Expand Down
26 changes: 13 additions & 13 deletions spring-content-s3/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>s3</artifactId>
<version>2.25.11</version>
<version>2.25.40</version>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
Expand Down Expand Up @@ -91,18 +91,18 @@
<version>${hibernate-orm.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.awspring.cloud</groupId>
<artifactId>spring-cloud-aws-context</artifactId>
<version>2.4.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>localstack</artifactId>
<version>${test-containers.version}</version>
<scope>test</scope>
</dependency>
<!-- <dependency>-->
<!-- <groupId>io.awspring.cloud</groupId>-->
<!-- <artifactId>spring-cloud-aws-context</artifactId>-->
<!-- <version>2.4.4</version>-->
<!-- <scope>test</scope>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.testcontainers</groupId>-->
<!-- <artifactId>localstack</artifactId>-->
<!-- <version>${test-containers.version}</version>-->
<!-- <scope>test</scope>-->
<!-- </dependency>-->
</dependencies>

<repositories>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.content.commons.annotations.ContentId;
import org.springframework.content.commons.repository.AssociativeStore;
import org.springframework.content.commons.repository.ContentStore;
Expand All @@ -34,13 +35,17 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.core.convert.converter.ConverterRegistry;
import org.springframework.core.env.Environment;
import org.springframework.core.io.Resource;

import com.github.paulcwarren.ginkgo4j.Ginkgo4jRunner;

import internal.org.springframework.content.s3.io.S3StoreResource;
import internal.org.springframework.content.s3.it.S3StoreIT;
import lombok.Data;
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
import software.amazon.awssdk.auth.credentials.AwsCredentials;
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.s3.S3Client;

Expand Down Expand Up @@ -230,13 +235,18 @@ public S3Client getS3Client() {
@Configuration
public static class InfrastructureConfig {

public Region region() {
return Region.US_WEST_1;
}
@Autowired
private Environment env;

@Bean
public S3Client client() throws URISyntaxException {
return S3Client.builder().build();
AwsCredentials awsCredentials = AwsBasicCredentials.create(env.getProperty("AWS_ACCESS_KEY"), env.getProperty("AWS_SECRET_KEY"));
StaticCredentialsProvider credentialsProvider = StaticCredentialsProvider.create(awsCredentials);

return S3Client.builder()
.region(Region.US_WEST_1)
.credentialsProvider(credentialsProvider)
.build();
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,76 +1,76 @@
package internal.org.springframework.content.s3.it;

import java.io.Serializable;
import java.net.URI;
import java.net.URISyntaxException;

import org.testcontainers.containers.localstack.LocalStackContainer;
import org.testcontainers.utility.DockerImageName;

import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSCredentialsProvider;
import com.github.dockerjava.zerodep.shaded.org.apache.hc.core5.net.URIBuilder;

import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
import software.amazon.awssdk.auth.credentials.AwsCredentials;
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
import software.amazon.awssdk.core.ServiceConfiguration;
import software.amazon.awssdk.services.s3.S3Client;

public class LocalStack extends LocalStackContainer implements Serializable {

private static final DockerImageName IMAGE_NAME = DockerImageName.parse("localstack/localstack");

private static LocalStack INSTANCE = null;

private LocalStack() {
super(IMAGE_NAME);
withServices(Service.S3);
start();
}

public static LocalStack singleton() {
if (INSTANCE == null) {
INSTANCE = new LocalStack();
}
return INSTANCE;
}

public static S3Client getAmazonS3Client() throws URISyntaxException {
return S3Client.builder()
.endpointOverride(new URI(LocalStack.singleton().getEndpointConfiguration(LocalStackContainer.Service.S3).getServiceEndpoint()))
.credentialsProvider(new LocalStack.CrossAwsCredentialsProvider(LocalStack.singleton().getDefaultCredentialsProvider()))
.serviceConfiguration((serviceBldr) -> {serviceBldr.pathStyleAccessEnabled(true);})
.build();
}

@Override
public URI getEndpointOverride(EnabledService service) {
try {
// super method converts localhost to 127.0.0.1 which fails on macos
// need to revert it back to whatever getContainerIpAddress() returns
return new URIBuilder(super.getEndpointOverride(service)).setHost(getContainerIpAddress()).build();
} catch (URISyntaxException e) {
throw new IllegalStateException("Cannot obtain endpoint URL", e);
}
}

@SuppressWarnings("unused") // Serializable safe singleton usage
protected LocalStack readResolve() {
return singleton();
}


private static class CrossAwsCredentialsProvider implements AwsCredentialsProvider {
private final AWSCredentials credentials;

public CrossAwsCredentialsProvider(AWSCredentialsProvider provider) {
this.credentials = provider.getCredentials();
}

@Override
public AwsCredentials resolveCredentials() {
return AwsBasicCredentials.create(credentials.getAWSAccessKeyId(), credentials.getAWSSecretKey());
}
}
}
//package internal.org.springframework.content.s3.it;
//
//import java.io.Serializable;
//import java.net.URI;
//import java.net.URISyntaxException;
//
//import org.testcontainers.containers.localstack.LocalStackContainer;
//import org.testcontainers.utility.DockerImageName;
//
//import com.amazonaws.auth.AWSCredentials;
//import com.amazonaws.auth.AWSCredentialsProvider;
//import com.github.dockerjava.zerodep.shaded.org.apache.hc.core5.net.URIBuilder;
//
//import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
//import software.amazon.awssdk.auth.credentials.AwsCredentials;
//import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
//import software.amazon.awssdk.core.ServiceConfiguration;
//import software.amazon.awssdk.services.s3.S3Client;
//
//public class LocalStack extends LocalStackContainer implements Serializable {
//
// private static final DockerImageName IMAGE_NAME = DockerImageName.parse("localstack/localstack");
//
// private static LocalStack INSTANCE = null;
//
// private LocalStack() {
// super(IMAGE_NAME);
// withServices(Service.S3);
// start();
// }
//
// public static LocalStack singleton() {
// if (INSTANCE == null) {
// INSTANCE = new LocalStack();
// }
// return INSTANCE;
// }
//
// public static S3Client getAmazonS3Client() throws URISyntaxException {
// return S3Client.builder()
// .endpointOverride(new URI(LocalStack.singleton().getEndpointConfiguration(LocalStackContainer.Service.S3).getServiceEndpoint()))
// .credentialsProvider(new LocalStack.CrossAwsCredentialsProvider(LocalStack.singleton().getDefaultCredentialsProvider()))
// .serviceConfiguration((serviceBldr) -> {serviceBldr.pathStyleAccessEnabled(true);})
// .build();
// }
//
// @Override
// public URI getEndpointOverride(EnabledService service) {
// try {
// // super method converts localhost to 127.0.0.1 which fails on macos
// // need to revert it back to whatever getContainerIpAddress() returns
// return new URIBuilder(super.getEndpointOverride(service)).setHost(getContainerIpAddress()).build();
// } catch (URISyntaxException e) {
// throw new IllegalStateException("Cannot obtain endpoint URL", e);
// }
// }
//
// @SuppressWarnings("unused") // Serializable safe singleton usage
// protected LocalStack readResolve() {
// return singleton();
// }
//
//
// private static class CrossAwsCredentialsProvider implements AwsCredentialsProvider {
// private final AWSCredentials credentials;
//
// public CrossAwsCredentialsProvider(AWSCredentialsProvider provider) {
// this.credentials = provider.getCredentials();
// }
//
// @Override
// public AwsCredentials resolveCredentials() {
// return AwsBasicCredentials.create(credentials.getAWSAccessKeyId(), credentials.getAWSSecretKey());
// }
// }
//}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
import internal.org.springframework.content.s3.io.S3StoreResource;
import internal.org.springframework.content.s3.io.SimpleStorageResource;
import jakarta.persistence.*;
import junit.framework.Assert;
import lombok.*;
import net.bytebuddy.utility.RandomString;
import org.apache.commons.io.IOUtils;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.content.commons.annotations.ContentId;
import org.springframework.content.commons.annotations.ContentLength;
import org.springframework.content.commons.annotations.MimeType;
Expand All @@ -27,6 +27,7 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.core.env.Environment;
import org.springframework.core.io.Resource;
import org.springframework.core.io.WritableResource;
import org.springframework.data.jpa.repository.JpaRepository;
Expand All @@ -38,6 +39,10 @@
import org.springframework.orm.jpa.vendor.Database;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.transaction.PlatformTransactionManager;
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
import software.amazon.awssdk.auth.credentials.AwsCredentials;
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.model.*;

Expand All @@ -60,7 +65,8 @@
@Ginkgo4jConfiguration(threads=1)
public class S3StoreIT {

private static final String BUCKET = "aws-test-bucket";
// private static final String BUCKET = "aws-test-bucket";
private static final String BUCKET = "spring-eg-content-s3";

static {
System.setProperty("spring.content.s3.bucket", BUCKET);
Expand Down Expand Up @@ -587,9 +593,19 @@ public void test() {
@EnableS3Stores(basePackages="internal.org.springframework.content.s3.it")
@Import(InfrastructureConfig.class)
public static class TestConfig {

@Autowired
private Environment env;

@Bean
public S3Client client() throws URISyntaxException {
return LocalStack.getAmazonS3Client();
AwsCredentials awsCredentials = AwsBasicCredentials.create(env.getProperty("AWS_ACCESS_KEY"), env.getProperty("AWS_SECRET_KEY"));
StaticCredentialsProvider credentialsProvider = StaticCredentialsProvider.create(awsCredentials);

return S3Client.builder()
.region(Region.US_WEST_1)
.credentialsProvider(credentialsProvider)
.build();
}
}

Expand Down
Loading

0 comments on commit 451f7f8

Please sign in to comment.