Skip to content

Examples: Add a Hello World example #1

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

Merged
merged 1 commit into from
Sep 27, 2024
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: 8 additions & 0 deletions Examples/HelloWorldVapor/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.DS_Store
/.build
/Packages
xcuserdata/
DerivedData/
.swiftpm/configuration/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc
213 changes: 213 additions & 0 deletions Examples/HelloWorldVapor/Package.resolved

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

27 changes: 27 additions & 0 deletions Examples/HelloWorldVapor/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// swift-tools-version: 6.0

//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftContainerPlugin open source project
//
// Copyright (c) 2024 Apple Inc. and the SwiftContainerPlugin project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of SwiftContainerPlugin project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//

import PackageDescription

let package = Package(
name: "hello-world",
platforms: [.macOS(.v13)],
dependencies: [
.package(url: "https://github.com/vapor/vapor", .upToNextMajor(from: "4.102.0")),
.package(url: "https://github.com/apple/swift-container-plugin", from: "0.1.0"),
],
targets: [.executableTarget(name: "hello-world", dependencies: [.product(name: "Vapor", package: "vapor")])]
)
26 changes: 26 additions & 0 deletions Examples/HelloWorldVapor/Sources/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftContainerPlugin open source project
//
// Copyright (c) 2024 Apple Inc. and the SwiftContainerPlugin project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of SwiftContainerPlugin project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//

import Foundation
import Vapor

let myos = ProcessInfo.processInfo.operatingSystemVersionString

let app = try Application(.detect())
app.http.server.configuration.hostname = "0.0.0.0"
defer { app.shutdown() }

app.get { _ in "Hello World, from \(myos)\n" }

try app.run()
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,5 @@ Trying to pull registry.example.com/myservice@sha256:a3f75d0932d052dd9d448a1c904
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.

Learn more about setting up your project in the [ContainerImageBuilder plugin documentation](Sources/ContainerImageBuilderPluginDocumentation/Documentation.docc/ContainerImageBuilderPlugin.md).

Take a look at the [Examples](Examples).
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ The ContainerImageBuilder plugin is a Swift Package Manager command plugin which
The plugin requires Swift 6.0 and runs on macOS and Linux.
The plugin does not require a container runtime to be installed locally in order to build an image.

Try one of the [Examples](../../../Examples)

## Install a Swift SDK for cross-compilation on macOS

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:
Expand All @@ -29,7 +31,7 @@ Check that the SDK is available. In this case we have installed the Swift Stat

```shell
% swift sdk list
swift-6.0-DEVELOPMENT-SNAPSHOT-2024-07-02-a_static-linux-0.0.1
swift-6.0.1-RELEASE_static-linux-0.0.1
```

> 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)
Expand Down