|
| 1 | +{ |
| 2 | + "AWSTemplateFormatVersion" : "2010-09-09", |
| 3 | + |
| 4 | + "Description" : "Creates a single EC2 instance with a pruned Bitcoin Core node, C-Lightning, Lightning Charge, Postgres, Ruby on Rails and Matreon.", |
| 5 | + |
| 6 | + "Parameters" : { |
| 7 | + |
| 8 | + "KeyName": { |
| 9 | + "Description" : "Name of an existing EC2 KeyPair to enable SSH access to the instances", |
| 10 | + "Type": "AWS::EC2::KeyPair::KeyName", |
| 11 | + "ConstraintDescription" : "must be the name of an existing EC2 KeyPair." |
| 12 | + }, |
| 13 | + |
| 14 | + "InstanceType" : { |
| 15 | + "Description" : "WebServer EC2 instance type", |
| 16 | + "Type" : "String", |
| 17 | + "Default" : "t2.small", |
| 18 | + "AllowedValues" : [ "t2.micro", "t2.small", "t2.medium"], |
| 19 | + "ConstraintDescription" : "must be a valid EC2 instance type." |
| 20 | + }, |
| 21 | + |
| 22 | + "SSHLocation" : { |
| 23 | + "Description" : "The IP address range that can be used to SSH to the EC2 instances", |
| 24 | + "Type": "String", |
| 25 | + "MinLength": "9", |
| 26 | + "MaxLength": "18", |
| 27 | + "Default": "0.0.0.0/0", |
| 28 | + "AllowedPattern": "(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})/(\\d{1,2})", |
| 29 | + "ConstraintDescription": "must be a valid IP CIDR range of the form x.x.x.x/x." |
| 30 | + } |
| 31 | + }, |
| 32 | + |
| 33 | + "Mappings" : { |
| 34 | + "AWSInstanceType2Arch" : { |
| 35 | + "t2.micro" : { "Arch" : "HVM64" }, |
| 36 | + "t2.small" : { "Arch" : "HVM64" }, |
| 37 | + "t2.medium" : { "Arch" : "HVM64" } |
| 38 | + }, |
| 39 | + |
| 40 | + "AWSInstanceType2NATArch" : { |
| 41 | + "t2.micro" : { "Arch" : "NATHVM64" }, |
| 42 | + "t2.small" : { "Arch" : "NATHVM64" }, |
| 43 | + "t2.medium" : { "Arch" : "NATHVM64" } |
| 44 | + |
| 45 | + }, |
| 46 | + |
| 47 | + "AWSRegionArch2AMI" : { |
| 48 | + "eu-central-1" : {"HVM64" : "ami-5652ce39"} |
| 49 | + } |
| 50 | + |
| 51 | + }, |
| 52 | + |
| 53 | + "Resources" : { |
| 54 | + |
| 55 | + "WebServer": { |
| 56 | + "Type": "AWS::EC2::Instance", |
| 57 | + "Metadata" : { |
| 58 | + "AWS::CloudFormation::Init" : { |
| 59 | + "configSets" : { |
| 60 | + "full_install" : [ "install_cfn", "install_docker", "install_container_bitcoin", "install_matreon" ] |
| 61 | + }, |
| 62 | + |
| 63 | + "install_cfn" : { |
| 64 | + "files" : { |
| 65 | + "/etc/cfn/cfn-hup.conf" : { |
| 66 | + "content" : { "Fn::Join" : ["", [ |
| 67 | + "[main]\n", |
| 68 | + "stack=", { "Ref" : "AWS::StackId" }, "\n", |
| 69 | + "region=", { "Ref" : "AWS::Region" }, "\n" |
| 70 | + ]]}, |
| 71 | + "mode" : "000400", |
| 72 | + "owner" : "root", |
| 73 | + "group" : "root" |
| 74 | + }, |
| 75 | + |
| 76 | + "/etc/cfn/hooks.d/cfn-auto-reloader.conf" : { |
| 77 | + "content": { "Fn::Join" : ["", [ |
| 78 | + "[cfn-auto-reloader-hook]\n", |
| 79 | + "triggers=post.update\n", |
| 80 | + "path=Resources.WebServer.Metadata.AWS::CloudFormation::Init\n", |
| 81 | + "action=/opt/aws/bin/cfn-init -v ", |
| 82 | + " --stack ", { "Ref" : "AWS::StackName" }, |
| 83 | + " --resource WebServer ", |
| 84 | + " --configsets full_install ", |
| 85 | + " --region ", { "Ref" : "AWS::Region" }, "\n", |
| 86 | + "runas=root\n" |
| 87 | + ]]}, |
| 88 | + "mode" : "000400", |
| 89 | + "owner" : "root", |
| 90 | + "group" : "root" |
| 91 | + } |
| 92 | + }, |
| 93 | + |
| 94 | + "services" : { |
| 95 | + "sysvinit" : { |
| 96 | + "cfn-hup" : { "enabled" : "true", "ensureRunning" : "true", |
| 97 | + "files" : ["/etc/cfn/cfn-hup.conf", "/etc/cfn/hooks.d/cfn-auto-reloader.conf"]} |
| 98 | + } |
| 99 | + } |
| 100 | + }, |
| 101 | + |
| 102 | + "install_docker": { |
| 103 | + "commands": { |
| 104 | + "01_install_docker": { |
| 105 | + "command": "yum install -y docker git && useradd bitcoin && usermod -a -G docker ec2-user && usermod -a -G docker bitcoin > /var/log/install_docker.log" |
| 106 | + }, |
| 107 | + "02_install_docker_compose": { |
| 108 | + "command": {"Fn::Join" : ["", [ |
| 109 | + "sudo curl -L https://github.com/docker/compose/releases/download/1.21.2/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose &&", |
| 110 | + "sudo chmod +x /usr/local/bin/docker-compose ", |
| 111 | + "> /var/log/install_docker.log" |
| 112 | + ]]} |
| 113 | + }, |
| 114 | + "03_start_service": { |
| 115 | + "command": "service docker start > /var/log/install_docker.log" |
| 116 | + } |
| 117 | + } |
| 118 | + }, |
| 119 | + |
| 120 | + "install_container_bitcoin": { |
| 121 | + "commands": { |
| 122 | + "01_configure_datadir": { |
| 123 | + "command": "su - bitcoin -c 'mkdir /home/bitcoin/bitcoin'" |
| 124 | + }, |
| 125 | + "02_clone_repo": { |
| 126 | + "command": "su - bitcoin -c 'git clone https://github.com/NicolasDorier/docker-bitcoin'" |
| 127 | + }, |
| 128 | + "03_docker_build": { |
| 129 | + "command": "su - bitcoin -c 'docker build docker-bitcoin/core/0.16.0 -t bitcoind:0.16.0'" |
| 130 | + } |
| 131 | + } |
| 132 | + }, |
| 133 | + |
| 134 | + "install_matreon": { |
| 135 | + "commands": { |
| 136 | + "01_clone_repo": { |
| 137 | + "command": "su - ec2-user -c 'git clone https://github.com/Sjors/matreon.git && cd matreon && git checkout 2018/05/docker-compose-aws-cloud'" |
| 138 | + }, |
| 139 | + "02_launch": { |
| 140 | + "command": "su - ec2-user -c 'cd matreon && BITCOIN_DATADIR=/home/bitcoin/bitcoin docker-compose up -d'" |
| 141 | + } |
| 142 | + } |
| 143 | + } |
| 144 | + } |
| 145 | + }, |
| 146 | + "Properties": { |
| 147 | + "ImageId" : { "Fn::FindInMap" : [ "AWSRegionArch2AMI", { "Ref" : "AWS::Region" }, |
| 148 | + { "Fn::FindInMap" : [ "AWSInstanceType2Arch", { "Ref" : "InstanceType" }, "Arch" ] } ] }, |
| 149 | + "InstanceType" : { "Ref" : "InstanceType" }, |
| 150 | + "SecurityGroups" : [ {"Ref" : "WebServerSecurityGroup"} ], |
| 151 | + "KeyName" : { "Ref" : "KeyName" }, |
| 152 | + "UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [ |
| 153 | + "#!/bin/bash -xe\n", |
| 154 | + "yum update -y aws-cfn-bootstrap\n", |
| 155 | + |
| 156 | + "/opt/aws/bin/cfn-init -v ", |
| 157 | + " --stack ", { "Ref" : "AWS::StackId" }, |
| 158 | + " --resource WebServer ", |
| 159 | + " --configsets full_install ", |
| 160 | + " --region ", { "Ref" : "AWS::Region" }, "\n", |
| 161 | + |
| 162 | + "/opt/aws/bin/cfn-signal -e $? ", |
| 163 | + " --stack ", { "Ref" : "AWS::StackId" }, |
| 164 | + " --resource WebServer ", |
| 165 | + " --region ", { "Ref" : "AWS::Region" }, "\n" |
| 166 | + ]]}} |
| 167 | + }, |
| 168 | + "CreationPolicy" : { |
| 169 | + "ResourceSignal" : { |
| 170 | + "Timeout" : "PT30M" |
| 171 | + } |
| 172 | + } |
| 173 | + }, |
| 174 | + |
| 175 | + "WebServerSecurityGroup" : { |
| 176 | + "Type" : "AWS::EC2::SecurityGroup", |
| 177 | + "Properties" : { |
| 178 | + "GroupDescription" : "Enable Bitcoin P22 and SSH access", |
| 179 | + "SecurityGroupIngress" : [ |
| 180 | + {"IpProtocol" : "tcp", "FromPort" : "8883", "ToPort" : "8883", "CidrIp" : "0.0.0.0/0"}, |
| 181 | + {"IpProtocol" : "tcp", "FromPort" : "22", "ToPort" : "22", "CidrIp" : { "Ref" : "SSHLocation"}} |
| 182 | + ] |
| 183 | + } |
| 184 | + } |
| 185 | + }, |
| 186 | + |
| 187 | + "Outputs" : { |
| 188 | + "WebsiteURL" : { |
| 189 | + "Value" : { "Fn::Join" : ["", ["http://", { "Fn::GetAtt" : [ "WebServer", "PublicDnsName" ]}, "/" ]] }, |
| 190 | + "Description" : "URL for your Matreon" |
| 191 | + } |
| 192 | + } |
| 193 | +} |
0 commit comments