-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add docker file, one-host_multi-node script
- Loading branch information
1 parent
50c4b51
commit ab8f93e
Showing
5 changed files
with
243 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,81 @@ | ||
FROM ubuntu:16.04 | ||
MAINTAINER it-chain | ||
|
||
# Let's start with some basic stuff. | ||
RUN apt-get update -qq && apt-get install -qqy \ | ||
apt-transport-https \ | ||
ca-certificates \ | ||
curl \ | ||
lxc \ | ||
iptables \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
# Install Docker from Docker Inc. repositories. | ||
RUN curl -sSL https://get.docker.com/ | sh | ||
|
||
RUN apt-get update && apt-get install -y --no-install-recommends \ | ||
g++ \ | ||
gcc \ | ||
libc6-dev \ | ||
make \ | ||
pkg-config \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
ENV GOLANG_VERSION 1.10.4 | ||
|
||
RUN set -eux; \ | ||
\ | ||
# this "case" statement is generated via "update.sh" | ||
dpkgArch="$(dpkg --print-architecture)"; \ | ||
case "${dpkgArch##*-}" in \ | ||
amd64) goRelArch='linux-amd64'; goRelSha256='fa04efdb17a275a0c6e137f969a1c4eb878939e91e1da16060ce42f02c2ec5ec' ;; \ | ||
armhf) goRelArch='linux-armv6l'; goRelSha256='4e1e80bd98f3598c0c48ba0c189c836d01b602bfc769b827a4bfed01d2c14b21' ;; \ | ||
arm64) goRelArch='linux-arm64'; goRelSha256='2e0f9e99aeefaabba280b2bf85db0336da122accde73603159b3d72d0b2bd512' ;; \ | ||
i386) goRelArch='linux-386'; goRelSha256='771f48e55776d4abc9c2a74907457066c7c282ac05fa01cf5ff4422ced76d2ee' ;; \ | ||
ppc64el) goRelArch='linux-ppc64le'; goRelSha256='1cfc147357c0be91a988998046997c5f30b20c6baaeb6cd5774717714db76093' ;; \ | ||
s390x) goRelArch='linux-s390x'; goRelSha256='5593d770d6544090c1bb20d57bb34c743131470695e195fbe5352bf056927a35' ;; \ | ||
*) goRelArch='src'; goRelSha256='6fe44965ed453cd968a81988523e9b0e794d3a478f91fd7983c28763d52d5781'; \ | ||
echo >&2; echo >&2 "warning: current architecture ($dpkgArch) does not have a corresponding Go binary release; will be building from source"; echo >&2 ;; \ | ||
esac; \ | ||
\ | ||
url="https://golang.org/dl/go${GOLANG_VERSION}.${goRelArch}.tar.gz"; \ | ||
wget -O go.tgz "$url"; \ | ||
echo "${goRelSha256} *go.tgz" | sha256sum -c -; \ | ||
tar -C /usr/local -xzf go.tgz; \ | ||
rm go.tgz; \ | ||
\ | ||
if [ "$goRelArch" = 'src' ]; then \ | ||
echo >&2; \ | ||
echo >&2 'error: UNIMPLEMENTED'; \ | ||
echo >&2 'TODO install golang-any from jessie-backports for GOROOT_BOOTSTRAP (and uninstall after build)'; \ | ||
echo >&2; \ | ||
exit 1; \ | ||
fi; \ | ||
\ | ||
export PATH="/usr/local/go/bin:$PATH"; \ | ||
go version | ||
|
||
ENV GOPATH /go | ||
ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH | ||
|
||
RUN mkdir -p "$GOPATH/src" "$GOPATH/bin" && chmod -R 777 "$GOPATH" | ||
|
||
RUN apt-get update -qq && apt-get install -qqy \ | ||
rabbitmq-server \ | ||
git \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
|
||
RUN mkdir /go/src/github.com ; \ | ||
mkdir /go/src/github.com/it-chain ;\ | ||
cd /go/src/github.com/it-chain ;\ | ||
git clone https://github.com/it-chain/engine ;\ | ||
go get -u github.com/golang/dep/cmd/dep ;\ | ||
cd engine ;\ | ||
/go/bin/dep ensure | ||
|
||
ADD ./entrypoint.sh /entrypoint.sh | ||
RUN chmod +x /entrypoint.sh | ||
EXPOSE 4000 5000 | ||
ENTRYPOINT ["sh"] | ||
CMD ["entrypoint.sh"] |
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,24 @@ | ||
engine: | ||
logpath: log/it-chain.log | ||
keypath: .it-chain/ | ||
mode: pbft | ||
amqp: amqp://guest:guest@localhost:5672/ | ||
bootstrapnodeaddress: | ||
txpool: | ||
timeoutms: 1000 | ||
maxtransactionbyte: 1024 | ||
consensus: | ||
batchtime: 3 | ||
maxtransactions: 100 | ||
blockchain: | ||
genesisconfpath: ./Genesis.conf | ||
peer: | ||
leaderelection: RAFT | ||
icode: | ||
repositorypath: empty | ||
grpcgateway: | ||
address: 172.18.1.0 | ||
port: 5000 | ||
apigateway: | ||
address: 172.18.1.0 | ||
port: 4000 |
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,24 @@ | ||
engine: | ||
logpath: log/it-chain.log | ||
keypath: .it-chain/ | ||
mode: pbft | ||
amqp: amqp://guest:guest@localhost:5672/ | ||
bootstrapnodeaddress: 127.0.0.1:5555 | ||
txpool: | ||
timeoutms: 1000 | ||
maxtransactionbyte: 1024 | ||
consensus: | ||
batchtime: 3 | ||
maxtransactions: 100 | ||
blockchain: | ||
genesisconfpath: ./Genesis.conf | ||
peer: | ||
leaderelection: RAFT | ||
icode: | ||
repositorypath: empty | ||
grpcgateway: | ||
address: 0.0.0.0 | ||
port: 5000 | ||
apigateway: | ||
address: 0.0.0.0 | ||
port: 4000 |
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,5 @@ | ||
dockerd & | ||
rabbitmq-server & | ||
sleep 5 | ||
cd /go/src/github.com/it-chain/engine | ||
go run it-chain.go --config conf/config_docker.yaml |
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,109 @@ | ||
# | ||
# input only one paramter for node number. | ||
# | ||
abspath=$PWD | ||
|
||
if [ $# -ne 1 ]; then | ||
echo please input node number to init or --help | ||
echo "ex) ./create_network.sh 4" | ||
exit 1 | ||
fi | ||
|
||
if [ $1 == "--help" ]; then | ||
echo use this shell script with node num to create | ||
echo "ex ) ./create_network.sh 4" | ||
echo "-> mean create 4 node and connect each to create network. it will make blocak chain network with 4 node." | ||
echo | ||
echo each api-gateway port has 40001 ~ 4000X, X = node num. so node1 = 40001, node2 = 40002 ... | ||
echo each grpc-gateway port has 50001 ~ 5000X, X = node num. so node1 = 50001, node2 = 50002 ... | ||
exit 0 | ||
fi | ||
|
||
echo wait for pull it-chain docker image | ||
# | ||
# docker pull itchain latest version | ||
# | ||
docker pull teamit/itchain:latest | ||
|
||
# | ||
# create node in docker container. | ||
# each node has port to api-gateway : 4000X | ||
# grpc-gateway : 5000X | ||
# X = node number | ||
# | ||
|
||
echo wait for create node container... | ||
|
||
docker network create --subnet=172.18.0.0/16 it-chain > /dev/null 2>&1 | ||
sleep 2 | ||
|
||
docker run -d -p 40001:4000 -p 50001:5000 -v $abspath/config_docker_leader.yaml:/go/src/github.com/it-chain/engine/conf/config_docker.yaml \ | ||
--privileged --net it-chain --ip 172.18.1.0 teamit/itchain:latest | ||
|
||
# | ||
# if node num is 1, not try to connect to other node. just finish | ||
# | ||
|
||
if [ $1 -eq 1 ]; then | ||
sleep 20 | ||
echo finish create node! | ||
echo node1 - api-gateway : 40001, grpc-gateway : 50001 | ||
exit | ||
fi | ||
|
||
|
||
|
||
for i in $(eval echo {2..$1}) | ||
do | ||
cp $abspath/config_docker_member.yaml config_docker_member_$i.yaml | ||
sed -i -e "s/0.0.0.0/172.18.$i.0/" config_docker_member_$i.yaml | ||
docker run -d -p 4000$i:4000 -p 5000$i:5000 \ | ||
-v $abspath/config_docker_member_$i.yaml:/go/src/github.com/it-chain/engine/conf/config_docker.yaml \ | ||
--privileged --net it-chain --ip 172.18.$i.0 teamit/itchain:latest | ||
done | ||
|
||
# | ||
# wait for 20 sec for waiting start node. | ||
# if something err with using this script, | ||
# try to increase this time first | ||
# | ||
|
||
echo wait for start all node... | ||
echo it will take about 60 sec ... | ||
|
||
for i in $(eval echo {1..$1}) | ||
do | ||
echo try to check node$i... | ||
status_code=$(curl --write-out %{http_code} --silent --output /dev/null http://127.0.0.1:4000$i/peers) | ||
while [ "$status_code" != 200 ] | ||
do | ||
sleep 1 | ||
status_code=$(curl --write-out %{http_code} --silent --output /dev/null http://127.0.0.1:4000$i/peers) | ||
sleep 5 | ||
done | ||
done | ||
|
||
echo start to connect each node... | ||
|
||
for i in $(eval echo {2..$1}) | ||
do | ||
curl --header "Content-Type: application/json" \ | ||
--request POST \ | ||
--data '{"type":"join","address":"172.18.1.0:5000"}' \ | ||
http://127.0.0.1:4000$i/peers | ||
sleep 5 | ||
done | ||
|
||
echo finish to connect each node... | ||
sleep 2 | ||
|
||
echo | ||
echo | ||
|
||
echo node port info------------ | ||
for i in $(eval echo {1..$1}) | ||
do | ||
echo node$i - api-gateway : 4000$i, grpc-gateway : 5000$i | ||
done | ||
|
||
rm $abspath/config_docker_member_* |