|
| 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" |
0 commit comments