Files
ccn/Services/Website/Package.swift
T
javier dc6b22e648 Database setup for the Website service (#13)
This PR contains the work done to introduce a _Fluent_-based persistence layer for the Website service, selectable at runtime alongside the existing in-memory default, plus the local dev tooling and docs to support it.

To provide further details about the work:

* Persistence package
  * The `Driver` and `TLS` enumerations
  * The `Configuration` type
  * The `Service` factory that builds the  service
  * `PrepareDB` for migrations registration
  * The `Probe` for readiness checks.

* App integration
  *  Builds the driver, registers migrations, and attaches `Fluent` to the service lifecycle so it starts/stops with the HTTP server.
  * Migrate-on-boot is gated to the in-memory backend; MySQL/MariaDB is migrated out of band via --database-migrate so shared databases never race on startup.
  * The `ConfigReader+Properties` extension maps database.* config keys onto the driver.

* Library
  * Added database configuration constants.
  * The `HealthController` controller gains a readiness probe: `GET /health/ready` checks whether the database is reachable, separate from the existing liveness check.

* Others
  * Updated the `docker-compose` files to support a database service behind a database profile, and hardened for local development
  * New database targets on the `Makefile` file and overall documentation updated
  * Updated the `.env.local`, `Dockerfile`, and `README` files to document the persistence workflow, config keys, and local DB commands

Reviewed-on: rock-n-code/loud-amsterdam#13
Co-authored-by: Javier Cicchelli <javier@rock-n-code.com>
Co-committed-by: Javier Cicchelli <javier@rock-n-code.com>
2026-07-11 09:15:58 +00:00

136 lines
3.9 KiB
Swift

// swift-tools-version: 6.3
import PackageDescription
let package = Package(
name: "Website",
defaultLocalization: "en",
platforms: [
.macOS(.v15),
.iOS(.v18),
.tvOS(.v18),
],
products: [
.executable(
name: "Website",
targets: [
"Website",
"WebsiteCore",
]
)
],
dependencies: [
.package(
path: "../../Packages/Localization"
),
.package(
path: "../../Packages/Persistence"
),
.package(
url: "https://github.com/elementary-swift/elementary.git",
from: "0.6.0"
),
.package(
url: "https://github.com/hummingbird-community/hummingbird-elementary.git",
from: "0.3.0"
),
.package(
url: "https://github.com/hummingbird-project/hummingbird.git",
from: "2.25.0"
),
.package(
url: "https://github.com/hummingbird-project/hummingbird-compression.git",
from: "2.0.0"
),
.package(
url: "https://github.com/apple/swift-configuration.git",
from: "1.0.0",
traits: [
.defaults,
"CommandLineArguments",
]
),
],
targets: [
.executableTarget(
name: "Website",
dependencies: [
.byName(name: "Persistence"),
.byName(name: "WebsiteCore"),
.product(
name: "Configuration",
package: "swift-configuration"
),
.product(
name: "Hummingbird",
package: "hummingbird"
),
.product(
name: "HummingbirdCompression",
package: "hummingbird-compression"
),
],
path: "Sources/App"
),
.target(
name: "WebsiteCore",
dependencies: [
.byName(name: "Localization"),
.byName(name: "Persistence"),
.product(
name: "Configuration",
package: "swift-configuration"
),
.product(
name: "Elementary",
package: "elementary"
),
.product(
name: "Hummingbird",
package: "hummingbird"
),
.product(
name: "HummingbirdElementary",
package: "hummingbird-elementary"
),
],
path: "Sources/Library",
resources: [
// Copied verbatim rather than processed: the String Catalog is read as raw JSON at
// runtime so it resolves identically on Darwin and Linux (which cannot compile it).
.copy("Catalogs/Localizable.xcstrings")
]
),
.testTarget(
name: "WebsiteTests",
dependencies: [
.byName(name: "Website"),
.product(
name: "HummingbirdTesting",
package: "hummingbird"
),
],
path: "Tests/App"
),
.testTarget(
name: "WebsiteCoreTests",
dependencies: [
.byName(name: "WebsiteCore"),
.product(
name: "Elementary",
package: "elementary"
),
.product(
name: "Hummingbird",
package: "hummingbird"
),
.product(
name: "HummingbirdTesting",
package: "hummingbird"
),
],
path: "Tests/Library"
),
]
)