Skip to content

Commit 58b8e06

Browse files
committed
add resources packaging example
1 parent b4f0164 commit 58b8e06

File tree

5 files changed

+140
-0
lines changed

5 files changed

+140
-0
lines changed
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
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+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import PackageDescription
5+
6+
let package = Package(
7+
name: "ResourcesPackaging",
8+
platforms: [.macOS(.v15)],
9+
products: [
10+
.executable(name: "MyLambda", targets: ["MyLambda"]),
11+
],
12+
dependencies: [
13+
.package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", branch: "main"),
14+
],
15+
targets: [
16+
.executableTarget(
17+
name: "MyLambda",
18+
dependencies: [
19+
.product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime"),
20+
],
21+
path: ".",
22+
resources: [
23+
.process("hello.txt"),
24+
]
25+
),
26+
]
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 SwiftAWSLambdaRuntime open source project
4+
//
5+
// Copyright (c) 2025 Apple Inc. and the SwiftAWSLambdaRuntime 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 SwiftAWSLambdaRuntime project authors
10+
//
11+
// SPDX-License-Identifier: Apache-2.0
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
import AWSLambdaRuntime
16+
import Foundation
17+
18+
let runtime = LambdaRuntime {
19+
(event: String, context: LambdaContext) in
20+
guard let fileURL = Bundle.module.url(forResource: "hello", withExtension: "txt") else {
21+
fatalError("no file url")
22+
}
23+
return try String(contentsOf: fileURL, encoding: .utf8)
24+
}
25+
26+
try await runtime.run()

Examples/ResourcesPackaging/hello.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hello World

scripts/test-plugin-ubuntu.sh

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/bin/bash
2+
##===----------------------------------------------------------------------===##
3+
##
4+
## This source file is part of the SwiftAWSLambdaRuntime open source project
5+
##
6+
## Copyright (c) 2025 Apple Inc. and the SwiftAWSLambdaRuntime project authors
7+
## Licensed under Apache License v2.0
8+
##
9+
## See LICENSE.txt for license information
10+
## See CONTRIBUTORS.txt for the list of SwiftAWSLambdaRuntime project authors
11+
##
12+
## SPDX-License-Identifier: Apache-2.0
13+
##
14+
##===----------------------------------------------------------------------===##
15+
16+
sudo apt update && sudo apt -y upgrade
17+
18+
# Install Swift 6.0.3
19+
sudo apt-get -y install \
20+
binutils \
21+
git \
22+
gnupg2 \
23+
libc6-dev \
24+
libcurl4-openssl-dev \
25+
libedit2 \
26+
libgcc-13-dev \
27+
libncurses-dev \
28+
libpython3-dev \
29+
libsqlite3-0 \
30+
libstdc++-13-dev \
31+
libxml2-dev \
32+
libz3-dev \
33+
pkg-config \
34+
tzdata \
35+
unzip \
36+
zip \
37+
zlib1g-dev
38+
39+
wget https://download.swift.org/swift-6.0.3-release/ubuntu2404-aarch64/swift-6.0.3-RELEASE/swift-6.0.3-RELEASE-ubuntu24.04-aarch64.tar.gz
40+
41+
tar xfvz swift-6.0.3-RELEASE-ubuntu24.04-aarch64.tar.gz
42+
43+
export PATH=/home/ubuntu/swift-6.0.3-RELEASE-ubuntu24.04-aarch64/usr/bin:"${PATH}"
44+
45+
swift --version
46+
47+
# Install Docker
48+
sudo apt-get update
49+
sudo apt-get install -y ca-certificates curl
50+
sudo install -m 0755 -d /etc/apt/keyrings
51+
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
52+
sudo chmod a+r /etc/apt/keyrings/docker.asc
53+
54+
# Add the repository to Apt sources:
55+
echo \
56+
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
57+
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
58+
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
59+
sudo apt-get update
60+
61+
sudo apt-get -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
62+
63+
# Add the current user to the docker group
64+
sudo usermod -aG docker $USER
65+
66+
# LOGOUT and LOGIN to apply the changes
67+
exit
68+
69+
# reconnect with ssh
70+
71+
export PATH=/home/ubuntu/swift-6.0.3-RELEASE-ubuntu24.04-aarch64/usr/bin:"${PATH}"
72+
73+
# clone a project
74+
git clone https://github.com/swift-server/swift-aws-lambda-runtime.git
75+
76+
# build the project
77+
cd swift-aws-lambda-runtime/Examples/ResourcesPackaging/
78+
LAMBDA_USE_LOCAL_DEPS=../.. swift package archive --allow-network-connections docker

0 commit comments

Comments
 (0)