single-instance-docker.yml 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. - IpProtocol: tcp
  27. FromPort: 443
  28. ToPort: 443
  29. CidrIp: 0.0.0.0/0
  30. - IpProtocol: tcp
  31. FromPort: 80
  32. ToPort: 80
  33. CidrIp: 0.0.0.0/0
  34. Tags:
  35. - Key: Name
  36. Value: !Sub '${AWS::StackName}_validator'
  37. InstanceLaunchTemplate:
  38. Type: AWS::EC2::LaunchTemplate
  39. Metadata:
  40. AWS::CloudFormation::Init:
  41. config:
  42. packages:
  43. apt:
  44. wget: []
  45. unzip: []
  46. Properties:
  47. LaunchTemplateName: !Sub 'LaunchTemplate_${AWS::StackName}'
  48. LaunchTemplateData:
  49. ImageId: !Ref EC2AMI
  50. InstanceType: !Ref EC2InstanceType
  51. KeyName: !Ref KeyName
  52. SecurityGroupIds:
  53. - !GetAtt SecurityGroup.GroupId
  54. BlockDeviceMappings:
  55. - DeviceName: /dev/sda1
  56. Ebs:
  57. VolumeSize: '120'
  58. UserData:
  59. Fn::Base64: !Sub |
  60. #!/bin/bash -xe
  61. # send script output to /tmp so we can debug boot failures
  62. exec > /tmp/userdata.log 2>&1
  63. # Update all packages
  64. apt-get update -y
  65. # Prevent interactive prompts that would interrupt the installation
  66. export DEBIAN_FRONTEND=noninteractive
  67. # Install the updates
  68. apt-get upgrade -y
  69. apt-get install -y apt-transport-https ca-certificates curl gnupg lsb-release
  70. curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
  71. echo "deb [arch=$(dpkg --print-architecture) 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
  72. apt-get update -y
  73. apt-get install -y docker-ce docker-ce-cli containerd.io
  74. usermod -aG docker ubuntu
  75. # Update docker-compose to 1.28+
  76. curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
  77. chmod +x /usr/local/bin/docker-compose
  78. ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
  79. # Get latest cfn scripts and install them;
  80. apt-get install -y python3-setuptools
  81. mkdir -p /opt/aws/bin
  82. wget https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-py3-latest.tar.gz
  83. python3 -m easy_install --script-dir /opt/aws/bin aws-cfn-bootstrap-py3-latest.tar.gz
  84. apt-get install -y python3-pip
  85. /opt/aws/bin/cfn-signal -e $? -r "Instance Created" '${WaitHandle}'
  86. Instance:
  87. Type: AWS::EC2::Instance
  88. Properties:
  89. LaunchTemplate:
  90. LaunchTemplateId: !Ref InstanceLaunchTemplate
  91. Version: !GetAtt InstanceLaunchTemplate.LatestVersionNumber
  92. Tags:
  93. - Key: Name
  94. Value: !Sub '${AWS::StackName}_1'
  95. WaitHandle:
  96. Type: AWS::CloudFormation::WaitConditionHandle
  97. WaitCondition:
  98. Type: AWS::CloudFormation::WaitCondition
  99. Properties:
  100. Handle: !Ref 'WaitHandle'
  101. Timeout: '600'
  102. Count: 1
  103. Outputs:
  104. PublicIp:
  105. Description: The DNS name for the created instance
  106. Value: !Sub '${Instance.PublicIp}'
  107. Export:
  108. Name: !Sub '${AWS::StackName}PublicIp'
  109. InstanceId:
  110. Description: The Instance ID
  111. Value: !Ref Instance