Skip to content

Commit 57e092c

Browse files
author
Simon Goldberg
committed
implement .env and remove local packages
1 parent 689e531 commit 57e092c

File tree

10 files changed

+1222
-2837
lines changed

10 files changed

+1222
-2837
lines changed

lib/bitcoin-core/.env

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
INSTANCE_CLASS=T3A
2+
INSTANCE_SIZE=LARGE
3+
EBS_VOLUME_SIZE=1000
4+
EBS_VOLUME_TYPE=GP3
5+
6+
ASG_MIN_CAPACITY=2
7+
ASG_MAX_CAPACITY=4
8+
ASG_DESIRED_CAPACITY=2

lib/bitcoin-core/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ npx cdk deploy HABitcoinCoreNodeStack
5858

5959
#### Single Node Setup
6060

61-
- A **Bitcoin node** deployed in a **public subnet** continuously synchronizes with the Bitcoin network using outbound connections through a **NAT Gateway**.
61+
- A **Bitcoin node** deployed in a **private subnet** continuously synchronizes with the Bitcoin network using outbound connections through a **NAT Gateway**.
6262
- Outbound communication flows through an **Internet Gateway (IGW)**, but the node itself does not have a **public IP address** or **Elastic IP (EIP)**.
6363
- The **NAT Gateway** translates the node's private IP into a public IP for outbound connections, but inbound connections are blocked. This ensures that the node functions as an **outbound-only node** (i.e., it does not accept inbound peer connections), increasing security and reducing data transfer costs.
6464

lib/bitcoin-core/generateRPCAuth.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function genRpcAuth(username = genUser(), password = genPass(), salt = genSalt()
3636
}
3737

3838
function writeRpcAuthToConf(rpcauthStr) {
39-
const confPath = 'lib/bitcoin.conf';
39+
const confPath = 'lib/bitcoin-core/lib/bitcoin.conf';
4040
try {
4141
fs.writeFileSync(confPath, rpcauthStr + '\n', { flag: 'a' });
4242
console.log(`Successfully wrote to ${confPath}`);

lib/bitcoin-core/lib/bitcoin.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ server=1
22
rpcallowip=0.0.0.0/0
33
txindex=1
44
rpcbind=0.0.0.0:8332
5-
datadir=/home/bitcoin/.bitcoin
5+
datadir=/home/bitcoin/.bitcoin

lib/bitcoin-core/lib/ha-node-stack.js

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,19 @@ const path = require('path');
77
const fs = require('fs');
88
const { AwsSolutionsChecks, NagSuppressions } = require('cdk-nag');
99
const { Aspects } = require('aws-cdk-lib');
10+
require('dotenv').config();
11+
12+
//Parse env variables
13+
const {
14+
INSTANCE_CLASS,
15+
INSTANCE_SIZE,
16+
EBS_VOLUME_SIZE,
17+
EBS_VOLUME_TYPE,
18+
ASG_MIN_CAPACITY,
19+
ASG_MAX_CAPACITY,
20+
ASG_DESIRED_CAPACITY
21+
} = process.env;
22+
1023

1124
class HABitcoinCoreNodeStack extends cdk.Stack {
1225
constructor(scope, id, props) {
@@ -93,15 +106,18 @@ class HABitcoinCoreNodeStack extends cdk.Stack {
93106

94107
// Create Launch Template
95108
const launchTemplate = new ec2.LaunchTemplate(this, 'BitcoinLaunchTemplate', {
96-
instanceType: ec2.InstanceType.of(ec2.InstanceClass.T3A, ec2.InstanceSize.LARGE),
109+
instanceType: ec2.InstanceType.of(
110+
ec2.InstanceClass[INSTANCE_CLASS],
111+
ec2.InstanceSize[INSTANCE_SIZE]
112+
),
97113
machineImage: ec2.MachineImage.latestAmazonLinux2(),
98114
userData,
99115
role,
100116
securityGroup: ec2Sg,
101117
blockDevices: [{
102118
deviceName: '/dev/xvda',
103-
volume: ec2.BlockDeviceVolume.ebs(1000, {
104-
volumeType: ec2.EbsDeviceVolumeType.GP3,
119+
volume: ec2.BlockDeviceVolume.ebs(Number(EBS_VOLUME_SIZE), {
120+
volumeType: ec2.EbsDeviceVolumeType[EBS_VOLUME_TYPE],
105121
encrypted: true,
106122
}),
107123
}],
@@ -111,9 +127,9 @@ class HABitcoinCoreNodeStack extends cdk.Stack {
111127
const asg = new autoscaling.AutoScalingGroup(this, 'BitcoinASG', {
112128
vpc,
113129
launchTemplate: launchTemplate,
114-
minCapacity: 2,
115-
maxCapacity: 4,
116-
desiredCapacity: 2,
130+
minCapacity: Number(ASG_MIN_CAPACITY),
131+
maxCapacity: Number(ASG_MAX_CAPACITY),
132+
desiredCapacity: Number(ASG_DESIRED_CAPACITY),
117133
});
118134

119135
// Attach the ASG to the Target Group

lib/bitcoin-core/lib/single-node-stack.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,15 @@ const path = require('path');
66
const fs = require('fs');
77
const { AwsSolutionsChecks, NagSuppressions } = require('cdk-nag');
88
const { Aspects } = require('aws-cdk-lib');
9+
require('dotenv').config();
910

11+
//Parse env variables
12+
const {
13+
INSTANCE_CLASS,
14+
INSTANCE_SIZE,
15+
EBS_VOLUME_SIZE,
16+
EBS_VOLUME_TYPE,
17+
} = process.env;
1018

1119
class SingleNodeBitcoinCoreStack extends cdk.Stack {
1220
constructor(scope, id, props) {
@@ -60,14 +68,17 @@ class SingleNodeBitcoinCoreStack extends cdk.Stack {
6068
// EC2 Instance
6169
const instance = new ec2.Instance(this, 'BitcoinSingleNode', {
6270
vpc,
63-
instanceType: ec2.InstanceType.of(ec2.InstanceClass.T3A, ec2.InstanceSize.LARGE),
71+
instanceType: ec2.InstanceType.of(
72+
ec2.InstanceClass[INSTANCE_CLASS],
73+
ec2.InstanceSize[INSTANCE_SIZE]
74+
),
6475
machineImage: ec2.MachineImage.latestAmazonLinux2(),
6576
role,
6677
securityGroup: sg,
6778
blockDevices: [{
6879
deviceName: '/dev/xvda',
69-
volume: ec2.BlockDeviceVolume.ebs(1000, {
70-
volumeType: ec2.EbsDeviceVolumeType.GP3,
80+
volume: ec2.BlockDeviceVolume.ebs(Number(EBS_VOLUME_SIZE), {
81+
volumeType: ec2.EbsDeviceVolumeType[EBS_VOLUME_TYPE],
7182
encrypted: true,
7283
}),
7384
}],

0 commit comments

Comments
 (0)