実現したいこと
AWS CodeBuildで、
aws/codebuild/standard:3.0からaws/codebuild/standard:7.0に変えた後再ビルド実行したら
buildspec.ymlに記載した「while :」コマンドが失敗してしまうので、成功するように解決したいです。
発生している問題・分からないこと
エラーメッセージのうち下記エラーがきっかけで失敗しているように見えます。
[Container] 2024/02/08 08:12:03.999403 Phase complete: BUILD State: FAILED
[Container] 2024/02/08 08:12:03.999422 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: while :
エラーメッセージ
error
12[Container] 2024/02/08 08:12:03.994661 Command did not exit successfully while : 3do 4 echo "imageScanStatus: $scan_status"; 5 if [ $scan_status = "COMPLETE" ]; then 6 break; 7 fi 8 if [ $timeout_count -gt 20 ]; then 9 echo "Timeout!!"; 10 exit 1; 11 fi 12 sleep 3; 13 scan_status=$(aws ecr describe-image-scan-findings --repository-name $target_project_name_l --image-id imageTag=latest | jq -r '.imageScanStatus.status' ); 14 timeout_count=$(( timeout_count + 1 )); 15done 16 exit status 1 17[Container] 2024/02/08 08:12:03.999403 Phase complete: BUILD State: FAILED 18[Container] 2024/02/08 08:12:03.999422 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: while :
該当のソースコード
yml
1version: 0.22 3env:4 parameter-store:5 MAVEN_TSCPP_DEVELOPER_USER: "MAVEN_TSCPP_DEVELOPER_USER"6 MAVEN_TSCPP_DEVELOPER_PASSWORD: "MAVEN_TSCPP_DEVELOPER_PASSWORD"7phases:8 install:9 commands:10 - nohup /usr/local/bin/dockerd --host=unix:///var/run/docker.sock --host=tcp://127.0.0.1:2375 --storage-driver=overlay& 11 - curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -12 - apt -y update 13 - apt -y install jq 14 - timeout 15 sh -c "until docker info; do echo .; sleep 1; done" 15 - cp -fr $CODEBUILD_SRC_DIR_BuildArtifact/build ./ 16 17 pre_build:18 commands:19 - export target_project_name_l=`echo "$TARGET_PROJECT_NAME" | awk '{print tolower($0)}'` 20 - export image_tag=$CODEBUILD_RESOLVED_SOURCE_VERSION 21 - export ecr_uri=354447979371.dkr.ecr.us-west-2.amazonaws.com/$target_project_name_l 22 23 # AWS認証情報取得24 # stsのendpointに、明示的にデプロイ対象のregionを指定しないと、25 # sts endpointから取得できる認証tokenが、デフォルトでONになっていないリージョンで操作権限のないものとなるため注意26 - credentials=$(aws sts assume-role --duration-seconds 3600 --role-arn arn:aws:iam::354447979371:role/CrossAccountRole_832053171557_ECRPushRole --role-session-name session-hoge --region us-west-2 --endpoint https://sts.us-west-2.amazonaws.com | jq .Credentials) 27 - export AWS_ACCESS_KEY_ID=$(echo $credentials | jq -r .AccessKeyId) 28 - export AWS_SECRET_ACCESS_KEY=$(echo $credentials | jq -r .SecretAccessKey) 29 - export AWS_SESSION_TOKEN=$(echo $credentials | jq -r .SessionToken) 30 - export AWS_DEFAULT_REGION=us-west-231 - aws sts get-caller-identity 32 33 build:34 commands:35 - |36 docker login 19maven.tscapi.g-book.com -u $MAVEN_TSCPP_DEVELOPER_USER -p $MAVEN_TSCPP_DEVELOPER_PASSWORD 37 docker pull 19maven.tscapi.g-book.com/openjdk:8-jdk 38 docker tag 19maven.tscapi.g-book.com/openjdk:8-jdk openjdk:8-jdk 39 docker pull 19maven.tscapi.g-book.com/openjdk:8-jdk-slim 40 docker tag 19maven.tscapi.g-book.com/openjdk:8-jdk-slim openjdk:8-jdk-slim 41 docker pull 19maven.tscapi.g-book.com/openjdk:8u282-jdk-slim 42 docker tag 19maven.tscapi.g-book.com/openjdk:8u282-jdk-slim openjdk:8u282-jdk-slim 43 docker pull 19maven.tscapi.g-book.com/alpine 44 docker tag 19maven.tscapi.g-book.com/alpine alpine 45 docker pull 19maven.tscapi.g-book.com/nginx@sha256:08262e7a01055bd33920b3f59e2249f438eea5d25cc67b8d8c7f5854437786d2 46 docker images 47 docker tag 2a36393edaf1 nginx 48 docker tag 2a36393edaf1 19maven.tscapi.g-book.com/nginx49 50 # Jarファイルの名前を変更(Dockerfile.deploy.awsに定義されている名前と合わせるため)51 - mv build/libs/*.jar build/libs/$TARGET_PROJECT_NAME-0.0.1-SNAPSHOT.jar 52 53 # dockerイメージ作成54 - docker build -t $ecr_uri:latest -f Dockerfile.deploy.aws . 55 - docker tag $ecr_uri:latest $ecr_uri:$image_tag 56 57 # AWS ECRレポジトリ作成58 - aws ecr create-repository --repository-name $target_project_name_l | awk '{print $1}' 59 60 # AWS ECRログイン61 - aws ecr get-login-password --region us-west-2 | docker login --username AWS --password-stdin $ecr_uri 62 63 # ECRにイメージがPushされたタイミングで自動スキャンされるように設定する64 - aws ecr put-image-scanning-configuration --repository-name $target_project_name_l --image-scanning-configuration scanOnPush=true 65 66 # dockerイメージをECRにPush67 - docker push $ecr_uri:latest 68 - docker push $ecr_uri:$image_tag 69 70 ################### ↓↓↓ ECRスキャン ↓↓↓ ###################71 # スキャンの進行状況を取得72 - scan_status=$(aws ecr describe-image-scan-findings --repository-name $target_project_name_l --image-id imageTag=latest | jq -r '.imageScanStatus.status' ) 73 74 # スキャンの進行状況がCOMPLETEになるまで結果を取得75 - timeout_count=0 76 - |77 while : 78 do 79 echo "imageScanStatus: $scan_status"; 80 if [ $scan_status = "COMPLETE" ]; then 81 break; 82 fi 83 if [ $timeout_count -gt 20 ]; then 84 echo "Timeout!!"; 85 exit 1; 86 fi 87 sleep 3; 88 scan_status=$(aws ecr describe-image-scan-findings --repository-name $target_project_name_l --image-id imageTag=latest | jq -r '.imageScanStatus.status' ); 89 timeout_count=$(( timeout_count + 1 )); 90 done91 92 以下略
試したこと・調べたこと
上記の詳細・結果
buildspec.ymlの「while :」を「while true」に変えた。
補足
ビルドプロジェクトの詳細
・環境タイプ:Linux EC2
・イメージ:aws/codebuild/standard:7.0(aws/codebuild/standard:5.0でも試した。)

0 コメント