CI CD pieple to publish devnet image to AWS ECR

This commit is contained in:
Jianrong 2022-09-03 18:40:54 +08:00
parent 94781c741d
commit 1921fe103c
6 changed files with 250 additions and 61 deletions

View file

@ -83,69 +83,18 @@ jobs:
env:
- GO111MODULE=auto
name: T-Z tests
- stage: Github release
go: '1.14.x'
script:
- GOARCH=amd64 GOOS=linux go build -o ./build/bin/XDC-linux-amd64 ./cmd/XDC
deploy:
provider: releases
api_key: $GITHUB_TOKEN
overwrite: true
file_glob: true
file: build/bin/XDC-*
skip_cleanup: true
on:
tags: true
- stage: Build and push image
- stage: (Devnet) Build and push image
if: branch = dev-upgrade
services:
- docker
install: skip
before_script:
- docker build -t XinFinOrg/XDPoSChain .
- docker build -t XinFinOrg/node -f Dockerfile.node .
- docker --version # document the version travis is using
- docker build -t xdc-devnet -f cicd/devnet/Dockerfile .
script:
- echo "$DOCKER_PASSWORD" | docker login --username "$DOCKER_USERNAME" --password-stdin
- docker tag XinFinOrg/XDPoSChain XinFinOrg/XDPoSChain:latest
- docker push XinFinOrg/XDPoSChain:latest
- docker tag XinFinOrg/XDPoSChain XinFinOrg/XDPoSChain:$TRAVIS_BUILD_ID
- docker push XinFinOrg/XDPoSChain:$TRAVIS_BUILD_ID
- docker tag XinFinOrg/node XinFinOrg/node:latest
- docker push XinFinOrg/node:latest
- docker tag XinFinOrg/node XinFinOrg/node:$TRAVIS_BUILD_ID
- docker push XinFinOrg/node:$TRAVIS_BUILD_ID
- stage: Build and push image (tagged)
services:
- docker
install: skip
before_script:
- docker build -t XinFinOrg/XDPoSChain .
- docker build -t XinFinOrg/XDPoSChain -f Dockerfile.node .
script:
- echo "$DOCKER_PASSWORD" | docker login --username "$DOCKER_USERNAME" --password-stdin
- docker tag XinFinOrg/XDPoSChain XinFinOrg/XDPoSChain:latest
- docker push XinFinOrg/XDPoSChain:latest
- docker tag XinFinOrg/XDPoSChain XinFinOrg/XDPoSChain:$TRAVIS_TAG
- docker push XinFinOrg/XDPoSChain:$TRAVIS_TAG
- docker tag XinFinOrg/XDPoSChain XinFinOrg/node:latest
- docker push XinFinOrg/node:latest
- docker tag XinFinOrg/node XinFinOrg/node:$TRAVIS_TAG
- docker push XinFinOrg/node:$TRAVIS_TAG
stages:
# - name: Lint
- name: Build and test
- name: Github release
if: type != pull_request AND branch =~ ^v AND tag IS present AND repo = XinFinOrg/XDPoSChain
- name: Build and push image
if: type != pull_request AND branch = master AND tag IS blank AND repo = XinFinOrg/XDPoSChain
- name: Build and push image (tagged)
if: type != pull_request AND branch =~ ^v AND tag IS present AND repo = XinFinOrg/XDPoSChain
notifications:
slack:
rooms:
secure:
on_success: change
on_failure: always
- pip install --user awscli # install aws cli w/o sudo
- export PATH=$PATH:$HOME/.local/bin # put aws in the path
- eval $(aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin $ECR_BASE_URI) #needs AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY envvars
- docker tag xdc-devnet:latest $ECR_BASE_URI/$ECR_REPO_NAME:latest # Need ECR_REPO_NAME
- docker push $ECR_BASE_URI/$ECR_REPO_NAME:latest

23
cicd/README.md Normal file
View file

@ -0,0 +1,23 @@
# CI/CD pipeline for XDC
This directory contains CI/CD scripts used for each of the XDC environments.
### Devnet
Each PR merged into `dev-upgrade` will trigger below actions:
- Tests
- Docker build of XDC with devnet configurations with tag of `:latest`
- Docker push to AWS ECR
- Deployment of the latest XDC image(from above) to devnet run by AWS ECS
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. ECR_REPO_NAME
2. ECR_BASE_URI
3. AWS_ACCESS_KEY_ID
4. AWS_SECRET_ACCESS_KEY
### Testnet
**WIP**
### Mainnet
**WIP**

36
cicd/devnet/Dockerfile Normal file
View file

@ -0,0 +1,36 @@
FROM golang:1.14 as builder
RUN apt-get update && apt-get install -y git build-essential
COPY . /builder
RUN mv /builder/common/constants/constants.go.devnet /builder/common/constants.go
RUN cd /builder && make
# The actual image for devnet containers
FROM golang:1.14
RUN apt-get update && apt-get install -y git build-essential
WORKDIR /work
COPY --from=builder /builder/build/bin/XDC /usr/bin
RUN chmod +x /usr/bin/XDC
# Copy over files
ADD cicd/devnet/genesis.json /work/genesis.json
ADD cicd/devnet/bootnodes.list /work/bootnodes.list
ADD cicd/devnet/start.sh /work/start.sh
# Create an empty pwd file
RUN touch /work/.pwd
# rpc
EXPOSE 8545
# ws
EXPOSE 8555
# port
EXPOSE 30304
ENTRYPOINT ["bash","/work/start.sh"]

View file

@ -0,0 +1,2 @@
enode://1c20e6b46ce608c1fe739e78611225b94e663535b74a1545b1667eac8ff75ed43216306d123306c10e043f228e42cc53cb2728655019292380313393eaaf6e23@194.233.77.19:30301
enode://1c20e6b46ce608c1fe739e78611225b94e663535b74a1545b1667eac8ff75ed43216306d123306c10e043f228e42cc53cb2728655019292380313393eaaf6e23@66.94.98.186:30301

129
cicd/devnet/genesis.json Normal file

File diff suppressed because one or more lines are too long

50
cicd/devnet/start.sh Executable file
View file

@ -0,0 +1,50 @@
#!/bin/bash
if [ ! -d /work/xdcchain/XDC/chaindata ]
then
# Randomly select a key from environment variable, seperated by ','
if test -z "$PRIVATE_KEYS"
then
echo "PRIVATE_KEYS environment variable has not been set. You need to pass at least one PK, or you can pass multiple PK seperated by ',', we will randomly choose one for you"
exit 1
fi
IFS=', ' read -r -a private_keys <<< "$PRIVATE_KEYS"
private_key=${private_keys[ $RANDOM % ${#private_keys[@]} ]}
echo "${private_key}" >> /tmp/key
wallet=$(XDC account import --password .pwd --datadir /work/xdcchain /tmp/key | awk -v FS="({|})" '{print $2}')
XDC --datadir /work/xdcchain init /work/genesis.json
else
wallet=$(XDC account list --datadir /work/xdcchain | head -n 1 | awk -v FS="({|})" '{print $2}')
fi
input="/work/bootnodes.list"
bootnodes=""
while IFS= read -r line
do
if [ -z "${bootnodes}" ]
then
bootnodes=$line
else
bootnodes="${bootnodes},$line"
fi
done < "$input"
netstats="aws_${wallet}:xinfin_xdpos_hybrid_network_stats@devnetstats.apothem.network:2000"
INSTANCE_IP=$(curl https://checkip.amazonaws.com)
echo "Running a node with wallet: ${wallet} at IP: ${INSTANCE_IP}"
echo "Starting nodes with $bootnodes ..."
XDC --ethstats ${netstats} --gcmode=archive \
--bootnodes ${bootnodes} --syncmode full \
--datadir /work/xdcchain --networkid 551 \
-port 30304 --rpc --rpccorsdomain "*" --rpcaddr 0.0.0.0 \
--rpcport 8545 \
--rpcapi admin,db,eth,debug,miner,net,shh,txpool,personal,web3,XDPoS \
--rpcvhosts "*" --unlock "${wallet}" --password /work/.pwd --mine \
--gasprice "1" --targetgaslimit "420000000" --verbosity 3 \
--ws --wsaddr=0.0.0.0 --wsport 8555 \
--wsorigins "*" 2>&1 >>/work/xdcchain/xdc.log | tee --append /work/xdcchain/xdc.log