Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #4

Merged
merged 3 commits into from
Feb 3, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 7 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@

Don't forget to check the sample code repository on [GitHub](https://github.com/tib/practical-server-side-swift).

### Second edition - v1.4.0
### Third edition - v1.5.0

- Swift 5.6+
- Vapor 4.65.0+
- Xcode 14 beta support

### Third edition - v1.4.0

- Swift async / await support
- Xcode 13 support
Expand Down
6 changes: 3 additions & 3 deletions Chapter 02/SPM/Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.5
// swift-tools-version:5.6
import PackageDescription

let package = Package(
Expand All @@ -10,10 +10,10 @@ let package = Package(
.executable(name: "myProject", targets: ["myProject"]),
],
dependencies: [
.package(url: "https://github.com/vapor/vapor", from: "4.54.0"),
.package(url: "https://github.com/vapor/vapor", from: "4.65.0"),
],
targets: [
.target(name: "myProject", dependencies: [
.executableTarget(name: "myProject", dependencies: [
.product(name: "Vapor", package: "vapor")
]),
.testTarget(name: "myProjectTests", dependencies: ["myProject"]),
Expand Down
2 changes: 1 addition & 1 deletion Chapter 02/VaporToolbox/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ DerivedData/
.DS_Store
db.sqlite
.swiftpm

.env
31 changes: 22 additions & 9 deletions Chapter 02/VaporToolbox/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ================================
# Build image
# ================================
FROM swift:5.4-focal as build
FROM swift:5.6-focal as build

# Install OS updates and, if needed, sqlite3
RUN export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true \
Expand All @@ -22,27 +22,40 @@ RUN swift package resolve
# Copy entire repo into container
COPY . .

# Build everything, with optimizations and test discovery
RUN swift build --enable-test-discovery -c release
# Build everything, with optimizations
RUN swift build -c release --static-swift-stdlib

# 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)/Run" ./

# Uncomment the next line if you need to load resources from the `Public` directory.
# 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 mv /build/Public ./Public && chmod -R a-w ./Public
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 swift:5.4-focal-slim
FROM ubuntu:focal

# Make sure all system packages are up to date.
RUN export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true && \
apt-get -q update && apt-get -q dist-upgrade -y && rm -r /var/lib/apt/lists/*
# 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 \
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 \
&& 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
Expand Down
13 changes: 7 additions & 6 deletions Chapter 02/VaporToolbox/Package.swift
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// swift-tools-version:5.3
// swift-tools-version:5.6
import PackageDescription

let package = Package(
name: "myProject",
name: "VaporToolbox",
platforms: [
.macOS(.v10_15)
.macOS(.v12)
],
dependencies: [
.package(url: "https://github.com/vapor/vapor", from: "4.54.0")
// 💧 A server-side Swift web framework.
.package(url: "https://github.com/vapor/vapor.git", from: "4.0.0"),
],
targets: [
.target(
Expand All @@ -18,11 +19,11 @@ let package = Package(
swiftSettings: [
// Enable better optimizations when building in Release configuration. Despite the use of
// the `.unsafeFlags` construct required by SwiftPM, this flag is recommended for Release
// builds. See <https://github.com/swift-server/guides#building-for-production> for details.
// builds. See <https://github.com/swift-server/guides/blob/main/docs/building.md#building-for-production> for details.
.unsafeFlags(["-cross-module-optimization"], .when(configuration: .release))
]
),
.target(name: "Run", dependencies: [.target(name: "App")]),
.executableTarget(name: "Run", dependencies: [.target(name: "App")]),
.testTarget(name: "AppTests", dependencies: [
.target(name: "App"),
.product(name: "XCTVapor", package: "vapor"),
Expand Down
8 changes: 4 additions & 4 deletions Chapter 02/VaporToolbox/Sources/App/routes.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import Vapor

func routes(_ app: Application) throws {
app.get { req in
return "It works!"
app.get { req async in
"It works!"
}

app.get("hello") { req -> String in
return "Hello, world!"
app.get("hello") { req async -> String in
"Hello, world!"
}
}
4 changes: 2 additions & 2 deletions Chapter 02/VaporToolbox/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ version: '3.7'

x-shared_environment: &shared_environment
LOG_LEVEL: ${LOG_LEVEL:-debug}

services:
app:
image: myProject:latest
image: vapor-toolbox:latest
build:
context: .
environment:
Expand Down
6 changes: 3 additions & 3 deletions Chapter 03/myProject/Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.5
// swift-tools-version:5.6
import PackageDescription

let package = Package(
Expand All @@ -7,8 +7,8 @@ let package = Package(
.macOS(.v12)
],
dependencies: [
.package(url: "https://github.com/vapor/vapor", from: "4.54.0"),
.package(url: "https://github.com/binarybirds/swift-html", from: "1.2.0"),
.package(url: "https://github.com/vapor/vapor", from: "4.65.0"),
.package(url: "https://github.com/binarybirds/swift-html", from: "1.6.0"),
],
targets: [
.target(name: "App", dependencies: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ enum BlogMigrations {
func revert(on db: Database) async throws {
try await db.schema(BlogCategoryModel.schema).delete()
try await db.schema(BlogPostModel.schema).delete()
try await db.schema(BlogPostModel.schema).delete()
}
}

Expand Down