Last active
March 23, 2023 06:48
-
-
Save sasasin/4d916d1a87204bdfa625ce48f19c7897 to your computer and use it in GitHub Desktop.
CodeBuild のコンテナイメージのとこだけ書き換えるやつ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| set -eo pipefail | |
| CODEBUILD_PROJECT_NAME="$1" | |
| aws codebuild update-project \ | |
| --name "${CODEBUILD_PROJECT_NAME}" \ | |
| --cli-input-json file://"${CODEBUILD_PROJECT_NAME}".patch.json \ | |
| > /dev/null | |
| # 更新後で取る | |
| # before と diff れるようにしたいので | |
| aws codebuild batch-get-projects \ | |
| --names "${CODEBUILD_PROJECT_NAME}" \ | |
| > "${CODEBUILD_PROJECT_NAME}".origin.after.json | |
| # update-project するとき邪魔なものを削る | |
| # before と diff れるようにしたいので | |
| cat "${CODEBUILD_PROJECT_NAME}".origin.after.json \ | |
| | jq '.projects[]' \ | |
| | jq 'del(.arn, .created, .lastModified, .badge, .projectVisibility, .webhook, .publicProjectAlias)' \ | |
| > "${CODEBUILD_PROJECT_NAME}".after.json | |
| set +e | |
| # 余計なとこ書き換えてないよね確認 | |
| # 書き換えるはずのとこは書き換えてるよな確認 | |
| diff -w \ | |
| <(jq --sort-keys . "${CODEBUILD_PROJECT_NAME}".before.json) \ | |
| <(jq --sort-keys . "${CODEBUILD_PROJECT_NAME}".after.json) | |
| # update-project 用に削ったこいつら | |
| # jq 'del(....)' | |
| # のうち .created, .lastModified 以外も、勝手に書き換えてないよね確認 | |
| diff -w \ | |
| <(cat "${CODEBUILD_PROJECT_NAME}".origin.before.json \ | |
| | jq '.projects[]' \ | |
| | jq 'del(.created, .lastModified)' \ | |
| | jq --sort-keys . ) \ | |
| <(cat "${CODEBUILD_PROJECT_NAME}".origin.after.json \ | |
| | jq '.projects[]' \ | |
| | jq 'del(.created, .lastModified)' \ | |
| | jq --sort-keys . ) | |
| /usr/bin/true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| set -eo pipefail | |
| CODEBUILD_PROJECT_NAME="$1" | |
| set +e | |
| # 余計なとこ書き換えてないよね確認 | |
| # 書き換えるはずのとこは書き換えてるよな確認 | |
| diff -w \ | |
| <(jq --sort-keys . "${CODEBUILD_PROJECT_NAME}".before.json) \ | |
| <(jq --sort-keys . "${CODEBUILD_PROJECT_NAME}".patch.json) | |
| # 余計なとこ書き換えてないよね確認 | |
| # 書き換えるはずのとこは書き換えてるよな確認 | |
| diff -w \ | |
| <(jq --sort-keys . "${CODEBUILD_PROJECT_NAME}".before.json) \ | |
| <(jq --sort-keys . "${CODEBUILD_PROJECT_NAME}".after.json) | |
| # update-project 用に削ったこいつら | |
| # jq 'del(....)' | |
| # のうち .created, .lastModified 以外も、勝手に書き換えてないよね確認 | |
| diff -w \ | |
| <(cat "${CODEBUILD_PROJECT_NAME}".origin.before.json \ | |
| | jq '.projects[]' \ | |
| | jq 'del(.created, .lastModified)' \ | |
| | jq --sort-keys . ) \ | |
| <(cat "${CODEBUILD_PROJECT_NAME}".origin.after.json \ | |
| | jq '.projects[]' \ | |
| | jq 'del(.created, .lastModified)' \ | |
| | jq --sort-keys . ) | |
| /usr/bin/true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| set -eo pipefail | |
| CODEBUILD_PROJECT_NAME="$1" | |
| aws codebuild batch-get-projects \ | |
| --names "${CODEBUILD_PROJECT_NAME}" \ | |
| > "${CODEBUILD_PROJECT_NAME}".origin.before.json | |
| # update-project するとき邪魔なものを削る | |
| cat "${CODEBUILD_PROJECT_NAME}".origin.before.json \ | |
| | jq '.projects[]' \ | |
| | jq 'del(.arn, .created, .lastModified, .badge, .projectVisibility, .webhook, .publicProjectAlias)' \ | |
| > "${CODEBUILD_PROJECT_NAME}".before.json | |
| # マネージドイメージのとこだけ書き換える | |
| cat "${CODEBUILD_PROJECT_NAME}".before.json \ | |
| | jq '.environment.image |= gsub("aws/codebuild/amazonlinux2-x86_64-standard:[23].0.*"; "aws/codebuild/amazonlinux2-x86_64-standard:4.0")' \ | |
| | jq '.environment.image |= gsub("aws/codebuild/standard:[345].0.*"; "aws/codebuild/standard:6.0")' \ | |
| > "${CODEBUILD_PROJECT_NAME}".patch.json | |
| set +e | |
| # 余計なとこ書き換えてないよね確認 | |
| # 書き換えるはずのとこは書き換えてるよな確認 | |
| diff -w \ | |
| <(jq --sort-keys . "${CODEBUILD_PROJECT_NAME}".before.json) \ | |
| <(jq --sort-keys . "${CODEBUILD_PROJECT_NAME}".patch.json) | |
| /usr/bin/true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment