feat: Adds docker support to start building views.
This commit is contained in:
3
.dockerignore
Normal file
3
.dockerignore
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
.build/
|
||||||
|
.swiftpm/
|
||||||
|
|
||||||
@@ -14,7 +14,6 @@ extension SiteRoute.Api {
|
|||||||
return try await route.respond(logger: logger)
|
return try await route.respond(logger: logger)
|
||||||
case .componentLoss(let route):
|
case .componentLoss(let route):
|
||||||
return try await route.respond(logger: logger)
|
return try await route.respond(logger: logger)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ struct DependenciesMiddleware: AsyncMiddleware {
|
|||||||
init(
|
init(
|
||||||
database: DatabaseClient,
|
database: DatabaseClient,
|
||||||
apiController: ApiController = .liveValue,
|
apiController: ApiController = .liveValue,
|
||||||
viewController: ViewController = .testValue
|
viewController: ViewController = .liveValue
|
||||||
) {
|
) {
|
||||||
self.values = withEscapedDependencies { $0 }
|
self.values = withEscapedDependencies { $0 }
|
||||||
self.apiController = apiController
|
self.apiController = apiController
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ public func configure(
|
|||||||
addMiddleware(to: app, database: databaseClient)
|
addMiddleware(to: app, database: databaseClient)
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
// Live reload of the application for development when launched with the `./swift-dev` command
|
// Live reload of the application for development when launched with the `./swift-dev` command
|
||||||
app.lifecycle.use(BrowserSyncHandler())
|
// app.lifecycle.use(BrowserSyncHandler())
|
||||||
#endif
|
#endif
|
||||||
// Add our route handlers.
|
// Add our route handlers.
|
||||||
addRoutes(to: app)
|
addRoutes(to: app)
|
||||||
@@ -72,10 +72,10 @@ private func setupDatabase(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func addRoutes(to app: Application) {
|
private func addRoutes(to app: Application) {
|
||||||
// Redirect the index path to purchase order route.
|
// Redirect the index path to project route.
|
||||||
// app.get { req in
|
app.get { req in
|
||||||
// req.redirect(to: SiteRoute.View.router.path(for: .purchaseOrder(.index)))
|
req.redirect(to: SiteRoute.View.router.path(for: .project(.index)))
|
||||||
// }
|
}
|
||||||
|
|
||||||
app.mount(
|
app.mount(
|
||||||
SiteRoute.router,
|
SiteRoute.router,
|
||||||
|
|||||||
@@ -83,7 +83,6 @@ extension ComponentPressureLoss {
|
|||||||
.field("createdAt", .datetime)
|
.field("createdAt", .datetime)
|
||||||
.field("updatedAt", .datetime)
|
.field("updatedAt", .datetime)
|
||||||
.field("projectID", .uuid, .required, .references(ProjectModel.schema, "id"))
|
.field("projectID", .uuid, .required, .references(ProjectModel.schema, "id"))
|
||||||
// .foreignKey("projectID", references: ProjectModel.schema, "id", onDelete: .cascade)
|
|
||||||
.unique(on: "projectID", "name")
|
.unique(on: "projectID", "name")
|
||||||
.create()
|
.create()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ extension SiteRoute {
|
|||||||
public enum View: Equatable, Sendable {
|
public enum View: Equatable, Sendable {
|
||||||
case project(ProjectRoute)
|
case project(ProjectRoute)
|
||||||
|
|
||||||
static let router = OneOf {
|
public static let router = OneOf {
|
||||||
Route(.case(Self.project)) {
|
Route(.case(Self.project)) {
|
||||||
SiteRoute.View.ProjectRoute.router
|
SiteRoute.View.ProjectRoute.router
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,18 @@ extension ViewController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension ViewController: TestDependencyKey {
|
extension ViewController: DependencyKey {
|
||||||
public static let testValue = Self()
|
public static let testValue = Self()
|
||||||
|
|
||||||
|
// FIX: Fix.
|
||||||
|
public static let liveValue = Self(
|
||||||
|
view: { _ in
|
||||||
|
return MainPage {
|
||||||
|
div {
|
||||||
|
h1 { "It works!" }
|
||||||
|
h2 { "Browser sync works!" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
93
docker/Dockerfile
Normal file
93
docker/Dockerfile
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
# ================================
|
||||||
|
# Build image
|
||||||
|
# ================================
|
||||||
|
FROM docker.io/swift:6.2-noble AS build
|
||||||
|
|
||||||
|
# Install OS updates
|
||||||
|
RUN export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true \
|
||||||
|
&& apt-get -q update \
|
||||||
|
&& apt-get -q dist-upgrade -y \
|
||||||
|
&& apt-get install -y libjemalloc-dev
|
||||||
|
|
||||||
|
# Set up a build area
|
||||||
|
WORKDIR /build
|
||||||
|
|
||||||
|
# First just resolve dependencies.
|
||||||
|
# This creates a cached layer that can be reused
|
||||||
|
# as long as your Package.swift/Package.resolved
|
||||||
|
# files do not change.
|
||||||
|
COPY ./Package.* ./
|
||||||
|
RUN swift package resolve \
|
||||||
|
$([ -f ./Package.resolved ] && echo "--force-resolved-versions" || true)
|
||||||
|
|
||||||
|
# Copy entire repo into container
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
# Build the application, with optimizations, with static linking, and using jemalloc
|
||||||
|
# N.B.: The static version of jemalloc is incompatible with the static Swift runtime.
|
||||||
|
RUN swift build -c release \
|
||||||
|
--product App \
|
||||||
|
--static-swift-stdlib \
|
||||||
|
-Xlinker -ljemalloc
|
||||||
|
|
||||||
|
# Switch to the staging area
|
||||||
|
WORKDIR /staging
|
||||||
|
|
||||||
|
# Copy main executable to staging area
|
||||||
|
RUN cp "$(swift build --package-path /build -c release --show-bin-path)/App" ./
|
||||||
|
|
||||||
|
# Copy static swift backtracer binary to staging area
|
||||||
|
RUN cp "/usr/libexec/swift/linux/swift-backtrace-static" ./
|
||||||
|
|
||||||
|
# Copy resources bundled by SPM to staging area
|
||||||
|
RUN find -L "$(swift build --package-path /build -c release --show-bin-path)/" -regex '.*\.resources$' -exec cp -Ra {} ./ \;
|
||||||
|
|
||||||
|
# Copy any resources from the public directory and views directory if the directories exist
|
||||||
|
# Ensure that by default, neither the directory nor any of its contents are writable.
|
||||||
|
RUN [ -d /build/Public ] && { mv /build/Public ./Public && chmod -R a-w ./Public; } || true
|
||||||
|
RUN [ -d /build/Resources ] && { mv /build/Resources ./Resources && chmod -R a-w ./Resources; } || true
|
||||||
|
|
||||||
|
# ================================
|
||||||
|
# Run image
|
||||||
|
# ================================
|
||||||
|
FROM docker.io/ubuntu:noble
|
||||||
|
|
||||||
|
# Make sure all system packages are up to date, and install only essential packages.
|
||||||
|
RUN export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true \
|
||||||
|
&& apt-get -q update \
|
||||||
|
&& apt-get -q dist-upgrade -y \
|
||||||
|
&& apt-get -q install -y \
|
||||||
|
libjemalloc2 \
|
||||||
|
ca-certificates \
|
||||||
|
tzdata \
|
||||||
|
# If your app or its dependencies import FoundationNetworking, also install `libcurl4`.
|
||||||
|
libcurl4 \
|
||||||
|
# If your app or its dependencies import FoundationXML, also install `libxml2`.
|
||||||
|
# libxml2 \
|
||||||
|
sqlite3 \
|
||||||
|
curl \
|
||||||
|
&& rm -r /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
# Create a vapor user and group with /app as its home directory
|
||||||
|
RUN useradd --user-group --create-home --system --skel /dev/null --home-dir /app vapor
|
||||||
|
|
||||||
|
# Switch to the new home directory
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Copy built executable and any staged resources from builder
|
||||||
|
COPY --from=build --chown=vapor:vapor /staging /app
|
||||||
|
|
||||||
|
# Provide configuration needed by the built-in crash reporter and some sensible default behaviors.
|
||||||
|
ENV SWIFT_BACKTRACE=enable=yes,sanitize=yes,threads=all,images=all,interactive=no,swift-backtrace=./swift-backtrace-static
|
||||||
|
ENV LOG_LEVEL=debug
|
||||||
|
|
||||||
|
# Ensure all further commands run as the vapor user
|
||||||
|
USER vapor:vapor
|
||||||
|
|
||||||
|
# Let Docker bind to port 8080
|
||||||
|
EXPOSE 8080
|
||||||
|
|
||||||
|
# Start the Vapor service when the image is run, default to listening on 8080 in production environment
|
||||||
|
ENTRYPOINT ["./App"]
|
||||||
|
CMD ["serve", "--env", "production", "--hostname", "0.0.0.0", "--port", "8080"]
|
||||||
|
|
||||||
46
docker/Dockerfile.dev
Normal file
46
docker/Dockerfile.dev
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
FROM swift:6.2-noble
|
||||||
|
|
||||||
|
# Make sure all system packages are up to date, and install only essential packages.
|
||||||
|
RUN export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true \
|
||||||
|
&& apt-get -q update \
|
||||||
|
&& apt-get -q dist-upgrade -y \
|
||||||
|
&& apt-get -q install -y \
|
||||||
|
libjemalloc2 \
|
||||||
|
ca-certificates \
|
||||||
|
tzdata \
|
||||||
|
# If your app or its dependencies import FoundationNetworking, also install `libcurl4`.
|
||||||
|
libcurl4 \
|
||||||
|
# If your app or its dependencies import FoundationXML, also install `libxml2`.
|
||||||
|
# libxml2 \
|
||||||
|
sqlite3 \
|
||||||
|
nodejs \
|
||||||
|
npm \
|
||||||
|
build-essential \
|
||||||
|
curl \
|
||||||
|
&& rm -r /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
# Set up a build area
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# First just resolve dependencies.
|
||||||
|
# This creates a cached layer that can be reused
|
||||||
|
# as long as your Package.swift/Package.resolved
|
||||||
|
# files do not change.
|
||||||
|
COPY ./Package.* ./
|
||||||
|
RUN swift package resolve \
|
||||||
|
$([ -f ./Package.resolved ] && echo "--force-resolved-versions" || true)
|
||||||
|
|
||||||
|
# Copy entire repo into container
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
RUN curl -L https://github.com/watchexec/watchexec/releases/download/v2.3.2/watchexec-2.3.2-aarch64-unknown-linux-gnu.tar.xz --output watchexec.tar.xz \
|
||||||
|
&& tar -xvf watchexec.tar.xz \
|
||||||
|
&& cp ./watchexec-2.3.2-aarch64-unknown-linux-gnu/watchexec /bin
|
||||||
|
|
||||||
|
RUN npm install -g browser-sync
|
||||||
|
|
||||||
|
ENV SWIFT_BACKTRACE=enable=no
|
||||||
|
ENV LOG_LEVEL=debug
|
||||||
|
|
||||||
|
CMD ["swift", "test"]
|
||||||
|
|
||||||
7
justfile
Normal file
7
justfile
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
docker_image := "manuald"
|
||||||
|
|
||||||
|
build-docker:
|
||||||
|
@podman build -f docker/Dockerfile.dev -t {{docker_image}}:dev .
|
||||||
|
|
||||||
|
run-dev:
|
||||||
|
@podman run -it --rm -v $PWD:/app -p 3000:3000 -p 3002:3002 -p 8080:8080 {{docker_image}}:dev ./swift-dev
|
||||||
5
swift-dev
Executable file
5
swift-dev
Executable file
@@ -0,0 +1,5 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
touch .build/browser-dev-sync
|
||||||
|
browser-sync start -p 0.0.0.0:8080 --ws --no-open &
|
||||||
|
watchexec -w Sources -e .swift -r 'swift build --product App && touch .build/browser-dev-sync' &
|
||||||
|
watchexec -w .build/browser-dev-sync --ignore-nothing -r '.build/debug/App'
|
||||||
Reference in New Issue
Block a user