-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from asavershin/add-imagga
Add imagga
- Loading branch information
Showing
20 changed files
with
683 additions
and
5 deletions.
There are no files selected for viewing
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
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
43 changes: 43 additions & 0 deletions
43
api/src/main/java/com/github/asavershin/api/config/Bucket4jConfig.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,43 @@ | ||
package com.github.asavershin.api.config; | ||
|
||
import io.github.bucket4j.Bandwidth; | ||
import io.github.bucket4j.Bucket; | ||
import io.github.bucket4j.BucketConfiguration; | ||
import io.github.bucket4j.distributed.ExpirationAfterWriteStrategy; | ||
import io.github.bucket4j.distributed.proxy.ClientSideConfig; | ||
import io.github.bucket4j.distributed.proxy.ProxyManager; | ||
import io.github.bucket4j.redis.lettuce.cas.LettuceBasedProxyManager; | ||
import io.lettuce.core.RedisClient; | ||
import io.lettuce.core.RedisURI; | ||
import io.lettuce.core.api.StatefulRedisConnection; | ||
import io.lettuce.core.codec.ByteArrayCodec; | ||
import io.lettuce.core.codec.RedisCodec; | ||
import io.lettuce.core.codec.StringCodec; | ||
import org.springframework.boot.autoconfigure.data.redis.RedisProperties; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.security.core.context.SecurityContextHolder; | ||
import org.springframework.security.core.userdetails.UserDetails; | ||
|
||
import java.time.Duration; | ||
import java.util.function.Supplier; | ||
|
||
@Configuration | ||
public class Bucket4jConfig { | ||
@Bean | ||
public RedisClient redisClient(final RedisProperties redisProperties) { | ||
return RedisClient.create( | ||
RedisURI.Builder.redis(redisProperties.getHost(), redisProperties.getPort()) | ||
.withPassword(redisProperties.getPassword().toCharArray()).build()); | ||
} | ||
|
||
@Bean | ||
public ProxyManager<String> lettuceBasedProxyManager(final RedisClient redisClient) { | ||
StatefulRedisConnection<String, byte[]> redisConnection = redisClient | ||
.connect(RedisCodec.of(StringCodec.UTF8, ByteArrayCodec.INSTANCE)); | ||
|
||
return LettuceBasedProxyManager | ||
.builderFor(redisConnection) | ||
.build(); | ||
} | ||
} |
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
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
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
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,7 @@ | ||
FROM openjdk:21 | ||
|
||
WORKDIR /app | ||
|
||
COPY target/*.jar app.jar | ||
|
||
CMD ["java", "-jar", "-Dspring.profiles.active=imagga", "app.jar"] |
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,52 @@ | ||
networks: | ||
kafka-net: | ||
name: kafka-net | ||
driver: bridge | ||
api-net: | ||
name: api-net | ||
driver: bridge | ||
|
||
services: | ||
|
||
backend-worker-imagga: | ||
container_name: backend-worker-imagga | ||
networks: | ||
- kafka-net | ||
- api-net | ||
build: | ||
context: . | ||
dockerfile: Dockerfile-imagga | ||
ports: | ||
- 8084:8081 | ||
env_file: | ||
- .env | ||
|
||
redis-imagga: | ||
networks: | ||
- api-net | ||
image: redis:7.2-rc-alpine | ||
restart: always | ||
container_name: redis-imagga | ||
ports: | ||
- '6381:6379' | ||
command: redis-server --save 20 1 --loglevel debug --requirepass ${REDIS_PASSWORD} | ||
volumes: | ||
- redis-rotate-data:/data | ||
|
||
# minio-api: | ||
# networks: | ||
# - api-net | ||
# image: minio/minio:RELEASE.2024-02-14T21-36-02Z | ||
# container_name: minio-api | ||
# env_file: | ||
# - .env | ||
# command: server ~/minio --console-address :9090 | ||
# ports: | ||
# - '9090:9090' | ||
# - '9000:9000' | ||
# volumes: | ||
# - minio-api-data:/minio | ||
|
||
volumes: | ||
# minio-api-data: | ||
redis-rotate-data: |
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
7 changes: 7 additions & 0 deletions
7
worker/src/main/java/com/github/asavershin/worker/BadImaggaCodeException.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,7 @@ | ||
package com.github.asavershin.worker; | ||
|
||
public class BadImaggaCodeException extends RuntimeException { | ||
public BadImaggaCodeException(final String s) { | ||
super(s); | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
worker/src/main/java/com/github/asavershin/worker/config/ImaggaConfig.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,68 @@ | ||
package com.github.asavershin.worker.config; | ||
|
||
import io.github.bucket4j.Bandwidth; | ||
import io.github.bucket4j.Bucket; | ||
import io.github.bucket4j.BucketConfiguration; | ||
import io.github.bucket4j.distributed.ExpirationAfterWriteStrategy; | ||
import io.github.bucket4j.distributed.proxy.ClientSideConfig; | ||
import io.github.bucket4j.distributed.proxy.ProxyManager; | ||
import io.github.bucket4j.redis.lettuce.cas.LettuceBasedProxyManager; | ||
import io.lettuce.core.RedisClient; | ||
import io.lettuce.core.RedisURI; | ||
import io.lettuce.core.api.StatefulRedisConnection; | ||
import io.lettuce.core.codec.ByteArrayCodec; | ||
import io.lettuce.core.codec.RedisCodec; | ||
import io.lettuce.core.codec.StringCodec; | ||
import org.springframework.boot.autoconfigure.data.redis.RedisProperties; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.retry.annotation.EnableRetry; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
import java.time.Duration; | ||
|
||
@Configuration | ||
@EnableRetry | ||
@Profile("imagga") | ||
public class ImaggaConfig { | ||
@Bean | ||
public RestTemplate restTemplate() { | ||
return new RestTemplate(); | ||
} | ||
|
||
@Bean | ||
public RedisClient redisClient(final RedisProperties redisProperties) { | ||
return RedisClient.create( | ||
RedisURI.Builder.redis(redisProperties.getHost(), redisProperties.getPort()) | ||
.withPassword(redisProperties.getPassword().toCharArray()).build()); | ||
} | ||
|
||
@Bean | ||
public ProxyManager<String> lettuceBasedProxyManager(final RedisClient redisClient) { | ||
StatefulRedisConnection<String, byte[]> redisConnection = redisClient | ||
.connect(RedisCodec.of(StringCodec.UTF8, ByteArrayCodec.INSTANCE)); | ||
|
||
return LettuceBasedProxyManager | ||
.builderFor(redisConnection) | ||
.build(); | ||
} | ||
|
||
@Bean | ||
public Bucket bucketConfiguration(final ProxyManager<String> proxyManager) { | ||
return proxyManager.builder().build( | ||
"imagga", | ||
() -> BucketConfiguration.builder() | ||
.addLimit( | ||
Bandwidth.builder() | ||
.capacity(33) | ||
.refillIntervally( | ||
33, | ||
Duration.ofDays(1L) | ||
) | ||
.build() | ||
) | ||
.build() | ||
); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
worker/src/main/java/com/github/asavershin/worker/config/ImaggaProperties.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,16 @@ | ||
package com.github.asavershin.worker.config; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
@ConfigurationProperties(prefix = "imagga") | ||
@Getter | ||
@Setter | ||
public class ImaggaProperties { | ||
private String key; | ||
private String secret; | ||
private String ttlprefix; | ||
} |
8 changes: 8 additions & 0 deletions
8
worker/src/main/java/com/github/asavershin/worker/dto/ImagaStatus.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,8 @@ | ||
package com.github.asavershin.worker.dto; | ||
|
||
import lombok.Data; | ||
@Data | ||
public class ImagaStatus { | ||
private String text; | ||
private String type; | ||
} |
Oops, something went wrong.