diff --git a/Package.resolved b/Package.resolved index 0576f3057..9fbe54ca3 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,5 +1,5 @@ { - "originHash" : "866e94bc132edee83eaa6b275b7a8b0a6d085f2a48ddb7a68b2c1132b864abb6", + "originHash" : "192dccdf148d5caa938e0fe6f73a430a5348c38ffd64a906ae36e2d45449805b", "pins" : [ { "identity" : "async-http-client", @@ -163,6 +163,24 @@ "version" : "1.23.0" } }, + { + "identity" : "redis", + "kind" : "remoteSourceControl", + "location" : "https://github.com/vapor/redis.git", + "state" : { + "revision" : "383ed57e5b5acd4dd447c2967aa665dc3bbe5be9", + "version" : "4.11.0" + } + }, + { + "identity" : "redistack", + "kind" : "remoteSourceControl", + "location" : "https://github.com/swift-server/RediStack.git", + "state" : { + "revision" : "622ce440f90d79b58e45f3a3efdd64c51d1dfd17", + "version" : "1.6.2" + } + }, { "identity" : "routing-kit", "kind" : "remoteSourceControl", diff --git a/Package.swift b/Package.swift index 70e2c2cf0..bc6225c79 100644 --- a/Package.swift +++ b/Package.swift @@ -48,6 +48,7 @@ let package = Package( .package(url: "https://github.com/vapor/fluent-postgres-driver.git", from: "2.0.0"), .package(url: "https://github.com/vapor/fluent.git", from: "4.0.0"), .package(url: "https://github.com/vapor/jwt-kit.git", from: "4.13.0"), + .package(url: "https://github.com/vapor/redis.git", from: "4.0.0"), .package(url: "https://github.com/vapor/vapor.git", from: "4.102.0"), ], targets: [ @@ -71,6 +72,7 @@ let package = Package( .product(name: "Fluent", package: "fluent"), .product(name: "FluentPostgresDriver", package: "fluent-postgres-driver"), .product(name: "Parsing", package: "swift-parsing"), + .product(name: "Redis", package: "redis"), .product(name: "ShellOut", package: "ShellOut"), .product(name: "SwiftPMDataModel-auto", package: "swift-package-manager"), .product(name: "SwiftPMPackageCollections", package: "swift-package-manager"), diff --git a/Sources/App/configure.swift b/Sources/App/configure.swift index 7102fc490..e1846a1b9 100644 --- a/Sources/App/configure.swift +++ b/Sources/App/configure.swift @@ -14,8 +14,10 @@ import Fluent import FluentPostgresDriver +import Redis import Vapor + @discardableResult public func configure(_ app: Application) async throws -> String { #if DEBUG && os(macOS) @@ -49,6 +51,7 @@ public func configure(_ app: Application) async throws -> String { // This parameter could also be made configurable via an env variable. let maxConnectionsPerEventLoop = 3 + // Setup database connection guard let host = Environment.get("DATABASE_HOST"), let port = Environment.get("DATABASE_PORT").flatMap(Int.init), @@ -75,6 +78,13 @@ public func configure(_ app: Application) async throws -> String { sqlLogLevel: .debug), as: .psql) + // Setup Redis connection + do { + app.redis.configuration = try RedisConfiguration(hostname: "redis") + } catch { + app.logger.warning("Failed to configure Redis, caching disabled. Error: \(error)") + } + do { // Migration 001 - schema 1.0 app.migrations.add(CreatePackage()) app.migrations.add(CreateRepository()) diff --git a/app.yml b/app.yml index a7e1b39f2..52d014365 100644 --- a/app.yml +++ b/app.yml @@ -161,23 +161,38 @@ services: - backend alerting: - image: registry.gitlab.com/finestructure/swiftpackageindex:${VERSION} - <<: *shared - depends_on: - - migrate - entrypoint: ["/bin/bash"] - command: ["-c", "--", + image: registry.gitlab.com/finestructure/swiftpackageindex:${VERSION} + <<: *shared + depends_on: + - migrate + entrypoint: ["/bin/bash"] + command: ["-c", "--", "trap : TERM INT; while true; do ./Run alerting --env ${ENV} --time-period ${ALERTING_TIME_PERIOD:-4} --limit ${ALERTING_LIMIT:-2000}; sleep ${ALERTING_SLEEP:-300}; done" - ] - deploy: - resources: - limits: - memory: 0.5GB - restart_policy: + ] + deploy: + resources: + limits: + memory: 0.5GB + restart_policy: max_attempts: 5 - networks: - - backend + networks: + - backend + redis: + # Eventually we'll probably want to use redis/redis-stack-server:7.4.0-v1 here, + # which excludes the RedisInsight GUI front-end. + image: redis/redis-stack:7.4.0-v1 + environment: + REDIS_ARGS: '--maxmemory 4GB --maxmemory-policy allkeys-lru' + ports: + - '6379:6379' + - '8001:8001' + deploy: + resources: + limits: + memory: 4.2GB + networks: + - backend migrate: image: registry.gitlab.com/finestructure/swiftpackageindex:${VERSION}