single-instance-docker.yml 3.6 KB

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