Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM registry.gitlab.com/finestructure/spi-base:1.2.2
FROM registry.gitlab.com/finestructure/spi-base:b1b04e30539d3e29f6e2b2ce31e1edfadae33077

# Install SPM build dependencies
RUN apt-get update && apt-get install -y curl git make unzip \
Expand Down
13 changes: 10 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
name: Test
runs-on: ubuntu-latest
container:
image: registry.gitlab.com/finestructure/spi-base:1.2.2
image: registry.gitlab.com/finestructure/spi-base:b1b04e30539d3e29f6e2b2ce31e1edfadae33077
options: --privileged
steps:
- name: GH Runner bug workaround
Expand All @@ -52,7 +52,11 @@ jobs:
restore-keys: "spi-debug-build-${{ runner.os }}-"

- name: Build tests
run: cp .env.testing.template .env.testing && make build-tests
run: |
# Fix for
# fatal: detected dubious ownership in repository at '/__w/SwiftPackageIndex-Server/SwiftPackageIndex-Server'
git config --global --add safe.directory /__w/SwiftPackageIndex-Server/SwiftPackageIndex-Server
cp .env.testing.template .env.testing && make build-tests

- name: Cache .build
if: steps.restore-cache.outputs.cache-hit != 'true'
Expand Down Expand Up @@ -160,7 +164,7 @@ jobs:
name: Release build
runs-on: ubuntu-latest
container:
image: registry.gitlab.com/finestructure/spi-base:1.2.2
image: registry.gitlab.com/finestructure/spi-base:b1b04e30539d3e29f6e2b2ce31e1edfadae33077
options: --privileged
steps:
- name: GH Runner bug workaround
Expand All @@ -184,6 +188,9 @@ jobs:

- name: Build release
run: |
# Fix for
# fatal: detected dubious ownership in repository at '/__w/SwiftPackageIndex-Server/SwiftPackageIndex-Server'
git config --global --add safe.directory /__w/SwiftPackageIndex-Server/SwiftPackageIndex-Server
# Since we're only pinging the version api endpoint, no database is needed and
# we can just copy the development template to ensure the db env variables are set.
cp .env.development.template .env.development
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/query-performance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
runs-on: ubuntu-latest
continue-on-error: true
container:
image: registry.gitlab.com/finestructure/spi-base:1.2.2
image: registry.gitlab.com/finestructure/spi-base:b1b04e30539d3e29f6e2b2ce31e1edfadae33077
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand All @@ -47,7 +47,11 @@ jobs:
restore-keys: "spi-query-performance-build-${{ runner.os }}-"

- name: Build tests
run: cp .env.testing.template .env.testing && make build-tests
run: |
# Fix for
# fatal: detected dubious ownership in repository at '/__w/SwiftPackageIndex-Server/SwiftPackageIndex-Server'
git config --global --add safe.directory /__w/SwiftPackageIndex-Server/SwiftPackageIndex-Server
cp .env.testing.template .env.testing && make build-tests

- name: Cache .build
if: steps.restore-cache.outputs.cache-hit != 'true'
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# ================================
# Build image
# ================================
FROM registry.gitlab.com/finestructure/spi-base:1.2.2 as build
FROM registry.gitlab.com/finestructure/spi-base:b1b04e30539d3e29f6e2b2ce31e1edfadae33077 as build

# Set up a build area
WORKDIR /build
Expand Down Expand Up @@ -62,7 +62,7 @@ RUN [ -d /build/Resources ] && { mv /build/Resources ./Resources && chmod -R a-w
# ================================
# Run image
# ================================
FROM registry.gitlab.com/finestructure/spi-base:1.2.2
FROM registry.gitlab.com/finestructure/spi-base:b1b04e30539d3e29f6e2b2ce31e1edfadae33077

# NB sas 2022-09-23: We're not using a dedicated `vapor` user to run the executable, because it
# makes managing the data in the checkouts volume difficult. See
Expand Down
2 changes: 1 addition & 1 deletion LOCAL_DEVELOPMENT_SETUP.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ The trickiest part of this is to ensure the test or app container can connect to
So, in order to run the tests in a Linux container run:

```
docker run --rm -v "$PWD":/host -w /host --add-host=host.docker.internal:host-gateway registry.gitlab.com/finestructure/spi-base:1.2.2 swift test
docker run --rm -v "$PWD":/host -w /host --add-host=host.docker.internal:host-gateway registry.gitlab.com/finestructure/spi-base:b1b04e30539d3e29f6e2b2ce31e1edfadae33077 swift test
```

Make sure you use the most recent `spi-base` image. You can find the latest image name in the `test-docker` target, which also provides a convenient way to run all all tests in a docker container.
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ test-docker:
@# run tests inside a docker container
docker run --rm -v "$(PWD)":/host -w /host \
--add-host=host.docker.internal:host-gateway \
registry.gitlab.com/finestructure/spi-base:1.2.2 \
registry.gitlab.com/finestructure/spi-base:b1b04e30539d3e29f6e2b2ce31e1edfadae33077 \
make test

test-e2e: db-reset reconcile ingest analyze
Expand Down
6 changes: 3 additions & 3 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ let package = Package(
.package(url: "https://github.com/SwiftPackageIndex/DependencyResolution.git", from: "1.1.2"),
.package(url: "https://github.com/SwiftPackageIndex/SPIManifest.git", from: "1.9.0"),
.package(url: "https://github.com/SwiftPackageIndex/SemanticVersion.git", from: "0.3.0"),
.package(url: "https://github.com/SwiftPackageIndex/ShellOut.git", from: "3.1.4"),
.package(url: "https://github.com/SwiftPackageIndex/ShellOut.git", from: "3.3.0"),
.package(url: "https://github.com/finestructure/swift-package-manager.git", branch: "release/6.1"),
.package(url: "https://github.com/pointfreeco/swift-custom-dump.git", from: "1.0.0"),
.package(url: "https://github.com/pointfreeco/swift-dependencies", from: "1.8.0"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
}


extension PackageCollectionSigning.Model.SignedCollection: @retroactive @unchecked Sendable, Vapor.Content {}
extension PackageCollectionSigning.Model.SignedCollection: Vapor.Content {}

Check warning on line 64 in Sources/App/Controllers/API/API+PackageCollectionController.swift

View workflow job for this annotation

GitHub Actions / Query Performance Test

extension declares a conformance of imported type 'SignedCollection' to imported protocols 'RequestDecodable', 'ResponseEncodable', 'AsyncRequestDecodable', 'AsyncResponseEncodable'; this will not behave correctly if the owners of 'PackageCollectionsModel' introduce this conformance in the future

Check warning on line 64 in Sources/App/Controllers/API/API+PackageCollectionController.swift

View workflow job for this annotation

GitHub Actions / Query Performance Test

extension declares a conformance of imported type 'SignedCollection' to imported protocols 'RequestDecodable', 'ResponseEncodable', 'AsyncRequestDecodable', 'AsyncResponseEncodable'; this will not behave correctly if the owners of 'PackageCollectionsModel' introduce this conformance in the future

Check warning on line 64 in Sources/App/Controllers/API/API+PackageCollectionController.swift

View workflow job for this annotation

GitHub Actions / Query Performance Test

extension declares a conformance of imported type 'SignedCollection' to imported protocols 'RequestDecodable', 'ResponseEncodable', 'AsyncRequestDecodable', 'AsyncResponseEncodable'; this will not behave correctly if the owners of 'PackageCollectionsModel' introduce this conformance in the future

Check warning on line 64 in Sources/App/Controllers/API/API+PackageCollectionController.swift

View workflow job for this annotation

GitHub Actions / Query Performance Test

extension declares a conformance of imported type 'SignedCollection' to imported protocols 'RequestDecodable', 'ResponseEncodable', 'AsyncRequestDecodable', 'AsyncResponseEncodable'; this will not behave correctly if the owners of 'PackageCollectionsModel' introduce this conformance in the future

Check warning on line 64 in Sources/App/Controllers/API/API+PackageCollectionController.swift

View workflow job for this annotation

GitHub Actions / Query Performance Test

extension declares a conformance of imported type 'SignedCollection' to imported protocols 'RequestDecodable', 'ResponseEncodable', 'AsyncRequestDecodable', 'AsyncResponseEncodable'; this will not behave correctly if the owners of 'PackageCollectionsModel' introduce this conformance in the future

Check warning on line 64 in Sources/App/Controllers/API/API+PackageCollectionController.swift

View workflow job for this annotation

GitHub Actions / Query Performance Test

extension declares a conformance of imported type 'SignedCollection' to imported protocols 'RequestDecodable', 'ResponseEncodable', 'AsyncRequestDecodable', 'AsyncResponseEncodable'; this will not behave correctly if the owners of 'PackageCollectionsModel' introduce this conformance in the future

Check warning on line 64 in Sources/App/Controllers/API/API+PackageCollectionController.swift

View workflow job for this annotation

GitHub Actions / Query Performance Test

extension declares a conformance of imported type 'SignedCollection' to imported protocols 'RequestDecodable', 'ResponseEncodable', 'AsyncRequestDecodable', 'AsyncResponseEncodable'; this will not behave correctly if the owners of 'PackageCollectionsModel' introduce this conformance in the future

Check warning on line 64 in Sources/App/Controllers/API/API+PackageCollectionController.swift

View workflow job for this annotation

GitHub Actions / Query Performance Test

extension declares a conformance of imported type 'SignedCollection' to imported protocols 'RequestDecodable', 'ResponseEncodable', 'AsyncRequestDecodable', 'AsyncResponseEncodable'; this will not behave correctly if the owners of 'PackageCollectionsModel' introduce this conformance in the future

Check warning on line 64 in Sources/App/Controllers/API/API+PackageCollectionController.swift

View workflow job for this annotation

GitHub Actions / Test

extension declares a conformance of imported type 'SignedCollection' to imported protocols 'RequestDecodable', 'ResponseEncodable', 'AsyncRequestDecodable', 'AsyncResponseEncodable'; this will not behave correctly if the owners of 'PackageCollectionsModel' introduce this conformance in the future

Check warning on line 64 in Sources/App/Controllers/API/API+PackageCollectionController.swift

View workflow job for this annotation

GitHub Actions / Test

extension declares a conformance of imported type 'SignedCollection' to imported protocols 'RequestDecodable', 'ResponseEncodable', 'AsyncRequestDecodable', 'AsyncResponseEncodable'; this will not behave correctly if the owners of 'PackageCollectionsModel' introduce this conformance in the future

Check warning on line 64 in Sources/App/Controllers/API/API+PackageCollectionController.swift

View workflow job for this annotation

GitHub Actions / Test

extension declares a conformance of imported type 'SignedCollection' to imported protocols 'RequestDecodable', 'ResponseEncodable', 'AsyncRequestDecodable', 'AsyncResponseEncodable'; this will not behave correctly if the owners of 'PackageCollectionsModel' introduce this conformance in the future

Check warning on line 64 in Sources/App/Controllers/API/API+PackageCollectionController.swift

View workflow job for this annotation

GitHub Actions / Test

extension declares a conformance of imported type 'SignedCollection' to imported protocols 'RequestDecodable', 'ResponseEncodable', 'AsyncRequestDecodable', 'AsyncResponseEncodable'; this will not behave correctly if the owners of 'PackageCollectionsModel' introduce this conformance in the future

Check warning on line 64 in Sources/App/Controllers/API/API+PackageCollectionController.swift

View workflow job for this annotation

GitHub Actions / Test

extension declares a conformance of imported type 'SignedCollection' to imported protocols 'RequestDecodable', 'ResponseEncodable', 'AsyncRequestDecodable', 'AsyncResponseEncodable'; this will not behave correctly if the owners of 'PackageCollectionsModel' introduce this conformance in the future

Check warning on line 64 in Sources/App/Controllers/API/API+PackageCollectionController.swift

View workflow job for this annotation

GitHub Actions / Test

extension declares a conformance of imported type 'SignedCollection' to imported protocols 'RequestDecodable', 'ResponseEncodable', 'AsyncRequestDecodable', 'AsyncResponseEncodable'; this will not behave correctly if the owners of 'PackageCollectionsModel' introduce this conformance in the future

Check warning on line 64 in Sources/App/Controllers/API/API+PackageCollectionController.swift

View workflow job for this annotation

GitHub Actions / Test

extension declares a conformance of imported type 'SignedCollection' to imported protocols 'RequestDecodable', 'ResponseEncodable', 'AsyncRequestDecodable', 'AsyncResponseEncodable'; this will not behave correctly if the owners of 'PackageCollectionsModel' introduce this conformance in the future

Check warning on line 64 in Sources/App/Controllers/API/API+PackageCollectionController.swift

View workflow job for this annotation

GitHub Actions / Test

extension declares a conformance of imported type 'SignedCollection' to imported protocols 'RequestDecodable', 'ResponseEncodable', 'AsyncRequestDecodable', 'AsyncResponseEncodable'; this will not behave correctly if the owners of 'PackageCollectionsModel' introduce this conformance in the future


extension API {
Expand Down
51 changes: 26 additions & 25 deletions Sources/App/Core/Dependencies/RedisClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ import NIOCore
import Dependencies
import DependenciesMacros

@globalActor
actor RedisSingletonActor {
static let shared = RedisSingletonActor()
}

@DependencyClient
struct RedisClient {
Expand All @@ -42,11 +46,11 @@ extension RedisClient: DependencyKey {
static var liveValue: RedisClient {
.init(
set: { key, value, expiresIn in
try await Redis.shared.set(key: key, value: value, expiresIn: expiresIn)
try await Redis.shared().set(key: key, value: value, expiresIn: expiresIn)
},
get: { key in try await Redis.shared.get(key: key) },
expire: { key, ttl in try await Redis.shared.expire(key: key, after: ttl) },
increment: { key, value in try await Redis.shared.increment(key: key, by: value) }
get: { key in try await Redis.shared().get(key: key) },
expire: { key, ttl in try await Redis.shared().expire(key: key, after: ttl) },
increment: { key, value in try await Redis.shared().increment(key: key, by: value) }
)
}
}
Expand Down Expand Up @@ -79,30 +83,27 @@ extension RedisClient {

private actor Redis {
var client: RediStack.RedisClient
static private var task: Task<Redis, Swift.Error>?
@RedisSingletonActor private static var _shared: Redis?

static var shared: Redis {
get async throws {
if let task {
return try await task.value
}
let task = Task<Redis, Swift.Error> {
var attemptsLeft = maxConnectionAttempts
while attemptsLeft > 0 {
do {
return try await Redis()
} catch {
attemptsLeft -= 1
@Dependency(\.logger) var logger
logger.warning("Redis connection failed, \(attemptsLeft) attempts left. Error: \(error)")
try? await Task.sleep(for: .milliseconds(500))
}
}
throw Error.unavailable
@RedisSingletonActor
static func shared() async throws -> Redis {
if let existing = _shared {
return existing
}
var attemptsLeft = maxConnectionAttempts
while attemptsLeft > 0 {
do {
let instance = try await Redis()
_shared = instance
return instance
} catch {
attemptsLeft -= 1
@Dependency(\.logger) var logger
logger.warning("Redis connection failed, \(attemptsLeft) attempts left. Error: \(error)")
try? await Task.sleep(for: .milliseconds(500))
}
self.task = task
return try await task.value
}
throw Error.unavailable
}

enum Error: Swift.Error {
Expand Down
2 changes: 1 addition & 1 deletion Sources/App/Core/Extensions/ShellOutCommand+ext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,5 @@ extension ShellOutCommand {


extension Reference {
var quoted: Argument { description.quoted }
var quoted: ShellArgument { description.quoted }
}
Loading