<commit_before>class ContainerInstance
  attr_accessor :district

  def initialize(district)
    @district = district
  end

  def user_data
    user_data = InstanceUserData.new
    user_data.packages += ["aws-cli", "jq", "aws-cfn-bootstrap", "awslogs"]
    user_data.run_commands += [
      "set -ex",
      # Embed SHA2 hash dockercfg so that instance replacement happens when dockercfg is updated
      "# #{Digest::SHA256.hexdigest(district.dockercfg.to_s)}",

      # Setup swap
      "MEMSIZE=`cat /proc/meminfo | grep MemTotal | awk '{print $2}'`",
      "if [ $MEMSIZE -lt 2097152 ]; then",
      "  SIZE=$((MEMSIZE * 2))k",
      "elif [ $MEMSIZE -lt 8388608 ]; then",
      "  SIZE=${MEMSIZE}k",
      "else",
      "  SIZE=8388608k",
      "fi",
      "fallocate -l $SIZE /swap.img && mkswap /swap.img && chmod 600 /swap.img && swapon /swap.img",

      "AWS_REGION=#{district.region}",
      "aws configure set s3.signature_version s3v4",
      "aws s3 cp s3://#{district.s3_bucket_name}/#{district.name}/ecs.config /etc/ecs/ecs.config",
      "chmod 600 /etc/ecs/ecs.config",

      # Configure sshd
      'printf "\nTrustedUserCAKeys /etc/ssh/ssh_ca_key.pub\n" >> /etc/ssh/sshd_config',
      'sed -i -e "s/^PermitRootLogin .*/PermitRootLogin no/" /etc/ssh/sshd_config',
      "service sshd restart",

      # Configure AWS CloudWatch Logs
      "ec2_id=$(curl http://169.254.169.254/latest/meta-data/instance-id)",
      'sed -i -e "s/{ec2_id}/$ec2_id/g" /etc/awslogs/awslogs.conf',
      'sed -i -e "s/us-east-1/'+district.region+'/g" /etc/awslogs/awscli.conf',
      "systemctl start awslogsd",

      # Install SSM agent
      "yum install -y https://amazon-ssm-#{district.region}.s3.amazonaws.com/latest/linux_amd64/amazon-ssm-agent.rpm",

      # Install AWS Inspector agent
      "curl https://d1wk0tztpsntt1.cloudfront.net/linux/latest/install | bash"
    ]<commit_msg>Remove installing ssm-agent in clout-init script<commit_after>class ContainerInstance
  attr_accessor :district

  def initialize(district)
    @district = district
  end

  def user_data
    user_data = InstanceUserData.new
    user_data.packages += ["aws-cli", "jq", "aws-cfn-bootstrap", "awslogs"]
    user_data.run_commands += [
      "set -ex",
      # Embed SHA2 hash dockercfg so that instance replacement happens when dockercfg is updated
      "# #{Digest::SHA256.hexdigest(district.dockercfg.to_s)}",

      # Setup swap
      "MEMSIZE=`cat /proc/meminfo | grep MemTotal | awk '{print $2}'`",
      "if [ $MEMSIZE -lt 2097152 ]; then",
      "  SIZE=$((MEMSIZE * 2))k",
      "elif [ $MEMSIZE -lt 8388608 ]; then",
      "  SIZE=${MEMSIZE}k",
      "else",
      "  SIZE=8388608k",
      "fi",
      "fallocate -l $SIZE /swap.img && mkswap /swap.img && chmod 600 /swap.img && swapon /swap.img",

      "AWS_REGION=#{district.region}",
      "aws configure set s3.signature_version s3v4",
      "aws s3 cp s3://#{district.s3_bucket_name}/#{district.name}/ecs.config /etc/ecs/ecs.config",
      "chmod 600 /etc/ecs/ecs.config",

      # Configure sshd
      'printf "\nTrustedUserCAKeys /etc/ssh/ssh_ca_key.pub\n" >> /etc/ssh/sshd_config',
      'sed -i -e "s/^PermitRootLogin .*/PermitRootLogin no/" /etc/ssh/sshd_config',
      "service sshd restart",

      # Configure AWS CloudWatch Logs
      "ec2_id=$(curl http://169.254.169.254/latest/meta-data/instance-id)",
      'sed -i -e "s/{ec2_id}/$ec2_id/g" /etc/awslogs/awslogs.conf',
      'sed -i -e "s/us-east-1/'+district.region+'/g" /etc/awslogs/awscli.conf',
      "systemctl start awslogsd",

      # Install AWS Inspector agent
      "curl https://d1wk0tztpsntt1.cloudfront.net/linux/latest/install | bash"
    ]
{'fraction_non_alphanumeric': 0.15881231272132934, 'fraction_numerical': 0.03241623535821302, 'mean_word_length': 2.849056603773585, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '645989', 'n_tokens_mistral': 1445, 'n_tokens_neox': 1320, 'n_words': 266}