Skip to content

Commit 482ea4c

Browse files
authored
Examples: Add a Hello World example (#1)
### Motivation Having a simple "getting started" example is helpful for new users. ### Modifications Adds the first example, using Vapor, and links it into the documentation. ### Result New users can start from a tested starting point. ### Test Plan Built and deployed the example locally, and ran the soundness checks.
1 parent 5b6a258 commit 482ea4c

File tree

6 files changed

+279
-1
lines changed

6 files changed

+279
-1
lines changed

Examples/HelloWorldVapor/.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.DS_Store
2+
/.build
3+
/Packages
4+
xcuserdata/
5+
DerivedData/
6+
.swiftpm/configuration/registries.json
7+
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
8+
.netrc

Examples/HelloWorldVapor/Package.resolved

Lines changed: 213 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// swift-tools-version: 6.0
2+
3+
//===----------------------------------------------------------------------===//
4+
//
5+
// This source file is part of the SwiftContainerPlugin open source project
6+
//
7+
// Copyright (c) 2024 Apple Inc. and the SwiftContainerPlugin project authors
8+
// Licensed under Apache License v2.0
9+
//
10+
// See LICENSE.txt for license information
11+
// See CONTRIBUTORS.txt for the list of SwiftContainerPlugin project authors
12+
//
13+
// SPDX-License-Identifier: Apache-2.0
14+
//
15+
//===----------------------------------------------------------------------===//
16+
17+
import PackageDescription
18+
19+
let package = Package(
20+
name: "hello-world",
21+
platforms: [.macOS(.v13)],
22+
dependencies: [
23+
.package(url: "https://github.com/vapor/vapor", .upToNextMajor(from: "4.102.0")),
24+
.package(url: "https://github.com/apple/swift-container-plugin", from: "0.1.0"),
25+
],
26+
targets: [.executableTarget(name: "hello-world", dependencies: [.product(name: "Vapor", package: "vapor")])]
27+
)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the SwiftContainerPlugin open source project
4+
//
5+
// Copyright (c) 2024 Apple Inc. and the SwiftContainerPlugin project authors
6+
// Licensed under Apache License v2.0
7+
//
8+
// See LICENSE.txt for license information
9+
// See CONTRIBUTORS.txt for the list of SwiftContainerPlugin project authors
10+
//
11+
// SPDX-License-Identifier: Apache-2.0
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
import Foundation
16+
import Vapor
17+
18+
let myos = ProcessInfo.processInfo.operatingSystemVersionString
19+
20+
let app = try Application(.detect())
21+
app.http.server.configuration.hostname = "0.0.0.0"
22+
defer { app.shutdown() }
23+
24+
app.get { _ in "Hello World, from \(myos)\n" }
25+
26+
try app.run()

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,5 @@ Trying to pull registry.example.com/myservice@sha256:a3f75d0932d052dd9d448a1c904
4747
Swift Container Plugin requires Swift 6.0 and runs on macOS and Linux. It does not require a local container runtime to be installed in order to build an image.
4848

4949
Learn more about setting up your project in the [ContainerImageBuilder plugin documentation](Sources/ContainerImageBuilderPluginDocumentation/Documentation.docc/ContainerImageBuilderPlugin.md).
50+
51+
Take a look at the [Examples](Examples).

Sources/ContainerImageBuilderPluginDocumentation/Documentation.docc/ContainerImageBuilderPlugin.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ The ContainerImageBuilder plugin is a Swift Package Manager command plugin which
1818
The plugin requires Swift 6.0 and runs on macOS and Linux.
1919
The plugin does not require a container runtime to be installed locally in order to build an image.
2020

21+
Try one of the [Examples](../../../Examples)
22+
2123
## Install a Swift SDK for cross-compilation on macOS
2224

2325
If you are running on macOS, you can use a [Swift SDK](https://github.com/apple/swift-evolution/blob/main/proposals/0387-cross-compilation-destinations.md) to cross-compile your server executable for Linux. Either:
@@ -29,7 +31,7 @@ Check that the SDK is available. In this case we have installed the Swift Stat
2931

3032
```shell
3133
% swift sdk list
32-
swift-6.0-DEVELOPMENT-SNAPSHOT-2024-07-02-a_static-linux-0.0.1
34+
swift-6.0.1-RELEASE_static-linux-0.0.1
3335
```
3436

3537
> Note: To use the Static Linux SDK on macOS, you must [install the open source Swift toolchain from swift.org](https://www.swift.org/documentation/articles/static-linux-getting-started.html#installing-the-sdk)

0 commit comments

Comments
 (0)