-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
883a626
commit 99bfc04
Showing
8 changed files
with
525 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,5 +17,3 @@ mobile/keystore/* | |
/ignores | ||
/deployment | ||
/output | ||
|
||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
stages: | ||
- build | ||
- deploy | ||
- test | ||
|
||
before_script: | ||
- id | ||
- echo $GOPATH | ||
- pwd | ||
|
||
build_image: | ||
stage: build | ||
tags: | ||
- r2 | ||
script: | ||
- cd build/k8s-network-ci/ && make all | ||
- echo "build image success!!!" | ||
|
||
deploy2k8s: | ||
stage: deploy | ||
tags: | ||
- r2 | ||
script: | ||
- cd build/k8s-network-ci/ && sh ci.sh deploy | ||
|
||
testChain: | ||
stage: test | ||
tags: | ||
- r2 | ||
script: | ||
- cd build/k8s-network-ci/ && sh ci.sh test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
FROM registry.cn-hangzhou.aliyuncs.com/maisi/alpinetz08:latest | ||
COPY you-linux-amd64 genesis.json ucon.json /bin/ | ||
RUN chmod +x /bin/you-linux-amd64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
SHELL := /bin/bash | ||
GROUP_NAME = maisi | ||
RELEASE_DIR = ${GOPATH}/src/youchain/you-release | ||
REGISTRY_URL = registry.cn-hangzhou.aliyuncs.com | ||
SRC_DIR = ../../cmd/you | ||
PKG_DIR = github.com/youchainhq/go-youchain/cmd/you | ||
ROOT_DIR = ../../ | ||
BIN_REVISION_STRING := $(shell git show -s --pretty=format:%h) | ||
BIN_BUILD_TIME := $(shell date +"%Y-%m-%d %H:%M:%S") | ||
BIN_BUILD_TIME_SHORT := $(shell date +"%Y%m%d-%H%M") | ||
BIN_BUILD_BRANCH := $(shell git symbolic-ref --short -q HEAD) | ||
BIN_PATH_PREFIX := ${RELEASE_DIR}/you-$(BIN_REVISION_STRING)-$(BIN_BUILD_TIME_SHORT) | ||
SERVICE_NAME := feature-ci | ||
|
||
all: push | ||
|
||
project_testcase: | ||
cd ${ROOT_DIR} && go test -v -short ./... | ||
|
||
update_version: | ||
echo -e "package node\n\nconst revision = \"$(BIN_REVISION_STRING)\"\n\nconst buildTime = \"$(BIN_BUILD_TIME)\"\n\nconst buildBranch = \"$(BIN_BUILD_BRANCH)\"" > $(SRC_DIR)/node/version.go | ||
|
||
clear_version: | ||
echo -e "package node\n\nconst revision = \"\"\n\nconst buildTime = \"\"\n\nconst buildBranch = \"\"" > $(SRC_DIR)/node/version.go | ||
|
||
docker: | ||
go mod tidy | ||
xgo2 --targets=linux/amd64 -ldflags "-s -w" -out you --pkg=${PKG_DIR} ${ROOT_DIR} | ||
docker build -t ${GROUP_NAME}/${SERVICE_NAME}:$(BIN_REVISION_STRING) . | ||
rm -rf you-linux-amd64 | ||
|
||
push: project_testcase update_version docker clear_version | ||
docker tag ${GROUP_NAME}/${SERVICE_NAME}:$(BIN_REVISION_STRING) ${REGISTRY_URL}/${GROUP_NAME}/${SERVICE_NAME}:$(BIN_REVISION_STRING) | ||
docker push ${REGISTRY_URL}/${GROUP_NAME}/${SERVICE_NAME}:$(BIN_REVISION_STRING) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#!/usr/bin/env bash | ||
app_name=feature-ci | ||
version=`git show -s --pretty=format:%h` | ||
job="yctest-$version" | ||
bran=`git name-rev --name-only HEAD` | ||
appbranch=${bran#*origin/} | ||
time=$(date +%Y%m%d%H%M%S) | ||
########################################################################################################################################### | ||
# | ||
app_name_version="$app_name-$version" | ||
app_image_version="$app_name:$version" | ||
yaml="combo.yaml_$version" | ||
/bin/cp combo.yaml $yaml | ||
jobstat=null | ||
# | ||
deploy() | ||
{ | ||
sed -i "s/{ci_identify_app_name_version}/$app_name_version/g" $yaml | ||
sed -i "s/{ci_identify_app_image_version}/$app_image_version/g" $yaml | ||
sed -i "s/{ci_identify_job_name}/$job/g" $yaml | ||
sed -i "s#{branch}#$appbranch#g" $yaml | ||
sed -i "s/{commit}/$version/g" $yaml | ||
sed -i "s/{timeci}/$time/g" $yaml | ||
scp -P 65535 $yaml root@$APISERVERIP:/tmp/$yaml | ||
ssh -p 65535 root@$APISERVERIP "kubectl create -f /tmp/$yaml" | ||
rm -rf $yaml | ||
} | ||
|
||
test() | ||
{ | ||
sleep 3s | ||
# get log | ||
podname=$(curl -X GET $APISERVER/api/v1/namespaces/default/pods?labelSelector={app=$job} -s --header "Authorization: Bearer $APITOKEN" --insecure | jq -r .items[0].metadata.name ) | ||
echo $podname | ||
curl -X GET $APISERVER/api/v1/namespaces/default/pods/$podname/log?follow=true -s --header "Authorization: Bearer $APITOKEN" --insecure | ||
# check job status | ||
status=$(curl -X GET $APISERVER/apis/batch/v1/namespaces/default/jobs/$job/status -s --header "Authorization: Bearer $APITOKEN" --insecure) | ||
|
||
stat=$(echo "$status"|jq .status) | ||
echo "$stat" | ||
if [ "$stat" = "\"Failure\"" ]; then | ||
jobstat=failed | ||
else | ||
active=$(echo "$status"|jq .status.active) | ||
while [ "$active" = "1" ]; do | ||
sleep 1s | ||
curl -X GET $APISERVER/api/v1/namespaces/default/pods/$podname/log?follow=true -s --header "Authorization: Bearer $APITOKEN" --insecure | ||
status=$(curl -X GET $APISERVER/apis/batch/v1/namespaces/default/jobs/$job/status -s --header "Authorization: Bearer $APITOKEN" --insecure) | ||
active=$(echo "$status"|jq .status.active) | ||
done | ||
# job is done, check result | ||
fc=$(echo "$status"|jq .status.failed) | ||
if [ "$fc" = "1" ]; then | ||
jobstat=failed | ||
else | ||
jobstat=successed | ||
fi | ||
fi | ||
|
||
podIp=$(curl -X GET $APISERVER/api/v1/namespaces/default/pods?labelSelector={app=youchain-$app_name_version} -s --header "Authorization: Bearer $APITOKEN" --insecure | jq -r .items[0].status.podIP) | ||
echo "label:\tyouchain-"$app_name_version | ||
echo "dump state of pod:\t"$podIp | ||
ssh -p 65535 root@$APISERVERIP "curl -s -X POST http://$podIp:8283 -H 'Content-Type: application/json' -d '{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"dev_stateDump\",\"params\":[]}'" | ||
|
||
ssh -p 65535 root@$APISERVERIP "kubectl delete -f /tmp/$yaml" | ||
|
||
# return | ||
if [ "$jobstat" = "failed" ]; then | ||
exit 1 | ||
fi | ||
} | ||
# | ||
################ | ||
# | ||
$1 | ||
# | ||
########################################################################################################################################### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
apiVersion: extensions/v1beta1 | ||
kind: Deployment | ||
metadata: | ||
name: bootnode-{ci_identify_app_name_version} | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: bootnode-{ci_identify_app_name_version} | ||
template: | ||
metadata: | ||
labels: | ||
app: bootnode-{ci_identify_app_name_version} | ||
spec: | ||
imagePullSecrets: | ||
- name: aliyun-secret | ||
containers: | ||
- name: bootnode-{ci_identify_app_name_version} | ||
image: 'registry.cn-hangzhou.aliyuncs.com/maisi/youchain-bootnode-ci:latest' | ||
imagePullPolicy: Always | ||
command: | ||
- /bin/bootnode-linux-amd64 | ||
args: | ||
- '-nodekeyhex' | ||
- 'ce7f44b1795b34a4966092a85023661a4a953961fb55d00caee36cf2891f6e25' | ||
ports: | ||
- containerPort: 9284 | ||
--- | ||
kind: Service | ||
apiVersion: v1 | ||
metadata: | ||
name: bootnode-{ci_identify_app_name_version}-svc | ||
labels: | ||
name: bootnode-{ci_identify_app_name_version}-svc | ||
spec: | ||
ports: | ||
- protocol: UDP | ||
port: 9284 | ||
targetPort: 9284 | ||
selector: | ||
app: bootnode-{ci_identify_app_name_version} | ||
--- | ||
apiVersion: apps/v1beta1 | ||
kind: StatefulSet | ||
metadata: | ||
name: youchain-{ci_identify_app_name_version} | ||
spec: | ||
serviceName: "youchain-{ci_identify_app_name_version}" | ||
podManagementPolicy: "Parallel" | ||
replicas: 12 | ||
template: | ||
metadata: | ||
labels: | ||
app: youchain-{ci_identify_app_name_version} | ||
spec: | ||
serviceAccount: nfs-client-provisioner | ||
imagePullSecrets: | ||
- name: aliyun-secret | ||
containers: | ||
- image: registry.cn-hangzhou.aliyuncs.com/maisi/{ci_identify_app_image_version} | ||
name: youchain-{ci_identify_app_name_version} | ||
ports: | ||
- name: http-rpc | ||
containerPort: 8283 | ||
- name: ws-rpc | ||
containerPort: 8284 | ||
- name: p2p-rudp | ||
containerPort: 9283 | ||
- name: p2p-discover | ||
containerPort: 9284 | ||
- name: pprof-port | ||
containerPort: 7283 | ||
args: | ||
- '-mine' | ||
- '-rpc.host' | ||
- '0.0.0.0' | ||
- '-rpc.port' | ||
- '8283' | ||
- '-rpc.api' | ||
- 'net,you,dev' | ||
- '-rpc.wshost' | ||
- '0.0.0.0' | ||
- '-log.level' | ||
- '5' | ||
- '-genesis' | ||
- '/bin/genesis.json' | ||
- '-bootuconfile' | ||
- '/bin/ucon.json' | ||
- '-bootnodesvcname' | ||
- 'bootnode-{ci_identify_app_name_version}-svc' | ||
- '-nat.type' | ||
- 'Full' | ||
- '-p2p.bootnode' | ||
- 'enode://e913d749369090d9e425f2535fe17b9ef1c713616b7f3214be1b08daf7e8195e707531f6a11e19da6c13a22b04e915020c6511be5137bfe438bc92d529d20bed@{ip}:9283?discport=9284&nat=1&nodetype=1' | ||
command: | ||
- /bin/you-linux-amd64 | ||
imagePullPolicy: Always | ||
initContainers: | ||
- name: init-bootnode | ||
image: busybox:1.28.3 | ||
command: ['sh', '-c', 'until nslookup bootnode-{ci_identify_app_name_version}-svc; do echo waiting for bootnode-{ci_identify_app_name_version}-svc; sleep 2; done;'] | ||
--- | ||
#youchain headless services | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: youchain-{ci_identify_app_name_version} | ||
labels: | ||
app: youchain-{ci_identify_app_name_version} | ||
spec: | ||
ports: | ||
- port: 8283 | ||
clusterIP: None | ||
selector: | ||
app: youchain-{ci_identify_app_name_version} | ||
--- | ||
apiVersion: batch/v1 | ||
kind: Job | ||
metadata: | ||
name: {ci_identify_job_name} | ||
spec: | ||
template: | ||
metadata: | ||
labels: | ||
app: {ci_identify_job_name} | ||
spec: | ||
imagePullSecrets: | ||
- name: aliyun-secret | ||
containers: | ||
- name: {ci_identify_job_name} | ||
image: registry.cn-hangzhou.aliyuncs.com/maisi/yctest:0.7.5 | ||
command: ["/bin/yctest-linux-amd64"] | ||
imagePullPolicy: Always | ||
args: | ||
- '-label' | ||
- 'app=youchain-{ci_identify_app_name_version}' | ||
- '-wsport' | ||
- '8284' | ||
- '-minnode' | ||
- '12' | ||
- '-maxnode' | ||
- '12' | ||
- '-conf' | ||
- 'conf0.json' | ||
- '-branch' | ||
- '{branch}' | ||
- '-commit' | ||
- '{commit}' | ||
- '-timeci' | ||
- '{timeci}' | ||
- '-smart' | ||
restartPolicy: Never | ||
backoffLimit: 0 |
Oops, something went wrong.