<commit_before>#!/bin/bash
set -euo pipefail

# Copies an AMI to all other regions and outputs a build/mappings.yml file
# Local Usage: .buildkite/steps/copy.sh <ami_id>

copy_ami_to_region() {
  local source_image_id="$1"
  local source_region="$2"
  local destination_image_region="$3"
  local destination_image_name="$4"

  aws ec2 copy-image \
    --source-image-id "$source_image_id" \
    --source-region "$source_region" \
    --name "$destination_image_name" \
    --region "$destination_image_region" \
    --query "ImageId" \
    --output text
}

wait_for_ami_to_be_available() {
  local image_id="$1"
  local region="$2"
  local image_state

  while true; do
    image_state=$(aws ec2 describe-images --region "$region" --image-ids "$image_id" --output text --query 'Images[*].State');
    echo "$image_id ($region) is $image_state"

    if [[ "$image_state" == "available" ]]; then
      break
    elif [[ "$image_state" == "pending" ]]; then
      sleep 10
    else
      exit 1
    fi
  done
}

make_ami_public() {
  local image_id="$1"
  local region="$2"

  aws ec2 modify-image-attribute \
    --region "$region" \
    --image-id "$image_id" \
    --launch-permission "{\"Add\": [{\"Group\":\"all\"}]}"
}

if [[ -z "${BUILDKITE_AWS_STACK_BUCKET}" ]] ; then
  echo "Must set an s3 bucket in BUILDKITE_AWS_STACK_BUCKET for temporary files"
  exit 1
fi

ALL_REGIONS=(
  us-east-2
  us-west-1
  us-west-2
  ap-south-1
  ap-northeast-2
  ap-southeast-1
  ap-southeast-2
  ap-northeast-1<commit_msg>Add back us-east-1<commit_after>#!/bin/bash
set -euo pipefail

# Copies an AMI to all other regions and outputs a build/mappings.yml file
# Local Usage: .buildkite/steps/copy.sh <ami_id>

copy_ami_to_region() {
  local source_image_id="$1"
  local source_region="$2"
  local destination_image_region="$3"
  local destination_image_name="$4"

  aws ec2 copy-image \
    --source-image-id "$source_image_id" \
    --source-region "$source_region" \
    --name "$destination_image_name" \
    --region "$destination_image_region" \
    --query "ImageId" \
    --output text
}

wait_for_ami_to_be_available() {
  local image_id="$1"
  local region="$2"
  local image_state

  while true; do
    image_state=$(aws ec2 describe-images --region "$region" --image-ids "$image_id" --output text --query 'Images[*].State');
    echo "$image_id ($region) is $image_state"

    if [[ "$image_state" == "available" ]]; then
      break
    elif [[ "$image_state" == "pending" ]]; then
      sleep 10
    else
      exit 1
    fi
  done
}

make_ami_public() {
  local image_id="$1"
  local region="$2"

  aws ec2 modify-image-attribute \
    --region "$region" \
    --image-id "$image_id" \
    --launch-permission "{\"Add\": [{\"Group\":\"all\"}]}"
}

if [[ -z "${BUILDKITE_AWS_STACK_BUCKET}" ]] ; then
  echo "Must set an s3 bucket in BUILDKITE_AWS_STACK_BUCKET for temporary files"
  exit 1
fi

ALL_REGIONS=(
  us-east-1
  us-east-2
  us-west-1
  us-west-2
  ap-south-1
  ap-northeast-2
  ap-southeast-1
  ap-southeast-2
  ap-northeast-1
{'fraction_non_alphanumeric': 0.15278235100428053, 'fraction_numerical': 0.016463615409944024, 'mean_word_length': 3.1054054054054054, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1324543', 'n_tokens_mistral': 1144, 'n_tokens_neox': 1115, 'n_words': 258}