single-instance-docker.yml 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. AWSTemplateFormatVersion: 2010-09-09
  2. Parameters:
  3. EC2InstanceType:
  4. Type: String
  5. Default: t2.xlarge
  6. EC2AMI:
  7. Type: String
  8. Default: 'ami-09e67e426f25ce0d7'
  9. KeyName:
  10. Description: Name of an existing EC2 KeyPair to enable SSH access to the instance
  11. Type: 'AWS::EC2::KeyPair::KeyName'
  12. Default: 'joystream-key'
  13. ConstraintDescription: must be the name of an existing EC2 KeyPair.
  14. Resources:
  15. SecurityGroup:
  16. Type: AWS::EC2::SecurityGroup
  17. Properties:
  18. GroupDescription: !Sub 'Internal Security group for validator nodes ${AWS::StackName}'
  19. SecurityGroupIngress:
  20. - IpProtocol: tcp
  21. FromPort: 22
  22. ToPort: 22
  23. CidrIp: 0.0.0.0/0
  24. Tags:
  25. - Key: Name
  26. Value: !Sub '${AWS::StackName}_validator'
  27. InstanceLaunchTemplate:
  28. Type: AWS::EC2::LaunchTemplate
  29. Metadata:
  30. AWS::CloudFormation::Init:
  31. config:
  32. packages:
  33. apt:
  34. wget: []
  35. unzip: []
  36. Properties:
  37. LaunchTemplateName: !Sub 'LaunchTemplate_${AWS::StackName}'
  38. LaunchTemplateData:
  39. ImageId: !Ref EC2AMI
  40. InstanceType: !Ref EC2InstanceType
  41. KeyName: !Ref KeyName
  42. SecurityGroupIds:
  43. - !GetAtt SecurityGroup.GroupId
  44. BlockDeviceMappings:
  45. - DeviceName: /dev/sda1
  46. Ebs:
  47. VolumeSize: '30'
  48. UserData:
  49. Fn::Base64: !Sub |
  50. #!/bin/bash -xe
  51. # send script output to /tmp so we can debug boot failures
  52. exec > /tmp/userdata.log 2>&1
  53. # Update all packages
  54. apt-get update -y
  55. # Install the updates
  56. apt-get upgrade -y
  57. apt-get install -y apt-transport-https ca-certificates curl gnupg lsb-release
  58. curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
  59. echo "deb [arch=arm64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
  60. apt-get update -y
  61. apt-get install -y docker-ce docker-ce-cli containerd.io
  62. usermod -aG docker ubuntu
  63. # Get latest cfn scripts and install them;
  64. apt-get install -y python3-setuptools
  65. mkdir -p /opt/aws/bin
  66. wget https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-py3-latest.tar.gz
  67. python3 -m easy_install --script-dir /opt/aws/bin aws-cfn-bootstrap-py3-latest.tar.gz
  68. apt-get install -y python3-pip
  69. /opt/aws/bin/cfn-signal -e $? -r "Instance Created" '${WaitHandle}'
  70. Instance:
  71. Type: AWS::EC2::Instance
  72. Properties:
  73. LaunchTemplate:
  74. LaunchTemplateId: !Ref InstanceLaunchTemplate
  75. Version: !GetAtt InstanceLaunchTemplate.LatestVersionNumber
  76. Tags:
  77. - Key: Name
  78. Value: !Sub '${AWS::StackName}_1'
  79. WaitHandle:
  80. Type: AWS::CloudFormation::WaitConditionHandle
  81. WaitCondition:
  82. Type: AWS::CloudFormation::WaitCondition
  83. Properties:
  84. Handle: !Ref 'WaitHandle'
  85. Timeout: '600'
  86. Count: 1
  87. Outputs:
  88. PublicIp:
  89. Description: The DNS name for the created instance
  90. Value: !Sub '${Instance.PublicIp}'
  91. Export:
  92. Name: !Sub '${AWS::StackName}PublicIp'
  93. InstanceId:
  94. Description: The Instance ID
  95. Value: !Ref Instance