123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- @ECHO OFF
- REM
- REM Copyright (c) Contributors to the Open 3D Engine Project.
- REM For complete copyright and license terms please see the LICENSE at the root of this distribution.
- REM
- REM SPDX-License-Identifier: Apache-2.0 OR MIT
- REM
- REM
- REM Deploy the CDK applications for AWS gems (Windows only)
- REM Prerequisites:
- REM 1) Node.js is installed
- REM 2) Node.js version >= 10.13.0, except for versions 13.0.0 - 13.6.0. A version in active long-term support is recommended.
- SETLOCAL EnableDelayedExpansion
- SET SOURCE_DIRECTORY=%CD%
- SET PATH=%SOURCE_DIRECTORY%\python;%PATH%
- SET GEM_DIRECTORY=%SOURCE_DIRECTORY%\Gems
- ECHO [cdk_installation] Install aws-cdk@%CDK_VERSION%
- CALL npm uninstall -g aws-cdk
- IF ERRORLEVEL 1 (
- ECHO [cdk_bootstrap] Failed to uninstall the current version of CDK
- exit /b 1
- )
- CALL npm install -g aws-cdk@%CDK_VERSION%
- IF ERRORLEVEL 1 (
- ECHO [cdk_bootstrap] Failed to install aws-cdk@%CDK_VERSION%
- exit /b 1
- )
- REM Set temporary AWS credentials from the assume role
- FOR /f "tokens=1,2,3" %%a IN ('CALL aws sts assume-role --query Credentials.[SecretAccessKey^,SessionToken^,AccessKeyId] --output text --role-arn %ASSUME_ROLE_ARN% --role-session-name o3de-Automation-session') DO (
- SET AWS_SECRET_ACCESS_KEY=%%a
- SET AWS_SESSION_TOKEN=%%b
- SET AWS_ACCESS_KEY_ID=%%c
- )
- FOR /F "tokens=4 delims=:" %%a IN ("%ASSUME_ROLE_ARN%") DO SET O3DE_AWS_DEPLOY_ACCOUNT=%%a
- IF "%O3DE_AWS_PROJECT_NAME%"=="" (
- REM To avoid resource name length issues, potentially verbose pipeline names are capped at 25 chars.
- REM TODO: consolidate project name formulation for tests and deploy/destroy scripts to same place.
- ECHO Truncated pipeline name is: %PIPELINE_NAME:~0,25%
- SET O3DE_AWS_PROJECT_NAME=%BRANCH_NAME%-%PIPELINE_NAME:~0,25%-Windows
- SET slashreplace=
- call SET O3DE_AWS_PROJECT_NAME=%%O3DE_AWS_PROJECT_NAME:/=%slashreplace%%%
- )
- REM Bootstrap and deploy the CDK applications
- ECHO [cdk_bootstrap] Bootstrap CDK
- CALL cdk bootstrap aws://%O3DE_AWS_DEPLOY_ACCOUNT%/%O3DE_AWS_DEPLOY_REGION%
- IF ERRORLEVEL 1 (
- ECHO [cdk_bootstrap] Failed to bootstrap CDK
- exit /b 1
- )
- CALL :DeployCDKApplication AWSCore "-c disable_access_log=true -c remove_all_storage_on_destroy=true --all"
- IF ERRORLEVEL 1 (
- exit /b 1
- )
- CALL :DeployCDKApplication AWSClientAuth
- IF ERRORLEVEL 1 (
- exit /b 1
- )
- CALL :DeployCDKApplication AWSMetrics "-c batch_processing=true"
- IF ERRORLEVEL 1 (
- exit /b 1
- )
- EXIT /b 0
- :DeployCDKApplication
- REM Deploy the CDK application for a specific AWS gem
- SET GEM_NAME=%~1
- SET ADDITIONAL_ARGUMENTS=%~2
- ECHO [cdk_deployment] Deploy the CDK application for the %GEM_NAME% gem
- PUSHD %GEM_DIRECTORY%\%GEM_NAME%\cdk
- REM Revert the CDK application code to a stable state using the provided commit ID
- CALL git checkout %COMMIT_ID% -- .
- IF ERRORLEVEL 1 (
- ECHO [git_checkout] Failed to checkout the CDK application for the %GEM_NAME% gem using commit ID %COMMIT_ID%
- POPD
- exit /b 1
- )
- REM Install required packages for the CDK application
- CALL python -m pip install -r requirements.txt
- IF ERRORLEVEL 1 (
- ECHO [cdk_deployment] Failed to install required packages for the %GEM_NAME% gem
- POPD
- exit /b 1
- )
- REM Deploy the CDK application
- CALL cdk deploy %ADDITIONAL_ARGUMENTS% --require-approval never
- IF ERRORLEVEL 1 (
- ECHO [cdk_deployment] Failed to deploy the CDK application for the %GEM_NAME% gem
- POPD
- exit /b 1
- )
- POPD
|