deploy_cdk_applications.cmd 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. @ECHO OFF
  2. REM
  3. REM Copyright (c) Contributors to the Open 3D Engine Project.
  4. REM For complete copyright and license terms please see the LICENSE at the root of this distribution.
  5. REM
  6. REM SPDX-License-Identifier: Apache-2.0 OR MIT
  7. REM
  8. REM
  9. REM Deploy the CDK applications for AWS gems (Windows only)
  10. REM Prerequisites:
  11. REM 1) Node.js is installed
  12. 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.
  13. SETLOCAL EnableDelayedExpansion
  14. SET SOURCE_DIRECTORY=%CD%
  15. SET PATH=%SOURCE_DIRECTORY%\python;%PATH%
  16. SET GEM_DIRECTORY=%SOURCE_DIRECTORY%\Gems
  17. ECHO [cdk_installation] Install aws-cdk@%CDK_VERSION%
  18. CALL npm uninstall -g aws-cdk
  19. IF ERRORLEVEL 1 (
  20. ECHO [cdk_bootstrap] Failed to uninstall the current version of CDK
  21. exit /b 1
  22. )
  23. CALL npm install -g aws-cdk@%CDK_VERSION%
  24. IF ERRORLEVEL 1 (
  25. ECHO [cdk_bootstrap] Failed to install aws-cdk@%CDK_VERSION%
  26. exit /b 1
  27. )
  28. REM Set temporary AWS credentials from the assume role
  29. 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 (
  30. SET AWS_SECRET_ACCESS_KEY=%%a
  31. SET AWS_SESSION_TOKEN=%%b
  32. SET AWS_ACCESS_KEY_ID=%%c
  33. )
  34. FOR /F "tokens=4 delims=:" %%a IN ("%ASSUME_ROLE_ARN%") DO SET O3DE_AWS_DEPLOY_ACCOUNT=%%a
  35. IF "%O3DE_AWS_PROJECT_NAME%"=="" (
  36. REM To avoid resource name length issues, potentially verbose pipeline names are capped at 25 chars.
  37. REM TODO: consolidate project name formulation for tests and deploy/destroy scripts to same place.
  38. ECHO Truncated pipeline name is: %PIPELINE_NAME:~0,25%
  39. SET O3DE_AWS_PROJECT_NAME=%BRANCH_NAME%-%PIPELINE_NAME:~0,25%-Windows
  40. SET slashreplace=
  41. call SET O3DE_AWS_PROJECT_NAME=%%O3DE_AWS_PROJECT_NAME:/=%slashreplace%%%
  42. )
  43. REM Bootstrap and deploy the CDK applications
  44. ECHO [cdk_bootstrap] Bootstrap CDK
  45. CALL cdk bootstrap aws://%O3DE_AWS_DEPLOY_ACCOUNT%/%O3DE_AWS_DEPLOY_REGION%
  46. IF ERRORLEVEL 1 (
  47. ECHO [cdk_bootstrap] Failed to bootstrap CDK
  48. exit /b 1
  49. )
  50. CALL :DeployCDKApplication AWSCore "-c disable_access_log=true -c remove_all_storage_on_destroy=true --all"
  51. IF ERRORLEVEL 1 (
  52. exit /b 1
  53. )
  54. CALL :DeployCDKApplication AWSClientAuth
  55. IF ERRORLEVEL 1 (
  56. exit /b 1
  57. )
  58. CALL :DeployCDKApplication AWSMetrics "-c batch_processing=true"
  59. IF ERRORLEVEL 1 (
  60. exit /b 1
  61. )
  62. EXIT /b 0
  63. :DeployCDKApplication
  64. REM Deploy the CDK application for a specific AWS gem
  65. SET GEM_NAME=%~1
  66. SET ADDITIONAL_ARGUMENTS=%~2
  67. ECHO [cdk_deployment] Deploy the CDK application for the %GEM_NAME% gem
  68. PUSHD %GEM_DIRECTORY%\%GEM_NAME%\cdk
  69. REM Revert the CDK application code to a stable state using the provided commit ID
  70. CALL git checkout %COMMIT_ID% -- .
  71. IF ERRORLEVEL 1 (
  72. ECHO [git_checkout] Failed to checkout the CDK application for the %GEM_NAME% gem using commit ID %COMMIT_ID%
  73. POPD
  74. exit /b 1
  75. )
  76. REM Install required packages for the CDK application
  77. CALL python -m pip install -r requirements.txt
  78. IF ERRORLEVEL 1 (
  79. ECHO [cdk_deployment] Failed to install required packages for the %GEM_NAME% gem
  80. POPD
  81. exit /b 1
  82. )
  83. REM Deploy the CDK application
  84. CALL cdk deploy %ADDITIONAL_ARGUMENTS% --require-approval never
  85. IF ERRORLEVEL 1 (
  86. ECHO [cdk_deployment] Failed to deploy the CDK application for the %GEM_NAME% gem
  87. POPD
  88. exit /b 1
  89. )
  90. POPD