Skip to content

Commit

Permalink
Merge pull request #130 from hyperledger/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
motxx committed Jan 19, 2017
2 parents 1489338 + 4204699 commit f6401e8
Show file tree
Hide file tree
Showing 13 changed files with 155 additions and 93 deletions.
60 changes: 27 additions & 33 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -1,51 +1,45 @@
machine:
services:
- docker
environment:
IROHA_HOME: $(pwd)/iroha
PATH: $PATH:/opt/cmake-3.5.2-Linux-x86_64/bin
JAVA_HOME: /usr/lib/jvm/java-1.8.0-openjdk-amd64/
java:
version: 'oraclejdk8'
pre:
- sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
- sudo apt-get update
- sudo apt-get install g++-5
- sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 20
- sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 20
- g++ -v

- sudo apt-get -y install build-essential libtcmalloc-minimal4 && sudo ln -s /usr/lib/libtcmalloc_minimal.so.4 /usr/lib/libtcmalloc_minimal.so
- sudo apt-get -y install xsltproc
- sudo apt-get -y install libhdf5-serial-dev libleveldb-dev libsnappy-dev liblmdb-dev
- sudo apt-get -y install autoconf automake libtool unzip


checkout:
post:
- git submodule init
- git submodule update

- cd $IROHA_HOME
- cd $IROHA_HOME/core/vendor/leveldb; make -j 4
- cd $IROHA_HOME/core/vendor/ed25519; make -j 4
- cd $IROHA_HOME/core/vendor/Cappuccino; git pull
- cd $IROHA_HOME/core/vendor/KeccakCodePackage; make; make generic64/libkeccak.a
- cd $IROHA_HOME/core/infra/crypto/; make
- git submodule sync
- git submodule update --init --recursive

dependencies:
cache_directories:
- ~/iroha/core/vendor/
- /tmp/protobuf
- /tmp/grpc
pre:
- if [[ ! -e /tmp/protobuf ]]; then git clone -b v3.0.0 https://github.com/google/protobuf.git /tmp/protobuf; cd /tmp/protobuf; (git cherry-pick 1760feb621a913189b90fe8595fffb74bce84598; echo Force continue); cd /tmp/protobuf; ./autogen.sh; ./configure --prefix=/usr; make -j 4; fi;
- cd /tmp/protobuf; sudo make install
- protoc --version
- ~/docker
override:
# one way to cache iroha-dev container is to save it to tar image. 2 mins vs 10 mins without caching.
- if [[ -e ~/docker/iroha-dev.tar ]]; then docker load -i ~/docker/iroha-dev.tar; fi
# build iroha-dev (if it is in cache, this step will be skipped) and iroha-docker (production) images
- ${IROHA_HOME}/docker/build.sh
# cache iroha-dev image. takes 30 sec to save into file
- mkdir -p ~/docker; docker save hyperledger/iroha-dev > ~/docker/iroha-dev.tar

- if [[ ! -e /tmp/grpc ]]; then git clone -b $(curl -L http://grpc.io/release) https://github.com/grpc/grpc /tmp/grpc; cd /tmp/grpc; git submodule update --init; make -j 4; fi;
- cd /tmp/grpc; sudo make install
- which grpc_cpp_plugin

test:
pre:
- mkdir build; cd build; cmake ..; make
override:
- ./test.sh
# TESTS:
# first, run ctest inside a container
- docker run -p 1204:1204 hyperledger/iroha-docker /test.sh
# then, run iroha with dummy config (1 node) and test curl request
- docker run -d -p 1204:1204 hyperledger/iroha-docker /run.sh && sleep 5 && curl -X POST http://127.0.0.1:1204/account/register -d '{"publicKey":"WdvM/DPabapmtA7ISbTYPywbHxk8gWu2221LzmcmAgw=","alias":"yonezu","timestamp":1482053586}'


deployment:
hub:
branch: master
commands:
- docker login -u ${DOCKER_USER} -p ${DOCKER_PASS}
- docker push hyperledger/iroha-docker

71 changes: 38 additions & 33 deletions core/infra/service/peer_service_with_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,65 +36,70 @@ namespace peer {
exit(EXIT_FAILURE);
}
}
}

optional<json> openConfig() {

json openConfig() {

if (configData) { // already content loaded
return configData;
}
if (configData) { // already content loaded
return *configData;
}

const auto PathToIROHA_HOME = [](){
const auto p = getenv("IROHA_HOME");
return p == nullptr ? "" : std::string(p);
}();
const auto PathToIROHA_HOME = [](){
const auto p = getenv("IROHA_HOME");
return p == nullptr ? "" : std::string(p);
}();

if (PathToIROHA_HOME.empty()) {
logger::error("peer with json") << "You must set IROHA_HOME!";
exit(EXIT_FAILURE);
}
if (PathToIROHA_HOME.empty()) {
logger::error("peer with json") << "You must set IROHA_HOME!";
exit(EXIT_FAILURE);
}

auto jsonStr = detail::openJSONText(PathToIROHA_HOME + "/config/sumeragi.json");

logger::info("peer with json") << "load json is " << jsonStr;
auto jsonStr = openJSONText(PathToIROHA_HOME + "/config/sumeragi.json");
logger::info("peer with json") << "load json is " << jsonStr;

detail::setConfigData(std::move(jsonStr));
setConfigData(std::move(jsonStr));

return configData;
return *configData;
}
}

std::string getMyPublicKey() {
if (auto config = openConfig()) {
return (*config)["me"]["publicKey"].get<std::string>();
try {
return detail::openConfig()["me"]["publicKey"].get<std::string>();
} catch(...) {
return "";
}
return "";
}

std::string getPrivateKey() {
if (auto config = openConfig()) {
return (*config)["me"]["privateKey"].get<std::string>();
try {
return detail::openConfig()["me"]["privateKey"].get<std::string>();
} catch(...) {
return "";
}
return "";
}

std::string getMyIp() {
if (auto config = openConfig()) {
return (*config)["me"]["ip"].get<std::string>();
try {
return detail::openConfig()["me"]["ip"].get<std::string>();
} catch(...) {
return "";
}
return "";
}

std::vector<std::unique_ptr<peer::Node>> getPeerList() {
std::vector<std::unique_ptr<peer::Node>> nodes;
if (auto config = openConfig()) {
for (const auto& peer : (*config)["group"].get<std::vector<json>>()){
try {
std::vector<std::unique_ptr<peer::Node>> nodes;
for (const auto& peer : detail::openConfig()["group"].get<std::vector<json>>()){
nodes.push_back(std::make_unique<peer::Node>(
peer["ip"].get<std::string>(),
peer["publicKey"].get<std::string>(),
1
));
}
return nodes;
} catch(...) {
return {};
}
return nodes;
}
};
};
4 changes: 1 addition & 3 deletions core/util/logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@ limitations under the License.
#include "datetime.hpp"

#if __cplusplus <= 201402L
#define NOEXCEPT
#define TYPE_UNC_EXC bool
#define STD_UNC_EXC std::uncaught_exception
#define COND_UNC_EXC ! STD_UNC_EXC()
#else
#define NOEXCEPT noexcept
#define TYPE_UNC_EXC int
#define STD_UNC_EXC std::uncaught_exceptions
#define COND_UNC_EXC uncaught >= STD_UNC_EXC()
Expand Down Expand Up @@ -58,7 +56,7 @@ namespace logger {
#define LOGGER_DEF(LoggerName, LogLevel, HasPrefix, LogType) \
struct LoggerName \
{ \
LoggerName(std::string&& caller) NOEXCEPT \
LoggerName(std::string&& caller) noexcept \
: caller(std::move(caller)), \
uncaught(STD_UNC_EXC()) \
{} \
Expand Down
8 changes: 4 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ services:
- 8000

iroha1:
image: hyperledger/iroha
image: hyperledger/iroha-docker
depends_on:
- configdiscovery
expose:
Expand All @@ -38,7 +38,7 @@ services:


iroha2:
image: hyperledger/iroha
image: hyperledger/iroha-docker
depends_on:
- configdiscovery
expose:
Expand All @@ -51,7 +51,7 @@ services:


iroha3:
image: hyperledger/iroha
image: hyperledger/iroha-docker
depends_on:
- configdiscovery
expose:
Expand All @@ -64,7 +64,7 @@ services:


iroha4:
image: hyperledger/iroha
image: hyperledger/iroha-docker
depends_on:
- configdiscovery
expose:
Expand Down
6 changes: 3 additions & 3 deletions docker/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ if [ -z ${IROHA_HOME} ]; then
fi

# build iroha-dev image
docker build -t hyperledger/iroha-dev ${IROHA_HOME}/docker/dev
docker build --rm=false -t hyperledger/iroha-dev ${IROHA_HOME}/docker/dev

# run dev container to build iroha
docker run -i --rm \
docker run -i \
-v ${IROHA_HOME}/docker/build:/build \
-v ${IROHA_HOME}:/opt/iroha \
hyperledger/iroha-dev \
Expand All @@ -24,4 +24,4 @@ docker run -i --rm \
COMMANDS

# build hyperledger/iroha container
docker build -t hyperledger/iroha ${IROHA_HOME}/docker/build
docker build --rm=false -t hyperledger/iroha-docker ${IROHA_HOME}/docker/build
13 changes: 8 additions & 5 deletions docker/build/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#-----------------------------------------------------------------------
# iroha-rel - IROHA container for Release
#
# build : docker build -t hyperledger/iroha .
# build : docker build -t hyperledger/iroha-docker .
#
# Copyright (c) 2016 Soramitsu,Co.,Ltd.
# All Rights Reserved.
Expand All @@ -11,8 +11,8 @@ FROM ubuntu

MAINTAINER Takeshi Yonezu <yonezu@soramitsu.co.jp> / Bogdan Vaneev <bogdan@soramitsu.co.jp>

LABEL BUILD="docker build -t hyperledger/iroha ."
LABEL RUN="docker run -d --name iroha hyperledger/iroha"
LABEL BUILD="docker build -t hyperledger/iroha-docker ."
LABEL RUN="docker run -d --name iroha hyperledger/iroha-docker"

ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64
# IROHA_HOME here should be the same as IROHA_RELEASE in iroha-dev
Expand All @@ -21,17 +21,20 @@ ENV IROHA_HOME=/usr/local/iroha
# this copies iroha and unpacks its binaries
ADD ./iroha.tar /
ADD ./scripts /
ADD ./config/sumeragi.json /tmp/sumeragi.json

RUN groupadd -g 168 iroha && \
useradd -u 168 -c "IROHA Administrator" -s /bin/bash -m -d ${IROHA_HOME} -p $(perl -e "print(crypt('passw0rd', 'sa'));") -g iroha iroha && \
usermod -G adm,sudo iroha && \
echo "export IROHA_HOME=${IROHA_HOME}" >> ${IROHA_HOME}/.bashrc && \
echo "export JAVA_HOME=${JAVA_HOME}" >> ${IROHA_HOME}/.bashrc; \

apt update && apt -y upgrade && apt -y install default-jdk netcat libsnappy-dev; \

echo /usr/local/lib >>/etc/ld.so.conf && \
echo ${IROHA_HOME}/lib >>/etc/ld.so.conf && \

mkdir -p ${IROHA_HOME}/config && \
cp /tmp/sumeragi.json ${IROHA_HOME}/config/sumeragi.json && \

ldconfig

CMD ["/run.sh"]
25 changes: 24 additions & 1 deletion docker/build/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,28 @@ This directory will be mounted to `iroha-dev` container. After successful build,

Then, to build iroha container, run:
```
docker build -t hyperledger/iroha .
docker build -t hyperledger/iroha-docker .
```


# Default config

Default `sumeragi.json` is

```json
{
"group": [
{
"ip": "127.0.0.1",
"name": "da77880a3da4",
"publicKey": "u7X/zQ/Dq21WW7YH4rbkpiCYJXjPxk5t3qNDKiVwBx8="
}
],
"me": {
"ip": "127.0.0.1",
"name": "da77880a3da4",
"privateKey": "cPY84e0BXGUHBjT4QdlPI0LI3BPIfUfSZjB8jdWURkNQ+pEagT/ysrewbt2YUo/Qbfd5vczW5oDooGSNUBTj9g==",
"publicKey": "u7X/zQ/Dq21WW7YH4rbkpiCYJXjPxk5t3qNDKiVwBx8="
}
}
```
15 changes: 15 additions & 0 deletions docker/build/config/sumeragi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"group": [
{
"ip": "127.0.0.1",
"name": "da77880a3da4",
"publicKey": "u7X/zQ/Dq21WW7YH4rbkpiCYJXjPxk5t3qNDKiVwBx8="
}
],
"me": {
"ip": "127.0.0.1",
"name": "da77880a3da4",
"privateKey": "cPY84e0BXGUHBjT4QdlPI0LI3BPIfUfSZjB8jdWURkNQ+pEagT/ysrewbt2YUo/Qbfd5vczW5oDooGSNUBTj9g==",
"publicKey": "u7X/zQ/Dq21WW7YH4rbkpiCYJXjPxk5t3qNDKiVwBx8="
}
}
8 changes: 8 additions & 0 deletions docker/build/scripts/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

total=0
for file in ${IROHA_HOME}/test_bin/*; do
./${file}
total=$((total + $?))
done
exit 0
2 changes: 2 additions & 0 deletions docker/dev/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ RUN apt-get update && apt-get -y upgrade; \
curl \
git \
make \
build-essential \
cmake \
g++-5 \
gcc-5 \
default-jdk \
Expand Down

0 comments on commit f6401e8

Please sign in to comment.