如何从代码构建中并行部署多个 shell 脚本?
How to deploy multiple shell scripts in parallel from codebuild?
所以目前我有一个代码构建,当我推送到我的存储库时由代码管道触发。
这些文件有一个 .sh 文件、一个 buildspec.yaml 文件和一个包含 1 到 n 个文件夹的文件夹,每个文件夹都有自己的 .sh 文件,然后将在其中部署 cloudformation 资源文件夹。
deploy.sh
buildspec.yaml
Folder
|
|-- Directory1
| -- deploy.sh
| -- template.yaml
|
|-- Directory2
| -- deploy.sh
| -- template.yaml
|
|-- Directory3
| -- deploy.sh
| -- template.yaml
目前,第一个 .sh 文件只是一个 for 循环,它将 cd 进入每个目录,然后 运行 .sh 脚本依次进入。
我试图使这个过程并行而不是顺序进行。由于可能有未知数量的子文件夹,这可能是一个漫长的过程,我不希望它等待以前的资源。
有人在这方面 advice/experience 吗?我做了一些搜索,但在我的测试中没有发现任何结论。
编辑:主 build.sh 文件,运行 是 for 循环
#!/bin/bash
set -e
PROFILE='new-profile'
aws configure --profile $PROFILE set credential_source EcsContainer
REGION=$AWS_REGION
for directory in *; do
if [ -d ${directory} ]; then
# Will not run if no directories are available
chmod +x $directory/deploy.sh
$directory/deploy.sh -p new-profile &
# cd $directory
# echo $directory
# echo "---------------------------------------------------------------------------------"
# echo "Start deploying $directory resources..."
# echo "---------------------------------------------------------------------------------"
# chmod +x ./deploy.sh
# ./deploy.sh -p new-profile &
# cd ../
# echo "---------------------------------------------------------------------------------"
# echo "End deploying $directory resources..."
# echo "---------------------------------------------------------------------------------"
fi
done
wait
echo "finished deployment"
在您的主脚本中,只需在后台循环所有子 deploy.sh 和 运行 它们,将 & 添加到字符串的末尾:
$directory/deploy.sh &
在主脚本的末尾写入
wait
echo "all sub-deploy processes are finished"
所以目前我有一个代码构建,当我推送到我的存储库时由代码管道触发。
这些文件有一个 .sh 文件、一个 buildspec.yaml 文件和一个包含 1 到 n 个文件夹的文件夹,每个文件夹都有自己的 .sh 文件,然后将在其中部署 cloudformation 资源文件夹。
deploy.sh
buildspec.yaml
Folder
|
|-- Directory1
| -- deploy.sh
| -- template.yaml
|
|-- Directory2
| -- deploy.sh
| -- template.yaml
|
|-- Directory3
| -- deploy.sh
| -- template.yaml
目前,第一个 .sh 文件只是一个 for 循环,它将 cd 进入每个目录,然后 运行 .sh 脚本依次进入。
我试图使这个过程并行而不是顺序进行。由于可能有未知数量的子文件夹,这可能是一个漫长的过程,我不希望它等待以前的资源。
有人在这方面 advice/experience 吗?我做了一些搜索,但在我的测试中没有发现任何结论。
编辑:主 build.sh 文件,运行 是 for 循环
#!/bin/bash
set -e
PROFILE='new-profile'
aws configure --profile $PROFILE set credential_source EcsContainer
REGION=$AWS_REGION
for directory in *; do
if [ -d ${directory} ]; then
# Will not run if no directories are available
chmod +x $directory/deploy.sh
$directory/deploy.sh -p new-profile &
# cd $directory
# echo $directory
# echo "---------------------------------------------------------------------------------"
# echo "Start deploying $directory resources..."
# echo "---------------------------------------------------------------------------------"
# chmod +x ./deploy.sh
# ./deploy.sh -p new-profile &
# cd ../
# echo "---------------------------------------------------------------------------------"
# echo "End deploying $directory resources..."
# echo "---------------------------------------------------------------------------------"
fi
done
wait
echo "finished deployment"
在您的主脚本中,只需在后台循环所有子 deploy.sh 和 运行 它们,将 & 添加到字符串的末尾:
$directory/deploy.sh &
在主脚本的末尾写入
wait
echo "all sub-deploy processes are finished"