Skip to content

Commit 760c003

Browse files
committed
adjust examples deployment scripts
1 parent 850608a commit 760c003

File tree

9 files changed

+105
-26
lines changed

9 files changed

+105
-26
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.build
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM swiftlang/swift:nightly-master-amazonlinux2
2+
3+
RUN yum -y install git zip

Examples/EndToEndDebugging/MyLambda/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ let package = Package(
1414
// this is the dependency on the swift-aws-lambda-runtime library
1515
// in real-world projects this would say
1616
// .package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", from: "1.0.0")
17-
.package(path: "../../.."),
17+
.package(name: "swift-aws-lambda-runtime", path: "../../.."),
1818
],
1919
targets: [
2020
.target(
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/bin/bash
2+
##===----------------------------------------------------------------------===##
3+
##
4+
## This source file is part of the SwiftAWSLambdaRuntime open source project
5+
##
6+
## Copyright (c) 2020 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+
set -eu
17+
18+
lambda_name=SwiftSample
19+
s3_bucket=swift-lambda-test
20+
executables=( $(swift package dump-package | sed -e 's|: null|: ""|g' | jq '.products[] | (select(.type.executable)) | .name' | sed -e 's|"||g') )
21+
22+
if [[ ${#executables[@]} = 0 ]]; then
23+
echo "no executables found"
24+
exit 1
25+
elif [[ ${#executables[@]} = 1 ]]; then
26+
executable=${executables[0]}
27+
elif [[ ${#executables[@]} > 1 ]]; then
28+
echo "multiple executables found:"
29+
for executable in ${executables[@]}; do
30+
echo " * $executable"
31+
done
32+
echo ""
33+
read -p "select which executables to deploy: " executable
34+
fi
35+
36+
echo -e "\ndeploying $executable"
37+
38+
echo "-------------------------------------------------------------------------"
39+
echo "preparing docker build image"
40+
echo "-------------------------------------------------------------------------"
41+
docker build . -t builder
42+
43+
echo "-------------------------------------------------------------------------"
44+
echo "building \"$executable\" lambda"
45+
echo "-------------------------------------------------------------------------"
46+
docker run --rm -v `pwd`/../../..:/workspace -w /workspace builder \
47+
bash -cl "cd Examples/EndToEndDebugging/MyLambda &&
48+
swift build --product $executable -c release -Xswiftc -g"
49+
echo "done"
50+
51+
echo "-------------------------------------------------------------------------"
52+
echo "packaging \"$executable\" lambda"
53+
echo "-------------------------------------------------------------------------"
54+
docker run --rm -v `pwd`:/workspace -w /workspace builder bash -cl "./scripts/package.sh $executable"
55+
56+
echo "-------------------------------------------------------------------------"
57+
echo "uploading \"$executable\" lambda to s3"
58+
echo "-------------------------------------------------------------------------"
59+
60+
aws s3 cp .build/lambda/$executable/lambda.zip s3://$s3_bucket/
61+
62+
echo "-------------------------------------------------------------------------"
63+
echo "updating \"$lambda_name\" to latest \"$executable\""
64+
echo "-------------------------------------------------------------------------"
65+
aws lambda update-function-code --function $lambda_name --s3-bucket $s3_bucket --s3-key lambda.zip
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
##===----------------------------------------------------------------------===##
3+
##
4+
## This source file is part of the SwiftAWSLambdaRuntime open source project
5+
##
6+
## Copyright (c) 2020 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+
set -eu
17+
18+
executable=$1
19+
20+
target=.build/lambda/$executable
21+
rm -rf "$target"
22+
mkdir -p "$target"
23+
cp ".build/release/$executable" "$target/"
24+
cp -Pv /usr/lib/swift/linux/lib*so* "$target"
25+
cd "$target"
26+
ln -s "$executable" "bootstrap"
27+
zip --symlinks lambda.zip *

Examples/LambdaFunctions/Dockerfile

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,3 @@
1-
FROM fabianfett/amazonlinux-swift:5.2-amazonlinux2
1+
FROM swiftlang/swift:nightly-master-amazonlinux2
22

3-
RUN yum -y install \
4-
git \
5-
libuuid-devel \
6-
libicu-devel \
7-
libedit-devel \
8-
libxml2-devel \
9-
sqlite-devel \
10-
python-devel \
11-
ncurses-devel \
12-
curl-devel \
13-
tzdata \
14-
libtool \
15-
libatomic\
16-
gcc-c++ \
17-
jq \
18-
tar \
19-
zip
3+
RUN yum -y install git zip

Examples/LambdaFunctions/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ let package = Package(
2323
// this is the dependency on the swift-aws-lambda-runtime library
2424
// in real-world projects this would say
2525
// .package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", from: "1.0.0")
26-
.package(path: "../.."),
26+
.package(name: "swift-aws-lambda-runtime", path: "../.."),
2727
],
2828
targets: [
2929
.target(name: "HelloWorld", dependencies: [

Examples/LambdaFunctions/scripts/deploy.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,17 @@ fi
3535

3636
echo -e "\ndeploying $executable"
3737

38-
39-
4038
echo "-------------------------------------------------------------------------"
4139
echo "preparing docker build image"
4240
echo "-------------------------------------------------------------------------"
43-
docker build . -q -t builder
41+
docker build . -t builder
4442

4543
echo "-------------------------------------------------------------------------"
4644
echo "building \"$executable\" lambda"
4745
echo "-------------------------------------------------------------------------"
48-
docker run --rm -v `pwd`:/workspace -w /workspace builder bash -cl "swift build --product $executable -c release -Xswiftc -g"
46+
docker run --rm -v `pwd`/../..:/workspace -w /workspace builder \
47+
bash -cl "cd Examples/LambdaFunctions && \
48+
swift build --product $executable -c release -Xswiftc -g"
4949
echo "done"
5050

5151
echo "-------------------------------------------------------------------------"

Examples/LambdaFunctions/scripts/package.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
##
1414
##===----------------------------------------------------------------------===##
1515

16-
1716
set -eu
1817

1918
executable=$1
@@ -22,7 +21,7 @@ target=.build/lambda/$executable
2221
rm -rf "$target"
2322
mkdir -p "$target"
2423
cp ".build/release/$executable" "$target/"
25-
cp -Pv /usr/lib/swift/linux/lib*so* /usr/lib64/libatomic.so.1* "$target"
24+
cp -Pv /usr/lib/swift/linux/lib*so* "$target"
2625
cd "$target"
2726
ln -s "$executable" "bootstrap"
2827
zip --symlinks lambda.zip *

0 commit comments

Comments
 (0)