feat(hos_client_create, hos_client_destory): 多次调用destory不会导致重复释放

This commit is contained in:
彭宣正
2020-12-14 17:24:58 +08:00
parent 505d529c32
commit 10b370e486
55976 changed files with 8544395 additions and 2 deletions

View File

@@ -0,0 +1,22 @@
version: 0.2
phases:
build:
commands:
- mv aws-sdk-cpp /tmp
- mkdir /tmp/build
- cd /tmp/build
- python /tmp/aws-sdk-cpp/scripts/build_3rdparty.py --configs="${BUILD_CONFIG}" --sourcedir=/tmp/aws-sdk-cpp/ --parallel=${BUILD_PARALLEL} --installdir=/tmp/install --generateClients="0" --architecture=${ARCHITECTURE} --cmake_params="-DMINIMIZE_SIZE=ON -DANDROID_NATIVE_API_LEVEL=${API_LEVEL}"
post_build:
commands:
- export BUILD_JOB_NAME=$(echo "${CODEBUILD_BUILD_ID}" | cut -f1 -d ":")
- export BUILD_URL="https://console.aws.amazon.com/codesuite/codebuild/projects/${BUILD_JOB_NAME}/build/${CODEBUILD_BUILD_ID}"
- |
if [ "${CODEBUILD_BUILD_SUCCEEDING}" = "1" ]; then
aws sns publish --topic-arn ${NOTIFICATIONS_TOPIC} --message "/md [BUILD SUCCESS](${BUILD_URL}) (${CODEBUILD_BUILD_ID})";
else
aws sns publish --topic-arn ${NOTIFICATIONS_TOPIC} --message "/md [BUILD FAILURE](${BUILD_URL}) (${CODEBUILD_BUILD_ID})";
fi
artifacts:
files:
- "**/*"
base-directory: /tmp/install

View File

@@ -0,0 +1,19 @@
version: 0.2
phases:
build:
commands:
- VERSION_NUM=$(grep AWS_SDK_VERSION_STRING aws-sdk-cpp/aws-cpp-sdk-core/include/aws/core/VersionConfig.h | cut -f2 -d '"')
- echo $VERSION_NUM | tee aws-sdk-cpp-version
post_build:
commands:
- export BUILD_JOB_NAME=$(echo "${CODEBUILD_BUILD_ID}" | cut -f1 -d ":")
- export BUILD_URL="https://console.aws.amazon.com/codesuite/codebuild/projects/${BUILD_JOB_NAME}/build/${CODEBUILD_BUILD_ID}"
- |
if [ "${CODEBUILD_BUILD_SUCCEEDING}" = "1" ]; then
aws sns publish --topic-arn ${NOTIFICATIONS_TOPIC} --message "/md [BUILD SUCCESS](${BUILD_URL}) (Extract Metadata)";
else
aws sns publish --topic-arn ${NOTIFICATIONS_TOPIC} --message "/md [BUILD FAILURE](${BUILD_URL}) (Extract Metadata)";
fi
artifacts:
files:
- "aws-sdk-cpp-version"

View File

@@ -0,0 +1,11 @@
version: 0.2
phases:
build:
commands:
- cd ..
- zip -r latestSnapshot.zip aws-sdk-cpp
- mv latestSnapshot.zip $CODEBUILD_SRC_DIR
- cd $CODEBUILD_SRC_DIR
artifacts:
files:
- latestSnapshot.zip

View File

@@ -0,0 +1,22 @@
version: 0.2
phases:
build:
commands:
- mv aws-sdk-cpp /tmp
- mkdir /tmp/build
- cd /tmp/build
- python /tmp/aws-sdk-cpp/scripts/build_3rdparty.py --configs="${BUILD_CONFIG}" --sourcedir=/tmp/aws-sdk-cpp/ --parallel=${BUILD_PARALLEL} --installdir=/tmp/install --generateClients="0" --cmake_params=""
post_build:
commands:
- export BUILD_JOB_NAME=$(echo "${CODEBUILD_BUILD_ID}" | cut -f1 -d ":")
- export BUILD_URL="https://console.aws.amazon.com/codesuite/codebuild/projects/${BUILD_JOB_NAME}/build/${CODEBUILD_BUILD_ID}"
- |
if [ "${CODEBUILD_BUILD_SUCCEEDING}" = "1" ]; then
aws sns publish --topic-arn ${NOTIFICATIONS_TOPIC} --message "/md [BUILD SUCCESS](${BUILD_URL}) (${CODEBUILD_BUILD_ID})";
else
aws sns publish --topic-arn ${NOTIFICATIONS_TOPIC} --message "/md [BUILD FAILURE](${BUILD_URL}) (${CODEBUILD_BUILD_ID})";
fi
artifacts:
files:
- "**/*"
base-directory: /tmp/install

View File

@@ -0,0 +1,23 @@
version: 0.2
phases:
build:
commands:
- mkdir C:\tmp
- mv aws-sdk-cpp C:\tmp
- mkdir C:\tmp\build
- cd C:\tmp\build
- python "C:\tmp\aws-sdk-cpp\scripts\build_3rdparty.py" --architecture=${Env:ARCHITURE} --configs="${Env:BUILD_CONFIG}" --sourcedir="C:\tmp\aws-sdk-cpp" --parallel=${Env:BUILD_PARALLEL} --installdir="C:\tmp\install" --generateClients="0" --cmake_params=""
post_build:
commands:
- $BUILD_JOB_NAME=$Env:CODEBUILD_BUILD_ID.Substring(0, $Env:CODEBUILD_BUILD_ID.IndexOf(":"))
- $BUILD_URL="https://console.aws.amazon.com/codesuite/codebuild/projects/$BUILD_JOB_NAME/build/$Env:CODEBUILD_BUILD_ID"
- |
if (${Env:CODEBUILD_BUILD_SUCCEEDING} -eq 1) {
aws sns publish --topic-arn ${Env:NOTIFICATIONS_TOPIC} --message "/md [BUILD SUCCESS](${BUILD_URL}) (${Env:CODEBUILD_BUILD_ID})"
} Else {
aws sns publish --topic-arn ${Env:NOTIFICATIONS_TOPIC} --message "/md [BUILD FAILURE](${BUILD_URL}) (${Env:CODEBUILD_BUILD_ID})"
}
artifacts:
files:
- "**/*"
base-directory: C:\tmp\install

View File

@@ -0,0 +1,90 @@
# Whenever you make any change here, you should update it in Amazon S3.
# This lambda function is used to publish binaries and make notifications in binary release pipeline.
# It will copy the binaries generated in each pipeline action from a temporary location (provided by its inputs) to a specific s3 bucket for customer download.
# In the "Publish" stage, each lambda function is responsible for uploading binaries for one platform.
import boto3
import json
import os
import zipfile
from botocore.client import Config
def lambda_handler(event, context):
print(event)
job_id = event['CodePipeline.job']['id']
sns_client = boto3.client('sns')
codepipeline_client = boto3.client('codepipeline')
try:
parameters = json.loads(event['CodePipeline.job']['data']['actionConfiguration']['configuration']['UserParameters'])
publish_bucket = parameters['bucket']
publish_key_prefix = parameters['key_prefix']
# Get SDK version
input_bucket = event['CodePipeline.job']['data']['inputArtifacts'][0]['location']['s3Location']['bucketName']
input_key = event['CodePipeline.job']['data']['inputArtifacts'][0]['location']['s3Location']['objectKey']
s3 = boto3.resource('s3', config=Config(signature_version='s3v4'))
s3.meta.client.download_file(input_bucket, input_key, '/tmp/aws-sdk-cpp-version.zip')
with zipfile.ZipFile('/tmp/aws-sdk-cpp-version.zip', 'r') as zip:
zip.extractall('/tmp')
with open('/tmp/aws-sdk-cpp-version', 'r') as fp:
sdk_version = fp.read().strip()
# Copy SDK binaries to public bucket
input_artifacts = event['CodePipeline.job']['data']['inputArtifacts']
for i in range(1, len(input_artifacts)):
artifact_name = input_artifacts[i]['name']
config = artifact_name[artifact_name.find('_')+1:]
publish_key = 'cpp/builds/{version}/{prefix}/{prefix}-{config}.zip'.format(
version = sdk_version,
prefix = publish_key_prefix,
config = config
)
print('Uploading artifacts to https://s3.console.aws.amazon.com/s3/object/{bucket}/{key}'.format(
bucket = publish_bucket,
key = publish_key))
s3.meta.client.copy(
{ 'Bucket': input_artifacts[i]['location']['s3Location']['bucketName'],
'Key': input_artifacts[i]['location']['s3Location']['objectKey'] },
publish_bucket, publish_key)
# Notifications
sns_response = sns_client.publish(
TopicArn = os.environ['NOTIFICATIONS_TOPIC'],
Message = '/md [PUBLISH SUCCESS]({url}) ({prefix})'.format(
url = 'https://s3.console.aws.amazon.com/s3/buckets/{bucket}/cpp/builds/{version}/{prefix}/'.format(
bucket = publish_bucket,
version = sdk_version,
prefix = publish_key_prefix
),
prefix = publish_key_prefix
)
)
print(sns_response)
codepipeline_client.put_job_success_result(
jobId = job_id
)
except Exception as e:
codepipeline_client.put_job_failure_result(
jobId = job_id,
failureDetails = {
'type': 'JobFailed',
'message': str(e)
}
)
sns_response = sns_client.publish(
TopicArn = os.environ['NOTIFICATIONS_TOPIC'],
Message = '/md [PUBLISH FAILURE]({url}) ({prefix})'.format(
url = 'https://s3.console.aws.amazon.com/s3/buckets/{bucket}/cpp/builds/{version}/{prefix}/'.format(
bucket = publish_bucket,
version = sdk_version,
prefix = publish_key_prefix
),
prefix = publish_key_prefix
)
)
print(sns_response)
print(e)
return 0

View File

@@ -0,0 +1,36 @@
# Whenever you make any change here, you should update it in Amazon S3.
# In binary release pipeline, build jobs will send the results to a SNS topic.
# And this lambda function, triggered by this SNS notifications, will send messages about the build results to a Chime room.
# Other functionality could be added in the future, like put metrics to CloudWatch or trigger another alarm.
import boto3
import json
import os
from botocore.vendored import requests
chime_bot_url = os.environ['CHIME_BOT_URL']
def lambda_handler(event, context):
print(event)
message = event["Records"][0]["Sns"]["Message"]
headers = {'Content-Type': 'application/json'}
data = {}
if "FAILURE" in message:
# @All Members if build failed.
# Will convert '/md [message]' to '/md @All[message]'
firstSpaceIndex = message.find(' ')
message = message[:firstSpaceIndex+1] + '@All' + message[firstSpaceIndex+1:]
make_request = True
elif 'SUCCESS' in message:
make_request = True
if make_request == True:
data["Content"] = message
r = requests.post(chime_bot_url, headers = headers, data = json.dumps(data))
return r.reason
else:
return 0

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,308 @@
# Whenever you make any change here, you should update it in Amazon S3.
# This CloudFormation template is used to create resources for CodeBuild projects to build C++ SDK on Linux and Windows with both Visual Studio 2015 and 2017.
# It's a sub-template used in the main template to create binary release pipeline.
AWSTemplateFormatVersion: 2010-09-09
Parameters:
BuildConfig:
Type: String
Default: <build-config>
Description: Build config when building SDK on Linux and Windows.
BinaryReleaseResultNotificationsTopic:
Type: String
Default: <binary-release-result-notifications-topic>
Description: Topic ARN of the SNS, used to handle notifications received from lambda functions.
BinaryReleaseCodeBuildRole:
Type: String
Default: <binary-release-codebuild-role>
Description: Name of the service role used by CodeBuild projects used to build SDK.
ParameterStoreAwsAccessKeyId:
Type: String
Default: <parameter-store-aws-access-key-id>
Description: Key name in Parameter Store, used for aws access key id.
ParameterStoreAwsSecretAccessKey:
Type: String
Default: <parameter-store-aws-secret-access-key>
Description: Key name in Parameter Store, used for aws secret access key.
LinuxGccProjectName:
Type: String
Default: <linux-gcc-project-name>
Description: Name of the CodeBuild project, which will build C++ SDK on Linux with GCC.
LinuxGccImageName:
Type: String
Default: <linux-gcc-image-name>
Description: Name of the image used in the CodeBuild Project to build SDK on Linux with GCC.
LinuxGccBuildSpecLocation:
Type: String
Default: <linux-gcc-buildspec-location>
Description: Location of buildspec for CodeBuild Project to build SDK on Linux with GCC.
WindowsProjectName:
Type: String
Default: <windows-project-name>
Description: Name of the CodeBuild project, which will build C++ SDK on Windows.
WindowsVS2015ImageName:
Type: String
Default: <windows-vs2015-image-name>
Description: Name of the image used in the CodeBuild Project to build SDK on Windows with VS2015.
WindowsVS2017ImageName:
Type: String
Default: <windows-vs2017-image-name>
Description: Name of the image used in the CodeBuild Project to build SDK on Windows with VS2017.
WindowsBuildSpecLocation:
Type: String
Default: <windows-buildspec-location>
Description: Location of buildspec for CodeBuild Project to build SDK on Windows.
AndroidProjectName:
Type: String
Default: <android-project-name>
Description: Name of the CodeBuild project, which cross compiles C++ SDK on Linux with Android NDK.
AndroidBuildSpecLocation:
Type: String
Default: <android-buildspec-location>
Description: Location of buildspec for CodeBuild Project to build SDK with Android NDK.
BuildParallel:
Type: String
Default: <build-parallel>
Description: Number of jobs in parallel to build C++ SDK.
Resources:
LinuxGccProject:
Type: AWS::CodeBuild::Project
Properties:
Name:
!Join
- '-'
- - !Ref LinuxGccProjectName
- !Ref BuildConfig
ServiceRole: !Ref BinaryReleaseCodeBuildRole
Source:
Type: CODEPIPELINE
BuildSpec: !Ref LinuxGccBuildSpecLocation
Artifacts:
Type: CODEPIPELINE
Environment:
Type: LINUX_CONTAINER
ComputeType: BUILD_GENERAL1_LARGE
Image: !Ref LinuxGccImageName
EnvironmentVariables:
- Name: BUILD_CONFIG
Type: PLAINTEXT
Value: !Ref BuildConfig
- Name: BUILD_PARALLEL
Type: PLAINTEXT
Value: !Ref BuildParallel
- Name: NOTIFICATIONS_TOPIC
Type: PLAINTEXT
Value: !Ref BinaryReleaseResultNotificationsTopic
- Name: AWS_ACCESS_KEY_ID
Type: PARAMETER_STORE
Value: !Ref ParameterStoreAwsAccessKeyId
- Name: AWS_SECRET_ACCESS_KEY
Type: PARAMETER_STORE
Value: !Ref ParameterStoreAwsSecretAccessKey
TimeoutInMinutes: 60
WindowsVS2015Project:
Type: AWS::CodeBuild::Project
Properties:
Name:
!Join
- '-'
- - !Ref WindowsProjectName
- vs2015
- !Ref BuildConfig
ServiceRole: !Ref BinaryReleaseCodeBuildRole
Source:
Type: CODEPIPELINE
BuildSpec: !Ref WindowsBuildSpecLocation
Artifacts:
Type: CODEPIPELINE
Environment:
Type: WINDOWS_CONTAINER
ComputeType: BUILD_GENERAL1_LARGE
Image: !Ref WindowsVS2015ImageName
EnvironmentVariables:
- Name: ARCHITURE
Type: PLAINTEXT
Value: Windows2015
- Name: BUILD_CONFIG
Type: PLAINTEXT
Value: !Ref BuildConfig
- Name: BUILD_PARALLEL
Type: PLAINTEXT
Value: !Ref BuildParallel
- Name: NOTIFICATIONS_TOPIC
Type: PLAINTEXT
Value: !Ref BinaryReleaseResultNotificationsTopic
- Name: AWS_ACCESS_KEY_ID
Type: PARAMETER_STORE
Value: !Ref ParameterStoreAwsAccessKeyId
- Name: AWS_SECRET_ACCESS_KEY
Type: PARAMETER_STORE
Value: !Ref ParameterStoreAwsSecretAccessKey
TimeoutInMinutes: 90
WindowsVS2017Project:
Type: AWS::CodeBuild::Project
Properties:
Name:
!Join
- '-'
- - !Ref WindowsProjectName
- vs2017
- !Ref BuildConfig
ServiceRole: !Ref BinaryReleaseCodeBuildRole
Source:
Type: CODEPIPELINE
BuildSpec: !Ref WindowsBuildSpecLocation
Artifacts:
Type: CODEPIPELINE
Environment:
Type: WINDOWS_CONTAINER
ComputeType: BUILD_GENERAL1_LARGE
Image: !Ref WindowsVS2017ImageName
EnvironmentVariables:
- Name: ARCHITURE
Type: PLAINTEXT
Value: Windows2017
- Name: BUILD_CONFIG
Type: PLAINTEXT
Value: !Ref BuildConfig
- Name: BUILD_PARALLEL
Type: PLAINTEXT
Value: !Ref BuildParallel
- Name: NOTIFICATIONS_TOPIC
Type: PLAINTEXT
Value: !Ref BinaryReleaseResultNotificationsTopic
- Name: AWS_ACCESS_KEY_ID
Type: PARAMETER_STORE
Value: !Ref ParameterStoreAwsAccessKeyId
- Name: AWS_SECRET_ACCESS_KEY
Type: PARAMETER_STORE
Value: !Ref ParameterStoreAwsSecretAccessKey
TimeoutInMinutes: 90
AndroidArm32Api19Project:
Type: AWS::CodeBuild::Project
Properties:
Name:
!Join
- '-'
- - !Ref AndroidProjectName
- arm32
- api19
- !Ref BuildConfig
ServiceRole: !Ref BinaryReleaseCodeBuildRole
Source:
Type: CODEPIPELINE
BuildSpec: !Ref AndroidBuildSpecLocation
Artifacts:
Type: CODEPIPELINE
Environment:
Type: LINUX_CONTAINER
ComputeType: BUILD_GENERAL1_LARGE
Image: !Ref LinuxGccImageName
EnvironmentVariables:
- Name: ARCHITECTURE
Type: PLAINTEXT
Value: AndroidArm32
- Name: API_LEVEL
Type: PLAINTEXT
Value: 19
- Name: BUILD_CONFIG
Type: PLAINTEXT
Value: !Ref BuildConfig
- Name: BUILD_PARALLEL
Type: PLAINTEXT
Value: !Ref BuildParallel
- Name: NOTIFICATIONS_TOPIC
Type: PLAINTEXT
Value: !Ref BinaryReleaseResultNotificationsTopic
- Name: AWS_ACCESS_KEY_ID
Type: PARAMETER_STORE
Value: !Ref ParameterStoreAwsAccessKeyId
- Name: AWS_SECRET_ACCESS_KEY
Type: PARAMETER_STORE
Value: !Ref ParameterStoreAwsSecretAccessKey
TimeoutInMinutes: 60
AndroidArm32Api21Project:
Type: AWS::CodeBuild::Project
Properties:
Name:
!Join
- '-'
- - !Ref AndroidProjectName
- arm32
- api21
- !Ref BuildConfig
ServiceRole: !Ref BinaryReleaseCodeBuildRole
Source:
Type: CODEPIPELINE
BuildSpec: !Ref AndroidBuildSpecLocation
Artifacts:
Type: CODEPIPELINE
Environment:
Type: LINUX_CONTAINER
ComputeType: BUILD_GENERAL1_LARGE
Image: !Ref LinuxGccImageName
EnvironmentVariables:
- Name: ARCHITECTURE
Type: PLAINTEXT
Value: AndroidArm32
- Name: API_LEVEL
Type: PLAINTEXT
Value: 21
- Name: BUILD_CONFIG
Type: PLAINTEXT
Value: !Ref BuildConfig
- Name: BUILD_PARALLEL
Type: PLAINTEXT
Value: !Ref BuildParallel
- Name: NOTIFICATIONS_TOPIC
Type: PLAINTEXT
Value: !Ref BinaryReleaseResultNotificationsTopic
- Name: AWS_ACCESS_KEY_ID
Type: PARAMETER_STORE
Value: !Ref ParameterStoreAwsAccessKeyId
- Name: AWS_SECRET_ACCESS_KEY
Type: PARAMETER_STORE
Value: !Ref ParameterStoreAwsSecretAccessKey
TimeoutInMinutes: 60
AndroidArm64Api21Project:
Type: AWS::CodeBuild::Project
Properties:
Name:
!Join
- '-'
- - !Ref AndroidProjectName
- arm64
- api21
- !Ref BuildConfig
ServiceRole: !Ref BinaryReleaseCodeBuildRole
Source:
Type: CODEPIPELINE
BuildSpec: !Ref AndroidBuildSpecLocation
Artifacts:
Type: CODEPIPELINE
Environment:
Type: LINUX_CONTAINER
ComputeType: BUILD_GENERAL1_LARGE
Image: !Ref LinuxGccImageName
EnvironmentVariables:
- Name: ARCHITECTURE
Type: PLAINTEXT
Value: AndroidArm64
- Name: API_LEVEL
Type: PLAINTEXT
Value: 21
- Name: BUILD_CONFIG
Type: PLAINTEXT
Value: !Ref BuildConfig
- Name: BUILD_PARALLEL
Type: PLAINTEXT
Value: !Ref BuildParallel
- Name: NOTIFICATIONS_TOPIC
Type: PLAINTEXT
Value: !Ref BinaryReleaseResultNotificationsTopic
- Name: AWS_ACCESS_KEY_ID
Type: PARAMETER_STORE
Value: !Ref ParameterStoreAwsAccessKeyId
- Name: AWS_SECRET_ACCESS_KEY
Type: PARAMETER_STORE
Value: !Ref ParameterStoreAwsSecretAccessKey
TimeoutInMinutes: 60