Skip to content

Commit 030fb2a

Browse files
committed
Update scripts
1 parent e51f156 commit 030fb2a

File tree

7 files changed

+109
-66
lines changed

7 files changed

+109
-66
lines changed

Examples/CloudFunctions/README.md

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,20 @@ Steps to deploy this sample to Tencent SCF Platform using TCCLI and COSCMD:
2020
3. Build, package and deploy the function
2121

2222
```
23-
./scripts/deploy.sh
23+
./scripts/deploy.sh [executable]
24+
```
25+
26+
You can combine step 2 and 3 with:
27+
28+
```
29+
./scripts/create-and-deploy.sh [executable]
2430
```
2531

2632
Notes:
2733
- This script assumes you have TCCLI installed and user configured (See https://cloud.tencent.com/document/product/440/34012).
2834
- This script also assumes you have COSCMD installed and user configured with the same main account as the one in TCCLI (See https://cloud.tencent.com/document/product/436/10976).
2935
- You'll be prompted to provide the COS bucket ID and region, and the SCF function name and region.
30-
- Both the cloud function and COS bucket must exist before deploying for the first time.
36+
- The COS bucket must exist before deploying, as well as the SCF function if you use `deploy.sh`.
3137

3238
### Deployment instructions using Serverless Framework for Tencent (serverless.com/cn)
3339

@@ -37,8 +43,8 @@ Notes:
3743

3844
To use Serverless to deploy this sample to Tencent Cloud:
3945

40-
1. Install Serverless by following the [instructions](https://www.serverless.com/framework/docs/getting-started/).
41-
If you already have installed, be sure you have the latest version.
46+
1. Install Serverless by following the [instructions](https://www.serverless.com/framework/docs/getting-started/). If you already have installed, be sure you have the latest version.
47+
4248
The examples have been tested with the version 1.80.0.
4349

4450
```
@@ -52,19 +58,19 @@ Components: 2.34.9
5258
2. Build, package and deploy the cloud function
5359

5460
```
55-
./scripts/serverless-deploy.sh
61+
./scripts/serverless-deploy.sh [executable]
5662
```
5763

58-
The script will ask you which sample function you wish to deploy.
64+
The script will ask you which sample function you wish to deploy if you don't provide one in the parameter.
5965

6066
3. Test
6167

62-
For the APIGateway sample, the Serverless template provides an endpoint with API Gateway which you can use to test the cloud function.
68+
For the APIGateway sample, the Serverless template provides an endpoint with API Gateway which you can use to test the cloud function.
6369

6470
Output example:
6571

6672
```
67-
$ sls deploy
73+
$ ./scripts/serverless-deploy.sh APIGateway
6874
6975
serverless ⚡ framework
7076
Action: "deploy" - Stage: "dev" - App: "SwiftAPIGatewayDemo" - Instance: "SwiftAPIGatewayDemo"
@@ -99,7 +105,7 @@ For extensive usage, you need to customize `serverless.yml` yourself.
99105
4. Remove
100106

101107
```
102-
./scripts/serverless-remove.sh
108+
./scripts/serverless-remove.sh [executable]
103109
```
104110

105-
The script will ask you which sample function you wish to remove from the previous deployment.
111+
The script will ask you which sample function you wish to remove from the previous deployment if you don't provide one in the parameter.

Examples/CloudFunctions/scripts/config.sh

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,25 @@
2727
##===------------------------------------------------------------------------------------===##
2828

2929
DIR="$(cd "$(dirname "$0")" && pwd)"
30-
executables=( $(swift package dump-package | sed -e 's|: null|: ""|g' | jq '.products[] | (select(.type.executable)) | .name' | sed -e 's|"||g') )
3130

32-
if [[ ${#executables[@]} = 0 ]]; then
33-
echo "No executables found"
34-
exit 1
35-
elif [[ ${#executables[@]} = 1 ]]; then
36-
executable=${executables[0]}
37-
elif [[ ${#executables[@]} > 1 ]]; then
38-
echo "Multiple executables found:"
39-
for executable in ${executables[@]}; do
40-
echo " * $executable"
41-
done
42-
echo ""
43-
read -p "Select which executable to deploy: " executable
31+
if [ -n "$1" ]; then
32+
executable=$1
33+
else
34+
executables=( $(swift package dump-package | sed -e 's|: null|: ""|g' | jq '.products[] | (select(.type.executable)) | .name' | sed -e 's|"||g') )
35+
36+
if [[ ${#executables[@]} = 0 ]]; then
37+
echo "No executables found"
38+
exit 1
39+
elif [[ ${#executables[@]} = 1 ]]; then
40+
executable=${executables[0]}
41+
elif [[ ${#executables[@]} > 1 ]]; then
42+
echo "Multiple executables found:"
43+
for executable in ${executables[@]}; do
44+
echo " * $executable"
45+
done
46+
echo ""
47+
read -p "Select which executable to deploy: " executable
48+
fi
4449
fi
4550

4651
echo "-------------------------------------------------------------------------"
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/bin/bash
2+
##===------------------------------------------------------------------------------------===##
3+
##
4+
## This source file is part of the SwiftTencentSCFRuntime open source project
5+
##
6+
## Copyright (c) 2020 stevapple and the SwiftTencentSCFRuntime 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 SwiftTencentSCFRuntime project authors
11+
##
12+
## SPDX-License-Identifier: Apache-2.0
13+
##
14+
##===------------------------------------------------------------------------------------===##
15+
16+
set -eu
17+
18+
DIR="$(cd "$(dirname "$0")" && pwd)"
19+
source $DIR/config.sh
20+
21+
workspace="$DIR/../.."
22+
23+
echo -e "\nDeploying $executable"
24+
25+
$DIR/build-and-package.sh "$executable"
26+
27+
echo "-------------------------------------------------------------------------"
28+
echo "Uploading \"$executable\" function to COS"
29+
echo "-------------------------------------------------------------------------"
30+
31+
read -p "COS bucket to upload (name-appid, eg: examplebucket-1250000000): " cos_bucket
32+
33+
read -p "COS bucket region (eg: ap-beijing): " cos_region
34+
cos_region=${cos_region:-ap-beijing} # default for easy testing
35+
36+
coscmd -b "$cos_bucket" -r "$cos_region" upload ".build/scf/$executable/cloud-function.zip" "$executable.zip"
37+
38+
echo "-------------------------------------------------------------------------"
39+
echo "Updating SCF function to use \"$executable\""
40+
echo "-------------------------------------------------------------------------"
41+
42+
cos_bucket=${cos_bucket%-*}
43+
44+
read -p "Cloud Function name (not exist in SCF): " function_name
45+
function_name=${function_name:-SwiftSample} # default for easy testing
46+
47+
read -p "Cloud Function region (eg: ap-beijing): " scf_region
48+
scf_region=${scf_region:-ap-beijing} # default for easy testing
49+
50+
# Temporarily broken API
51+
# tccli scf CreateFunction --region "$scf_region" \
52+
# --FunctionName "$function_name" --Description "Swift runtime demo with $executable" \
53+
# --Runtime "CustomRuntime" --Handler "swift.main" \
54+
# --InitTimeout 3 --MemorySize 64 \
55+
# --PublicNetConfig '{"PublicNetStatus":"ENABLE","EipConfig":{"EipStatus":"DISABLE"}}' \
56+
# --CodeSource "Cos" \
57+
# --Code "{\"CosBucketName\":\"$cos_bucket\",\"CosBucketRegion\":\"$cos_region\",\"CosObjectName\":\"$executable.zip\"}"
58+
59+
tccli scf CreateFunction --region "$scf_region" \
60+
--FunctionName "$function_name" --Description "Swift runtime demo with $executable" \
61+
--Runtime "CustomRuntime" --InitTimeout 3 --MemorySize 64 \
62+
--PublicNetConfig '{"PublicNetStatus":"ENABLE","EipConfig":{"EipStatus":"DISABLE"}}' \
63+
--CodeSource "Demo" --Code '{"DemoId":"demo-pbkaega3"}'
64+
sleep 3
65+
tccli scf UpdateFunctionCode --region "$scf_region" \
66+
--FunctionName "$function_name" --Handler "swift.main" \
67+
--CodeSource "Cos" --CosBucketName "$cos_bucket" --CosBucketRegion "$cos_region" --CosObjectName "$executable.zip"

Examples/CloudFunctions/scripts/deploy.sh

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,6 @@
1212
## SPDX-License-Identifier: Apache-2.0
1313
##
1414
##===------------------------------------------------------------------------------------===##
15-
##
16-
## This source file was part of the SwiftAWSLambdaRuntime open source project
17-
##
18-
## Copyright (c) 2020 Apple Inc. and the SwiftAWSLambdaRuntime project authors
19-
## Licensed under Apache License v2.0
20-
##
21-
## See LICENSE.txt for license information
22-
## See http://github.com/swift-server/swift-aws-lambda-runtime/blob/master/CONTRIBUTORS.txt
23-
## for the list of SwiftAWSLambdaRuntime project authors
24-
##
25-
## SPDX-License-Identifier: Apache-2.0
26-
##
27-
##===------------------------------------------------------------------------------------===##
2815

2916
set -eu
3017

@@ -60,4 +47,6 @@ function_name=${function_name:-SwiftSample} # default for easy testing
6047
read -p "Cloud Function region (eg: ap-beijing): " scf_region
6148
scf_region=${scf_region:-ap-beijing} # default for easy testing
6249

63-
tccli scf UpdateFunctionCode --region "$scf_region" --FunctionName "$function_name" --Handler "swift.main" --CodeSource "Cos" --CosBucketName "$cos_bucket" --CosBucketRegion "$cos_region" --CosObjectName $executable.zip
50+
tccli scf UpdateFunctionCode --region "$scf_region" \
51+
--FunctionName "$function_name" --Handler "swift.main" \
52+
--CodeSource "Cos" --CosBucketName "$cos_bucket" --CosBucketRegion "$cos_region" --CosObjectName "$executable.zip"

Examples/CloudFunctions/scripts/serverless-deploy.sh

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,6 @@
1212
## SPDX-License-Identifier: Apache-2.0
1313
##
1414
##===------------------------------------------------------------------------------------===##
15-
##
16-
## This source file was part of the SwiftAWSLambdaRuntime open source project
17-
##
18-
## Copyright (c) 2017-2018 Apple Inc. and the SwiftAWSLambdaRuntime project authors
19-
## Licensed under Apache License v2.0
20-
##
21-
## See LICENSE.txt for license information
22-
## See http://github.com/swift-server/swift-aws-lambda-runtime/blob/master/CONTRIBUTORS.txt
23-
## for the list of SwiftAWSLambdaRuntime project authors
24-
##
25-
## SPDX-License-Identifier: Apache-2.0
26-
##
27-
##===------------------------------------------------------------------------------------===##
2815

2916
set -eu
3017

Examples/CloudFunctions/scripts/serverless-remove.sh

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,6 @@
1212
## SPDX-License-Identifier: Apache-2.0
1313
##
1414
##===------------------------------------------------------------------------------------===##
15-
##
16-
## This source file was part of the SwiftAWSLambdaRuntime open source project
17-
##
18-
## Copyright (c) 2017-2018 Apple Inc. and the SwiftAWSLambdaRuntime project authors
19-
## Licensed under Apache License v2.0
20-
##
21-
## See LICENSE.txt for license information
22-
## See http://github.com/swift-server/swift-aws-lambda-runtime/blob/master/CONTRIBUTORS.txt
23-
## for the list of SwiftAWSLambdaRuntime project authors
24-
##
25-
## SPDX-License-Identifier: Apache-2.0
26-
##
27-
##===------------------------------------------------------------------------------------===##
2815

2916
set -eu
3017

Examples/LocalDebugging/MyCloudFunction/scripts/deploy.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ set -eu
3131
executable=MyCloudFunction
3232
function_name=swift-sample
3333
scf_region=ap-beijing
34-
cos_bucket=swift-scf-test-appid
34+
cos_bucket=swift-scf-test-<appid>
3535
cos_region=ap-beijing
3636

3737
echo -e "\ndeploying $executable"
@@ -64,5 +64,7 @@ coscmd -b "$cos_bucket" -r "$cos_region" upload ".build/scf/$executable/cloud-fu
6464
echo "-------------------------------------------------------------------------"
6565
echo "Updating \"$function_name\" to the latest \"$executable\""
6666
echo "-------------------------------------------------------------------------"
67-
tccli scf UpdateFunctionCode --region "$scf_region" --FunctionName "$function_name" --Handler "swift.main" --CodeSource "Cos" --CosBucketName "$cos_bucket" --CosBucketRegion "$cos_region" --CosObjectName $executable.zip
68-
echo "done"
67+
tccli scf UpdateFunctionCode --region "$scf_region" \
68+
--FunctionName "$function_name" --Handler "swift.main" \
69+
--CodeSource "Cos" --CosBucketName "$cos_bucket" --CosBucketRegion "$cos_region" --CosObjectName "$executable.zip"
70+
echo "done"

0 commit comments

Comments
 (0)