mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-18 02:40:45 +00:00
Host rpc node in ecs (#391)
This commit is contained in:
parent
32254671f5
commit
d24f187bfd
9 changed files with 150 additions and 9 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -52,4 +52,5 @@ coverage.txt
|
||||||
go.sum
|
go.sum
|
||||||
cicd/devnet/terraform/.terraform*
|
cicd/devnet/terraform/.terraform*
|
||||||
cicd/devnet/tmp
|
cicd/devnet/tmp
|
||||||
.env
|
.env
|
||||||
|
cicd/devnet/terraform/node-config.json
|
||||||
|
|
@ -171,6 +171,7 @@ jobs:
|
||||||
echo "Force deploy xdc-$i"
|
echo "Force deploy xdc-$i"
|
||||||
aws ecs update-service --region ap-southeast-2 --cluster devnet-xdcnode-cluster --service ecs-service-xdc$i --force-new-deployment --no-cli-pager;
|
aws ecs update-service --region ap-southeast-2 --cluster devnet-xdcnode-cluster --service ecs-service-xdc$i --force-new-deployment --no-cli-pager;
|
||||||
done
|
done
|
||||||
|
aws ecs update-service --region ap-southeast-1 --cluster devnet-xdcnode-cluster --service ecs-service-rpc1 --force-new-deployment --no-cli-pager;
|
||||||
|
|
||||||
- stage: (Devnet) Send Deployment Notification
|
- stage: (Devnet) Send Deployment Notification
|
||||||
if: branch = dev-upgrade AND type = push AND tag IS blank
|
if: branch = dev-upgrade AND type = push AND tag IS blank
|
||||||
|
|
|
||||||
|
|
@ -10,4 +10,4 @@ eu_west_1_end=72
|
||||||
|
|
||||||
# Sydney
|
# Sydney
|
||||||
ap_southeast_2_start=73
|
ap_southeast_2_start=73
|
||||||
ap_southeast_2_end=110
|
ap_southeast_2_end=108
|
||||||
|
|
@ -23,7 +23,6 @@ module "us-east-2" {
|
||||||
devnetNodeKeys = local.devnetNodeKeys["us-east-2"]
|
devnetNodeKeys = local.devnetNodeKeys["us-east-2"]
|
||||||
logLevel = local.logLevel
|
logLevel = local.logLevel
|
||||||
devnet_xdc_ecs_tasks_execution_role_arn = aws_iam_role.devnet_xdc_ecs_tasks_execution_role.arn
|
devnet_xdc_ecs_tasks_execution_role_arn = aws_iam_role.devnet_xdc_ecs_tasks_execution_role.arn
|
||||||
|
|
||||||
providers = {
|
providers = {
|
||||||
aws = aws.us-east-2
|
aws = aws.us-east-2
|
||||||
}
|
}
|
||||||
|
|
@ -40,7 +39,6 @@ module "eu-west-1" {
|
||||||
devnetNodeKeys = local.devnetNodeKeys["eu-west-1"]
|
devnetNodeKeys = local.devnetNodeKeys["eu-west-1"]
|
||||||
logLevel = local.logLevel
|
logLevel = local.logLevel
|
||||||
devnet_xdc_ecs_tasks_execution_role_arn = aws_iam_role.devnet_xdc_ecs_tasks_execution_role.arn
|
devnet_xdc_ecs_tasks_execution_role_arn = aws_iam_role.devnet_xdc_ecs_tasks_execution_role.arn
|
||||||
|
|
||||||
providers = {
|
providers = {
|
||||||
aws = aws.eu-west-1
|
aws = aws.eu-west-1
|
||||||
}
|
}
|
||||||
|
|
@ -57,8 +55,27 @@ module "ap-southeast-2" {
|
||||||
devnetNodeKeys = local.devnetNodeKeys["ap-southeast-2"]
|
devnetNodeKeys = local.devnetNodeKeys["ap-southeast-2"]
|
||||||
logLevel = local.logLevel
|
logLevel = local.logLevel
|
||||||
devnet_xdc_ecs_tasks_execution_role_arn = aws_iam_role.devnet_xdc_ecs_tasks_execution_role.arn
|
devnet_xdc_ecs_tasks_execution_role_arn = aws_iam_role.devnet_xdc_ecs_tasks_execution_role.arn
|
||||||
|
|
||||||
providers = {
|
providers = {
|
||||||
aws = aws.ap-southeast-2
|
aws = aws.ap-southeast-2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# WARNING: APSE-1 will only be used to host rpc node
|
||||||
|
# Workaround to avoid conflicts with existing ecs cluster in existing regions
|
||||||
|
provider "aws" {
|
||||||
|
alias = "ap-southeast-1"
|
||||||
|
region = "ap-southeast-1"
|
||||||
|
}
|
||||||
|
|
||||||
|
module "ap-southeast-1-rpc" {
|
||||||
|
source = "./module/region"
|
||||||
|
region = "ap-southeast-1"
|
||||||
|
devnetNodeKeys = local.rpcNodeKeys
|
||||||
|
enableFixedIp = true
|
||||||
|
logLevel = local.logLevel
|
||||||
|
devnet_xdc_ecs_tasks_execution_role_arn = aws_iam_role.devnet_xdc_ecs_tasks_execution_role.arn
|
||||||
|
|
||||||
|
providers = {
|
||||||
|
aws = aws.ap-southeast-1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -56,15 +56,17 @@ data "aws_ecs_task_definition" "devnet_ecs_task_definition" {
|
||||||
task_definition = aws_ecs_task_definition.devnet_task_definition_group[each.key].family
|
task_definition = aws_ecs_task_definition.devnet_task_definition_group[each.key].family
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# ECS cluster
|
||||||
resource "aws_ecs_cluster" "devnet_ecs_cluster" {
|
resource "aws_ecs_cluster" "devnet_ecs_cluster" {
|
||||||
name = "devnet-xdcnode-cluster"
|
name = "devnet-xdcnode-cluster"
|
||||||
tags = {
|
tags = {
|
||||||
Name = "TfDevnetEcsCluster"
|
Name = "TfDevnetEcsCluster"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
resource "aws_ecs_service" "devnet_ecs_service" {
|
resource "aws_ecs_service" "devnet_ecs_service" {
|
||||||
for_each = var.devnetNodeKeys
|
for_each = var.enableFixedIp ? {} : var.devnetNodeKeys
|
||||||
name = "ecs-service-${each.key}"
|
name = "ecs-service-${each.key}"
|
||||||
cluster = aws_ecs_cluster.devnet_ecs_cluster.id
|
cluster = aws_ecs_cluster.devnet_ecs_cluster.id
|
||||||
task_definition = "${aws_ecs_task_definition.devnet_task_definition_group[each.key].family}:${max(aws_ecs_task_definition.devnet_task_definition_group[each.key].revision, data.aws_ecs_task_definition.devnet_ecs_task_definition[each.key].revision)}"
|
task_definition = "${aws_ecs_task_definition.devnet_task_definition_group[each.key].family}:${max(aws_ecs_task_definition.devnet_task_definition_group[each.key].revision, data.aws_ecs_task_definition.devnet_ecs_task_definition[each.key].revision)}"
|
||||||
|
|
|
||||||
|
|
@ -72,6 +72,14 @@ resource "aws_default_security_group" "devnet_xdcnode_security_group" {
|
||||||
cidr_blocks = ["0.0.0.0/0"]
|
cidr_blocks = ["0.0.0.0/0"]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ingress {
|
||||||
|
description = "rpc port"
|
||||||
|
from_port = 8545
|
||||||
|
to_port = 8545
|
||||||
|
protocol = "tcp"
|
||||||
|
cidr_blocks = ["10.0.0.0/16"]
|
||||||
|
}
|
||||||
|
|
||||||
egress {
|
egress {
|
||||||
from_port = 0
|
from_port = 0
|
||||||
to_port = 0
|
to_port = 0
|
||||||
|
|
|
||||||
104
cicd/devnet/terraform/module/region/rpc.tf
Normal file
104
cicd/devnet/terraform/module/region/rpc.tf
Normal file
|
|
@ -0,0 +1,104 @@
|
||||||
|
# Allocate an Elastic IP for the NLB
|
||||||
|
resource "aws_eip" "nlb_eip" {
|
||||||
|
domain = "vpc"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# Create a Network Load Balancer
|
||||||
|
resource "aws_lb" "rpc_node_nlb" {
|
||||||
|
count = var.enableFixedIp ? 1 : 0
|
||||||
|
name = "rpc-node-nlb"
|
||||||
|
load_balancer_type = "network"
|
||||||
|
|
||||||
|
enable_deletion_protection = false
|
||||||
|
|
||||||
|
subnet_mapping {
|
||||||
|
subnet_id = aws_subnet.devnet_subnet.id
|
||||||
|
allocation_id = aws_eip.nlb_eip.id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Listener and Target Group for the rpc node container
|
||||||
|
resource "aws_lb_target_group" "rpc_node_tg_8545" {
|
||||||
|
count = var.enableFixedIp ? 1 : 0
|
||||||
|
name = "rpc-node-tg"
|
||||||
|
port = 8545
|
||||||
|
protocol = "TCP"
|
||||||
|
vpc_id = aws_vpc.devnet_vpc.id
|
||||||
|
target_type = "ip"
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "aws_lb_listener" "rpc_node_listener_8545" {
|
||||||
|
count = var.enableFixedIp ? 1 : 0
|
||||||
|
load_balancer_arn = aws_lb.rpc_node_nlb[0].arn
|
||||||
|
port = 8545
|
||||||
|
protocol = "TCP"
|
||||||
|
|
||||||
|
default_action {
|
||||||
|
type = "forward"
|
||||||
|
target_group_arn = aws_lb_target_group.rpc_node_tg_8545[0].arn
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "aws_ecs_service" "devnet_rpc_node_ecs_service" {
|
||||||
|
for_each = var.enableFixedIp ? var.devnetNodeKeys : {}
|
||||||
|
name = "ecs-service-${each.key}"
|
||||||
|
cluster = aws_ecs_cluster.devnet_ecs_cluster.id
|
||||||
|
task_definition = "${aws_ecs_task_definition.devnet_task_definition_group[each.key].family}:${max(aws_ecs_task_definition.devnet_task_definition_group[each.key].revision, data.aws_ecs_task_definition.devnet_ecs_task_definition[each.key].revision)}"
|
||||||
|
launch_type = "FARGATE"
|
||||||
|
scheduling_strategy = "REPLICA"
|
||||||
|
desired_count = 1
|
||||||
|
force_new_deployment = true
|
||||||
|
deployment_minimum_healthy_percent = 0
|
||||||
|
deployment_maximum_percent = 100
|
||||||
|
|
||||||
|
network_configuration {
|
||||||
|
subnets = [aws_subnet.devnet_subnet.id]
|
||||||
|
assign_public_ip = true
|
||||||
|
security_groups = [
|
||||||
|
aws_default_security_group.devnet_xdcnode_security_group.id
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
deployment_circuit_breaker {
|
||||||
|
enable = true
|
||||||
|
rollback = false
|
||||||
|
}
|
||||||
|
|
||||||
|
load_balancer {
|
||||||
|
target_group_arn = aws_lb_target_group.rpc_node_tg_8545[0].arn
|
||||||
|
container_name = "tfXdcNode"
|
||||||
|
container_port = 8545
|
||||||
|
}
|
||||||
|
|
||||||
|
depends_on = [
|
||||||
|
aws_lb_listener.rpc_node_listener_8545
|
||||||
|
]
|
||||||
|
|
||||||
|
tags = {
|
||||||
|
Name = "TfDevnetRpcNodeEcsService-${each.key}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Target Group for port 30303
|
||||||
|
resource "aws_lb_target_group" "rpc_node_tg_30303" {
|
||||||
|
count = var.enableFixedIp ? 1 : 0
|
||||||
|
name = "rpc-node-tg-30303"
|
||||||
|
port = 30303
|
||||||
|
protocol = "TCP"
|
||||||
|
vpc_id = aws_vpc.devnet_vpc.id
|
||||||
|
target_type = "ip"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Listener for port 30303
|
||||||
|
resource "aws_lb_listener" "rpc_node_listener_30303" {
|
||||||
|
count = var.enableFixedIp ? 1 : 0
|
||||||
|
load_balancer_arn = aws_lb.rpc_node_nlb[0].arn
|
||||||
|
port = 30303
|
||||||
|
protocol = "TCP"
|
||||||
|
|
||||||
|
default_action {
|
||||||
|
type = "forward"
|
||||||
|
target_group_arn = aws_lb_target_group.rpc_node_tg_30303[0].arn
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -16,4 +16,10 @@ variable "logLevel" {
|
||||||
variable "devnet_xdc_ecs_tasks_execution_role_arn" {
|
variable "devnet_xdc_ecs_tasks_execution_role_arn" {
|
||||||
description = "aws iam role resource arn"
|
description = "aws iam role resource arn"
|
||||||
type = string
|
type = string
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "enableFixedIp" {
|
||||||
|
description = "a flag to indicate whether fixed ip should be associated to the nodes. This is used for RPC node"
|
||||||
|
type = bool
|
||||||
|
default = false
|
||||||
}
|
}
|
||||||
|
|
@ -5,7 +5,7 @@ locals {
|
||||||
{{Name of the node, in a pattern of 'xdc'+ number. i.e xdc50}}: {
|
{{Name of the node, in a pattern of 'xdc'+ number. i.e xdc50}}: {
|
||||||
pk: {{Value of the node private key}},
|
pk: {{Value of the node private key}},
|
||||||
... any other configuration we want to pass.
|
... any other configuration we want to pass.
|
||||||
}
|
}
|
||||||
Note: No `n` is allowed in the node name
|
Note: No `n` is allowed in the node name
|
||||||
**/
|
**/
|
||||||
predefinedNodesConfig = jsondecode(data.aws_s3_object.devnet_xdc_node_config.body)
|
predefinedNodesConfig = jsondecode(data.aws_s3_object.devnet_xdc_node_config.body)
|
||||||
|
|
@ -39,6 +39,8 @@ locals {
|
||||||
for r in local.regions :
|
for r in local.regions :
|
||||||
r.name => { for i in local.keyNames[r.name]: i => local.predefinedNodesConfig[i] }
|
r.name => { for i in local.keyNames[r.name]: i => local.predefinedNodesConfig[i] }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rpcNodeKeys = { "rpc1": local.predefinedNodesConfig["rpc1"]} // we hardcode the rpc to a single node for now
|
||||||
|
|
||||||
s3BucketName = "tf-devnet-bucket"
|
s3BucketName = "tf-devnet-bucket"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue