Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ハンズオン当日セットアップの自動化 #444

Open
MasayaAoyama opened this issue Nov 26, 2024 · 0 comments
Open

ハンズオン当日セットアップの自動化 #444

MasayaAoyama opened this issue Nov 26, 2024 · 0 comments

Comments

@MasayaAoyama
Copy link
Contributor

一旦残骸を残しておく

for index in `seq -w 02 40`; do

export AWS_PAGER=""

aws ec2 create-key-pair  \
  --key-name cnd-handson-key-${index} \
  --key-type ed25519 \
  --query 'KeyMaterial' \
  --output text > cnd-handson-key-${index}.pem

aws ec2 create-security-group \
  --group-name cnd-handson-segcroup-${index} \
  --description "CND handson security group ${index}"

SECGROUP_ID=`aws ec2 describe-security-groups --group-names "cnd-handson-segcroup-${index}" --query 'SecurityGroups[*].[GroupId]' --output text`
for PORT in 22 80 443 8080 8443 18080 18443 28080 28443; do
  aws ec2 authorize-security-group-ingress \
  --group-id ${SECGROUP_ID} \
  --protocol tcp \
  --cidr 0.0.0.0/0 \
  --port ${PORT}
done

done






for index in `seq -w 02 40`; do

export AWS_PAGER=""

SECGROUP_ID=`aws ec2 describe-security-groups --group-names "cnd-handson-segcroup-${index}" --query 'SecurityGroups[*].[GroupId]' --output text`

aws ec2 run-instances \
  --image-id ami-0162fe8bfebb6ea16 \
  --count 1 \
  --instance-type t2.xlarge \
  --block-device-mappings '[{"DeviceName":"/dev/sda1","Ebs":{"VolumeSize":100}}]' \
  --key-name cnd-handson-key-${index} \
  --security-group-ids ${SECGROUP_ID} \
  --tag-specifications "ResourceType=instance,Tags=[{Key=Name,Value=cnd-handson-vm-${index}}]"

done







for index in `seq -w 02 40`; do

export AWS_PAGER=""

aws ec2 describe-instances \
  --filters "Name=tag:Name,Values=cnd-handson-vm-${index}" \
  --query 'Reservations[*].Instances[*].PublicIpAddress' \
  --output text

done







for index in `seq -w 01 40`; do

cp record.json record-$index.json

IPADDR=`head -n $index iplist.txt | tail -n 1`

perl -pi -e "s|vmXX|vm$index|g" record-$index.json
perl -pi -e "s|xxx.xxx.xxx.xxx|$IPADDR|g" record-$index.json

aws route53 change-resource-record-sets \
    --hosted-zone-id Z080738624DO48AUL6TRM \
    --change-batch file://record-$index.json

done



for index in `seq -w 01 40`; do

IPADDR=`head -n $index iplist.txt | tail -n 1`

ssh ubuntu@$IPADDR -i cnd-handson-key-${index}.pem

done












cat << _EOF_ > record.json
{
  "Comment": "Add a test record",
  "Changes": [
_EOF_

for RECORD in hello-world.vmXX.handson.cloudnativedays.jp rollout.vmXX.handson.cloudnativedays.jp blue.vmXX.handson.cloudnativedays.jp green.vmXX.handson.cloudnativedays.jp app.vmXX.handson.cloudnativedays.jp cndw-web.vmXX.handson.cloudnativedays.jp prometheus.vmXX.handson.cloudnativedays.jp grafana.vmXX.handson.cloudnativedays.jp jaeger.vmXX.handson.cloudnativedays.jp argocd.vmXX.handson.cloudnativedays.jp app.argocd.vmXX.handson.cloudnativedays.jp dev.kustomize.argocd.vmXX.handson.cloudnativedays.jp prd.kustomize.argocd.vmXX.handson.cloudnativedays.jp helm.argocd.vmXX.handson.cloudnativedays.jp app-preview.argocd.vmXX.handson.cloudnativedays.jp kiali.vmXX.handson.cloudnativedays.jp kiali-ambient.vmXX.handson.cloudnativedays.jp app.cilium.vmXX.handson.cloudnativedays.jp hubble.cilium.vmXX.handson.cloudnativedays.jp pyroscope.vmXX.handson.cloudnativedays.jp; do

cat << _EOF_ >> record.json
    {
      "Action": "UPSERT",
      "ResourceRecordSet": {
        "Name": "$RECORD.",
        "Type": "A",
        "TTL": 300,
        "ResourceRecords": [
          {
            "Value": "xxx.xxx.xxx.xxx"
          }
        ]
      }
    },
_EOF_

done

cat << _EOF_ >> record.json
  ]
}
_EOF_


for index in `seq -w 01 40`; do

git checkout -b handson-cndw2024-${index}

for FILE in `grep vmXX.handson.cloudnativedays.jp ./* -R | cut -d ":" -f 1 | sort | uniq `; do

perl -pi -e "s|vmXX.handson.cloudnativedays.jp|vm${index}.handson.cloudnativedays.jp|g" $FILE

done

gcmt -m "personalize $index"; gpush
git checkout handson-cndw2024

done

git clone https://github.com/cloudnativedaysjp/cnd-handson
git checkout handson-cndw2024-$index
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant