Copy AMIs in parallel

+39 -18
+39 -18
nixos/maintainers/scripts/ec2/create-amis.sh
··· 13 13 14 14 rm -f ec2-amis.nix 15 15 16 + types="hvm pv" 17 + stores="ebs s3" 18 + regions="eu-west-1 eu-central-1 us-east-1 us-west-1 us-west-2 ap-southeast-1 ap-southeast-2 ap-northeast-1 sa-east-1" 16 19 17 - for type in hvm pv; do 20 + for type in $types; do 18 21 link=$stateDir/$type 19 22 imageFile=$link/nixos.qcow2 20 23 system=x86_64-linux ··· 31 34 --arg configuration "{ imports = [ <nixpkgs/nixos/maintainers/scripts/ec2/amazon-image.nix> ]; ec2.hvm = $hvmFlag; }" 32 35 fi 33 36 34 - for store in ebs s3; do 37 + for store in $stores; do 35 38 36 39 bucket=nixos-amis 37 40 bucketDir="$version-$type-$store" ··· 39 42 prevAmi= 40 43 prevRegion= 41 44 42 - for region in eu-west-1 eu-central-1 us-east-1 us-west-1 us-west-2 ap-southeast-1 ap-southeast-2 ap-northeast-1 sa-east-1; do 45 + for region in $regions; do 43 46 44 47 name=nixos-$version-$arch-$type-$store 45 48 description="NixOS $system $version ($type-$store)" ··· 226 229 227 230 echo "region = $region, type = $type, store = $store, ami = $ami" 228 231 229 - if [ -z "$NO_WAIT" -o -z "$prevAmi" ]; then 230 - echo -n "waiting for AMI..." 231 - while true; do 232 - status=$(aws ec2 describe-images --image-ids "$ami" --region "$region" | jq -r .Images[0].State) 233 - if [ "$status" = available ]; then break; fi 234 - sleep 10 235 - echo -n '.' 236 - done 237 - echo 238 - 239 - # Make the image public. 240 - aws ec2 modify-image-attribute \ 241 - --image-id "$ami" --region "$region" --launch-permission 'Add={Group=all}' 242 - fi 243 - 244 232 if [ -z "$prevAmi" ]; then 245 233 prevAmi="$ami" 246 234 prevRegion="$region" 247 235 fi 236 + done 237 + 238 + done 239 + 240 + done 241 + 242 + for type in $types; do 243 + link=$stateDir/$type 244 + system=x86_64-linux 245 + arch=x86_64 246 + 247 + for store in $stores; do 248 + 249 + for region in $regions; do 250 + 251 + name=nixos-$version-$arch-$type-$store 252 + amiFile=$stateDir/$region.$type.$store.ami-id 253 + ami=$(cat $amiFile) 254 + 255 + echo "region = $region, type = $type, store = $store, ami = $ami" 256 + 257 + echo -n "waiting for AMI..." 258 + while true; do 259 + status=$(aws ec2 describe-images --image-ids "$ami" --region "$region" | jq -r .Images[0].State) 260 + if [ "$status" = available ]; then break; fi 261 + sleep 10 262 + echo -n '.' 263 + done 264 + echo 265 + 266 + # Make the image public. 267 + aws ec2 modify-image-attribute \ 268 + --image-id "$ami" --region "$region" --launch-permission 'Add={Group=all}' 248 269 249 270 echo " \"$major\".$region.$type-$store = \"$ami\";" >> ec2-amis.nix 250 271 done