Skip to content

Commit

Permalink
Merge pull request ethereum#312 from XinFinOrg/dev-upgrade
Browse files Browse the repository at this point in the history
CI Upgrade
  • Loading branch information
liam-lai authored Aug 25, 2023
2 parents c87218a + f6b50b8 commit a05b3da
Show file tree
Hide file tree
Showing 28 changed files with 775 additions and 196 deletions.
14 changes: 9 additions & 5 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ Describe the big picture of your changes here to communicate to the maintainers
What types of changes does your code introduce to XDC network?
_Put an `` in the boxes that apply_

- [ ] Bugfix
- [ ] New feature
- [ ] Documentation Update or any other KTLO
- [ ] Not sure (Please specify below)
- [ ] Bugfix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] Documentation Update (if none of the other choices apply)
- [ ] Regular KTLO or any of the maintaince work. e.g code style
- [ ] CICD Improvement

## Impacted Components
Which part of the codebase this PR will touch base on,
Expand All @@ -30,4 +32,6 @@ _Put an `✅` in the boxes once you have confirmed below actions (or provide rea
- [ ] This PR has sufficient test coverage (unit/integration test) OR I have provided reason in the PR description for not having test coverage
- [ ] Provide an end-to-end test plan in the PR description on how to manually test it on the devnet/testnet.
- [ ] Tested the backwards compatibility.
- [ ] Relevant documentation has been updated as part of this PR
- [ ] Tested with XDC nodes running this version co-exist with those running the previous version.
- [ ] Relevant documentation has been updated as part of this PR
- [ ] N/A
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@ profile.cov
**/yarn-error.log
coverage.txt
go.sum
cicd/devnet/terraform/.terraform
cicd/devnet/terraform/.terraform*
cicd/devnet/tmp
67 changes: 41 additions & 26 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
sudo: required
language: go
go_import_path: github.com/XinFinOrg/XDPoSChain
branches:
only:
- master
- dev-upgrade

on:
branches:
- master
- dev-upgrade
tags: true

env:
global:
Expand Down Expand Up @@ -88,9 +90,33 @@ jobs:
env:
- GO111MODULE=auto
name: T-Z tests


- stage: TAG Build
if: tag IS present
services:
- docker
install: skip
before_script:
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
- docker --version # document the version travis is using
- docker build -t xinfinorg/xdposchain:$TRAVIS_TAG -f cicd/Dockerfile .
script:
- docker push xinfinorg/xdposchain:$TRAVIS_TAG

- stage: (Devnet) Build, and push images
if: branch = dev-upgrade AND type = push AND tag IS blank
services:
- docker
install: skip
before_script:
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
- docker --version # document the version travis is using
- docker build -t xinfinorg/devnet:latest -f cicd/Dockerfile .
script:
- docker push xinfinorg/devnet:latest

- stage: (Devnet)Terraform plan
if: branch = dev-upgrade AND type = pull_request
if: branch = dev-upgrade AND type = push AND tag IS blank
dist: xenial
language: bash
install:
Expand All @@ -105,21 +131,8 @@ jobs:
- terraform init $tf_init_cli_options
- terraform validate $tf_validation_cli_options
- terraform plan $tf_plan_cli_options

- stage: (Devnet) Build, and push images
if: branch = dev-upgrade AND type = push AND tag IS blank
services:
- docker
install: skip
before_script:
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
- docker --version # document the version travis is using
- docker build -t xdc-devnet -f cicd/devnet/Dockerfile .
script:
- docker tag xdc-devnet:latest xinfinorg/devnet:latest # Always push to the latest
- docker push xinfinorg/devnet:latest

- stage: Terraform apply
- stage: (Devnet) Terraform apply
if: branch = dev-upgrade AND type = push AND tag IS blank
dist: xenial
language: bash
Expand All @@ -129,27 +142,29 @@ jobs:
- unzip terraform_"$tf_version"_linux_amd64.zip
- sudo mv terraform /usr/local/bin/
- rm terraform_"$tf_version"_linux_amd64.zip
- pip install --user awscli # install aws cli w/o sudo
- curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
- unzip awscliv2.zip
- sudo ./aws/install
- export PATH=$PATH:$HOME/.local/bin # put aws in the path
script:
- echo "Merge detected, executing changes(Devnet)"
- cd cicd/devnet/terraform
# Terraform init and then apply changes to environment
- terraform init $tf_init_cli_options
- terraform apply $tf_apply_cli_options
- sleep 20
- sleep 5
- |
source .env
for ((i=$us_east_2_start;i<$us_east_2_end;i++)); do
echo "Force deploy xdc-$i"
sleep 5 && aws ecs update-service --region us-east-2 --cluster devnet-xdcnode-cluster --service ecs-service-xdc$i --force-new-deployment;
aws ecs update-service --region us-east-2 --cluster devnet-xdcnode-cluster --service ecs-service-xdc$i --force-new-deployment --no-cli-pager;
done
for ((i=$eu_west_1_start;i<$eu_west_1_end;i++)); do
echo "Force deploy xdc-$i"
sleep 5 && aws ecs update-service --region eu-west-1 --cluster devnet-xdcnode-cluster --service ecs-service-xdc$i --force-new-deployment;
aws ecs update-service --region eu-west-1 --cluster devnet-xdcnode-cluster --service ecs-service-xdc$i --force-new-deployment --no-cli-pager;
done
for ((i=$ap_southeast_2_start;i<$ap_southeast_2_end;i++)); do
echo "Force deploy xdc-$i"
sleep 5 && aws ecs update-service --region ap-southeast-2 --cluster devnet-xdcnode-cluster --service ecs-service-xdc$i --force-new-deployment;
aws ecs update-service --region ap-southeast-2 --cluster devnet-xdcnode-cluster --service ecs-service-xdc$i --force-new-deployment --no-cli-pager;
done
1 change: 1 addition & 0 deletions cicd/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Dockerfile
41 changes: 41 additions & 0 deletions cicd/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
FROM golang:1.14-alpine as builder

RUN apk add make build-base linux-headers

COPY . /builder
RUN cd /builder && make && mv /builder/build/bin/XDC /builder/build/bin/XDC-mainnet

RUN mv /builder/common/constants/constants.go.devnet /builder/common/constants.go
RUN cd /builder && make && mv /builder/build/bin/XDC /builder/build/bin/XDC-devnet

RUN mv /builder/common/constants/constants.go.testnet /builder/common/constants.go
RUN cd /builder && make && mv /builder/build/bin/XDC /builder/build/bin/XDC-testnet

# The runtime image
FROM alpine:3

WORKDIR /work

RUN apk add --no-cache bash curl

COPY --from=builder /builder/build/bin/XDC-devnet /usr/bin
COPY --from=builder /builder/build/bin/XDC-testnet /usr/bin
COPY --from=builder /builder/build/bin/XDC-mainnet /usr/bin

# # Copy over files
ADD cicd/devnet /work/devnet
ADD cicd/testnet /work/testnet
ADD cicd/mainnet /work/mainnet
ADD cicd/entry.sh /work/

# Create an empty pwd file
RUN touch /work/.pwd

# rpc
EXPOSE 8545
# ws
EXPOSE 8555
# port
EXPOSE 30303

ENTRYPOINT ["bash","/work/entry.sh"]
56 changes: 7 additions & 49 deletions cicd/README.md
Original file line number Diff line number Diff line change
@@ -1,52 +1,10 @@
# CI/CD pipeline for XDC
This directory contains CI/CD scripts used for each of the XDC environments.
# Docker Command

## How to deploy more nodes
Adjust the number of variable `num_of_nodes` under file `.env`. (**Maximum supported is 58**)

## Devnet
Each PR merged into `dev-upgrade` will trigger below actions:
- Tests
- Terraform to apply infrascture changes(if any)
- Docker build of XDC with devnet configurations with tag of `:latest`
- Docker push to docker hub. https://hub.docker.com/repository/docker/xinfinorg/devnet
- Deployment of the latest XDC image(from above) to devnet run by AWS ECS

### First time set up an new environment
1. Pre-generate a list of node private keys in below format
## Docker Build
```
{
"xdc0": {
"pk": {{PRIVATE KEY}},
"address": {{XDC wallet address}},
"imageTag": {{Optional field to run different version of XDC}},
"logLevel": {{Optional field to adjust the log level for the container}}
},
"xdc1": {...},
"xdc{{NUMBER}}: {...}
}
docker build -f cicd/Dockerfile .
```
2. Access to aws console, create a bucket with name `tf-devnet-bucket`:
- You can choose any name, just make sure update the name in the s3 bucket name variable in `variables.tf`
- And update the name of the terraform.backend.s3.bucket from `s3.tf`
3. Upload the file from step 1 into the above bucket with name `node-config.json`
4. In order to allow pipeline able to push and deploy via ECR and ECS, we require below environment variables to be injected into the CI pipeline:
1. DOCKER_USERNAME
2. DOCKER_PASSWORD
3. AWS_ACCESS_KEY_ID
4. AWS_SECRET_ACCESS_KEY

You are all set!

## How to run different version of XDC on selected nodes
1. Create a new image tag:
- Check out the repo
- Run docker build `docker build -t xdc-devnet -f cicd/devnet/Dockerfile .`
- Run docker tag `docker tag xdc-devnet:latest xinfinorg/devnet:test-{{put your version number here}}`
- Run docker push `docker push xinfinorg/devnet:test-{{Version number from step above}}`
2. Adjust node-config.json
- Download the node-config.json from s3
- Add/update the `imageTag` field with value of `test-{{version number you defined in step 1}}` for the selected number of nodes you want to test with
- Optional: Adjust the log level by add/updating the field of `logLevel`
- Save and upload to s3
3. Make a dummy PR and get merged. Wait it to be updated.
## Docker Run
```
docker run -it -e NETWORK=devnet -e PRIVATE_KEYS=$KEY $IMAGE
``
36 changes: 0 additions & 36 deletions cicd/devnet/Dockerfile

This file was deleted.

52 changes: 52 additions & 0 deletions cicd/devnet/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# CI/CD pipeline for XDC
This directory contains CI/CD scripts used for each of the XDC environments.

## How to deploy more nodes
Adjust the number of variable `num_of_nodes` under file `.env`. (**Maximum supported is 58**)

## Devnet
Each PR merged into `dev-upgrade` will trigger below actions:
- Tests
- Terraform to apply infrascture changes(if any)
- Docker build of XDC with devnet configurations with tag of `:latest`
- Docker push to docker hub. https://hub.docker.com/repository/docker/xinfinorg/devnet
- Deployment of the latest XDC image(from above) to devnet run by AWS ECS

### First time set up an new environment
1. Pre-generate a list of node private keys in below format
```
{
"xdc0": {
"pk": {{PRIVATE KEY}},
"address": {{XDC wallet address}},
"imageTag": {{Optional field to run different version of XDC}},
"logLevel": {{Optional field to adjust the log level for the container}}
},
"xdc1": {...},
"xdc{{NUMBER}}: {...}
}
```
2. Access to aws console, create a bucket with name `tf-devnet-bucket`:
- You can choose any name, just make sure update the name in the s3 bucket name variable in `variables.tf`
- And update the name of the terraform.backend.s3.bucket from `s3.tf`
3. Upload the file from step 1 into the above bucket with name `node-config.json`
4. In order to allow pipeline able to push and deploy via ECR and ECS, we require below environment variables to be injected into the CI pipeline:
1. DOCKER_USERNAME
2. DOCKER_PASSWORD
3. AWS_ACCESS_KEY_ID
4. AWS_SECRET_ACCESS_KEY

You are all set!

## How to run different version of XDC on selected nodes
1. Create a new image tag:
- Check out the repo
- Run docker build `docker build -t xdc-devnet -f cicd/devnet/Dockerfile .`
- Run docker tag `docker tag xdc-devnet:latest xinfinorg/devnet:test-{{put your version number here}}`
- Run docker push `docker push xinfinorg/devnet:test-{{Version number from step above}}`
2. Adjust node-config.json
- Download the node-config.json from s3
- Add/update the `imageTag` field with value of `test-{{version number you defined in step 1}}` for the selected number of nodes you want to test with
- Optional: Adjust the log level by add/updating the field of `logLevel`
- Save and upload to s3
3. Make a dummy PR and get merged. Wait it to be updated.
4 changes: 2 additions & 2 deletions cicd/devnet/start-local-devnet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ then

echo "${private_key}" >> ./tmp/key
echo "Creating a new wallet"
wallet=$(../../build/bin/XDC account import --password ./tmp/.pwd --datadir ./tmp/xdcchain ./tmp/key | awk -v FS="({|})" '{print $2}')
wallet=$(../../build/bin/XDC account import --password ./tmp/.pwd --datadir ./tmp/xdcchain ./tmp/key | sed -n 's/Address: {\(.*\)}/\1/p')
../../build/bin/XDC --datadir ./tmp/xdcchain init ./genesis.json
else
echo "Wallet already exist, re-use the same one. If you have changed the private key, please manually inspect the key if matches. Otherwise, delete the 'tmp' directory and start again!"
wallet=$(../../build/bin/XDC account list --datadir ./tmp/xdcchain | head -n 1 | awk -v FS="({|})" '{print $2}')
wallet=$(../../build/bin/XDC account list --datadir ./tmp/xdcchain | head -n 1 | sed -n 's/Address: {\(.*\)}/\1/p')
fi

input="./bootnodes.list"
Expand Down
Loading

0 comments on commit a05b3da

Please sign in to comment.