Skip to content

Commit 1a7886d

Browse files
committed
Docker and AWS CloudFormation support
1 parent bb68b28 commit 1a7886d

File tree

3 files changed

+267
-2
lines changed

3 files changed

+267
-2
lines changed

Matreon.Template

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
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+
}

README.md

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,65 @@ Current status: extremely experimental!
55

66
Live instance: [matreon.sprovoost.nl](https://matreon.sprovoost.nl/)
77

8-
## Prerequisites
8+
## Deploy to AWS using Docker
99

10-
You need to run [c-lightning](https://github.com/ElementsProject/lightning) and [Lightning Charge](https://github.com/ElementsProject/lightning-charge) somewhere.
10+
Coming soon...
11+
12+
Install the Amazon CloudFormation template by downloading [Matreon.Template](https://raw.githubusercontent.com/Sjors/matreon/master/Matreon.Template) and then uploading it on the [CloudFormation stack creation page](https://eu-central-1.console.aws.amazon.com/cloudformation/home?region=eu-central-1&stackName=Matreon#/stacks/new).
13+
14+
You'll need to enter some details:
15+
16+
[SCREENSHOT]
17+
18+
[HINTS]
19+
20+
See the next section for what's happening under the hood.
21+
22+
## Deploy elsewhere using Docker
23+
24+
Install [Docker](https://docs.docker.com/install/).
25+
26+
Work in progress. For now it just launches `bitcoind` and syncs the node.
27+
28+
Create a directory to store the blockchain, wallet info, etc:
29+
30+
```sh
31+
mkdir matreon-vol
32+
mkdir matreon-vol/bitcoin
33+
```
34+
35+
We use Docker Compose to combine a number of containers. To minimize trust, we build these
36+
containers locally.
37+
38+
### Container 1 - bitcoind
39+
40+
```sh
41+
git clone https://github.com/NicolasDorier/docker-bitcoin
42+
docker build docker-bitcoin/core/0.16.0 -t bitcoind:0.16.0
43+
```
44+
45+
### Docker Compose
46+
47+
From the Matreon project directory:
48+
49+
```sh
50+
BITCOIN_DATADIR=~/matreon-vol/bitcoin docker-compose up
51+
```
52+
53+
To shut it down
54+
55+
```
56+
docker-compose down
57+
```
1158

1259
## Deploy to Heroku
1360

61+
### Prerequisites
62+
63+
You need to run [c-lightning](https://github.com/ElementsProject/lightning) and [Lightning Charge](https://github.com/ElementsProject/lightning-charge) somewhere.
64+
65+
### Heroku
66+
1467
Create a new Heroku app `app-name` and add the Sendgrid Add-On.
1568

1669
Clone this repo and:

docker-compose.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
version: "3"
2+
3+
services:
4+
bitcoind:
5+
restart: always
6+
user: bitcoin
7+
image: bitcoind:0.16.0
8+
environment:
9+
BITCOIN_EXTRA_ARGS: |
10+
${NBITCOIN_NETWORK:-testnet}=1
11+
whitelist=0.0.0.0/0
12+
prune=2000
13+
expose:
14+
- "8882"
15+
- "8883"
16+
- "18882"
17+
- "18883"
18+
volumes:
19+
- ${BITCOIN_DATADIR}:/home/bitcoin/.bitcoin

0 commit comments

Comments
 (0)