Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ci improvement #496

Merged
merged 4 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,13 @@ jobs:
run: echo ${{ secrets.DOCKER_PASSWORD }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
- name: Build and Push Docker images
run: |
git_hash=$(git rev-parse --short "$GITHUB_SHA")
docker pull xinfinorg/devnet:latest
docker tag xinfinorg/devnet:latest xinfinorg/devnet:previous
docker rmi xinfinorg/devnet:latest
docker build -t xinfinorg/devnet:latest -f cicd/Dockerfile .
docker tag xinfinorg/devnet:latest xinfinorg/devnet:dev-upgrade-${git_hash}
docker push xinfinorg/devnet:dev-upgrade-${git_hash}
docker push xinfinorg/devnet:latest
docker push xinfinorg/devnet:previous

Expand All @@ -105,9 +108,10 @@ jobs:
- uses: actions/checkout@v4
- name: Terraform Apply
run: |
git_hash=$(git rev-parse --short "$GITHUB_SHA")
cd cicd/devnet/terraform
terraform init ${{ env.tf_init_cli_options }}
terraform apply ${{ env.tf_apply_cli_options }}
terraform apply -var "docker_tag=dev-upgrade-${git_hash}" ${{ env.tf_apply_cli_options }}
sleep 5
source .env
for ((i=$us_east_2_start;i<$us_east_2_end;i++)); do
Expand All @@ -122,7 +126,6 @@ jobs:
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 | head -n 10;
done
aws ecs update-service --region ap-southeast-1 --cluster devnet-xdcnode-cluster --service ecs-service-rpc1 --force-new-deployment --no-cli-pager | head -n 10;

rpcnode_terraform_apply:
runs-on: ubuntu-latest
Expand All @@ -139,6 +142,20 @@ jobs:
terraform init ${{ env.tf_init_cli_options }}
terraform apply ${{ env.tf_apply_cli_options }}

devnet_dev-upgrade_node:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/dev-upgrade' && !startsWith(github.ref, 'refs/tags/')
needs: rpcnode_terraform_apply
environment: devnet
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
steps:
- uses: actions/checkout@v4
- name: ECS Update
run: |
aws ecs update-service --region ap-southeast-1 --cluster devnet-xdcnode-cluster --service ecs-service-rpc1 --force-new-deployment --no-cli-pager | head -n 10;

testnet_dev-upgrade_node:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/dev-upgrade' && !startsWith(github.ref, 'refs/tags/')
Expand Down
2 changes: 1 addition & 1 deletion cicd/devnet/terraform/.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
log_level=3
log_level=2

# Ohio
us_east_2_start=0
Expand Down
23 changes: 3 additions & 20 deletions cicd/devnet/terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module "us-east-2" {
devnetNodeKeys = local.devnetNodeKeys["us-east-2"]
logLevel = local.logLevel
devnet_xdc_ecs_tasks_execution_role_arn = aws_iam_role.devnet_xdc_ecs_tasks_execution_role.arn
docker_tag = var.docker_tag
providers = {
aws = aws.us-east-2
}
Expand All @@ -39,6 +40,7 @@ module "eu-west-1" {
devnetNodeKeys = local.devnetNodeKeys["eu-west-1"]
logLevel = local.logLevel
devnet_xdc_ecs_tasks_execution_role_arn = aws_iam_role.devnet_xdc_ecs_tasks_execution_role.arn
docker_tag = var.docker_tag
providers = {
aws = aws.eu-west-1
}
Expand All @@ -55,27 +57,8 @@ module "ap-southeast-2" {
devnetNodeKeys = local.devnetNodeKeys["ap-southeast-2"]
logLevel = local.logLevel
devnet_xdc_ecs_tasks_execution_role_arn = aws_iam_role.devnet_xdc_ecs_tasks_execution_role.arn
docker_tag = var.docker_tag
providers = {
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
}
}
2 changes: 1 addition & 1 deletion cicd/devnet/terraform/module/region/ecs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ data template_file devnet_container_definition {

vars = {
image_environment = "${lookup(each.value, "imageEnvironment", "devnet")}"
image_tag = "${lookup(each.value, "imageTag", "latest")}"
image_tag = "${lookup(each.value, "imageTag", var.docker_tag)}"
node_name = "${each.key}"
private_key = "${each.value.pk}"
cloudwatch_group = "tf-${each.key}"
Expand Down
8 changes: 7 additions & 1 deletion cicd/devnet/terraform/module/region/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,10 @@ 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
}
}

variable docker_tag {
type = string
default = "latest"
description = "description"
}
6 changes: 3 additions & 3 deletions cicd/devnet/terraform/s3.tf
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Bucket need to be created first. If first time run terraform init, need to comment out the below section
terraform {
backend "s3" {
bucket = "tf-devnet-bucket" // This name need to be updated to be the same as local.s3BucketName. We can't use variable here.
key = "tf/terraform_new.tfstate"
bucket = "tf-xinfin-bucket" // This name need to be updated to be the same as local.s3BucketName. We can't use variable here.
key = "tf/terraform_devnet.tfstate"
region = "us-east-1"
encrypt = true
}
}

data "aws_s3_object" "devnet_xdc_node_config" {
bucket = local.s3BucketName
bucket = "tf-xinfin-bucket"
key = "node-config.json"
}
10 changes: 6 additions & 4 deletions cicd/devnet/terraform/variables.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
variable docker_tag {
type = string
default = "latest"
description = "description"
}

locals {
/**
Load the nodes data from s3
Expand Down Expand Up @@ -39,8 +45,4 @@ locals {
for r in local.regions :
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"
}
19 changes: 19 additions & 0 deletions cicd/terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,25 @@ provider "aws" {
region = "ap-southeast-1"
}

module "devnet-rpc" {
source = "./module/region"
region = "ap-southeast-1"
nodeKeys = local.rpcDevnetNodeKeys
enableFixedIp = true
logLevel = local.logLevel
xdc_ecs_tasks_execution_role_arn = aws_iam_role.xdc_ecs_tasks_execution_role.arn

cpu = 1024
memory = 4096

network = "devnet"
vpc_cidr = "10.0.0.0/16"
subnet_cidr = "10.0.0.0/20"
providers = {
aws = aws.ap-southeast-1
}
}

module "testnet-rpc" {
source = "./module/region"
region = "ap-southeast-1"
Expand Down
2 changes: 1 addition & 1 deletion cicd/terraform/s3.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
terraform {
backend "s3" {
bucket = "tf-xinfin-bucket"
key = "tf/terraform.tfstate"
key = "tf/terraform_rpc.tfstate"
region = "us-east-1"
encrypt = true
}
Expand Down
1 change: 1 addition & 0 deletions cicd/terraform/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ locals {
# r.name => { for i in local.keyNames[r.name]: i => local.predefinedNodesConfig[i] }
# }

rpcDevnetNodeKeys = { "devnet-rpc1": local.predefinedNodesConfig["devnet-rpc1"]} // we hardcode the rpc to a single node for now
rpcTestnetNodeKeys = { "testnet-rpc1": local.predefinedNodesConfig["testnet-rpc1"]} // we hardcode the rpc to a single node for now
rpcMainnetNodeKeys = { "mainnet-rpc1": local.predefinedNodesConfig["mainnet-rpc1"]} // we hardcode the rpc to a single node for now
}