Skip to content

Commit

Permalink
Merge pull request #87 from Warchant/feature/docker-compose-dev
Browse files Browse the repository at this point in the history
Docker for development
  • Loading branch information
takemiyamakoto committed Dec 17, 2016
2 parents 9c26e3c + bbddc1c commit 61101cc
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@ LevelDB
fabric3 (python library, not hyperledger/fabric)
```
## Using docker and docker-compose for development
Refer to [this guide](./docs/using_docker.md).
## Installation
```
$ git submodule init
Expand Down
29 changes: 29 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

# Run this script inside 'iroha-dev' docker container to build iroha and its dependencies!

error(){
echo "[Error] $1"
exit 1
}


if [ -z ${IROHA_HOME} ]; then
error "Empty variable IROHA_HOME"
fi


# build dependencies
(cd $IROHA_HOME/core/vendor/leveldb && make -j4) || error "Can't build leveldb submodule"
(cd $IROHA_HOME/core/vendor/ed25519 && make -j4) || error "Can't build ed25519 submodule"
(cd $IROHA_HOME/core/vendor/KeccakCodePackage && \
make -j4 && \
make -j4 generic64/libkeccak.a) || error "Can't build KeccakCodePackage submodule"
(cd $IROHA_HOME/core/infra/crypto && make -j4) || error "Can't build crypto submodule"

# build iroha (important: build using single thread!)
(cd $IROHA_HOME && \
(mkdir $IROHA_HOME/build || echo "[+] build directory already exists, rebuilding") && \
cd $IROHA_HOME/build && \
cmake .. && \
make ) || error "Can't build iroha"
10 changes: 10 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: '2'

services:
iroha-dev:
build: ./iroha-dev
volumes:
# mounts current folder into container's /opt.
# Note: permissions and ownership will be transfered 1-to-1.
# It means, that file owned by user:user (id=1000) will be owned by user:user (id=1000) inside container!
- "../iroha:/opt/iroha"
47 changes: 47 additions & 0 deletions docs/using_docker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# How to use docker and docker-compose for `iroha` development

-----
Advantages:

- usage of docker-compose allows folder `iroha` to be mounted into container. This allows you to change code in host machine, at the same time changing it inside container(s)
- very easy to start development without dependencies conflicts

***Note***: permissions and ownership will be transfered 1-to-1 from host to container and backwards. It means, that file owned by `user:user` (**id=1000**) will be owned inside container by some other user (probably the same) **with id=1000**.
It means, that file created inside container by `root` will be owned by `root` on the host!
-----

First of all, you should clone `iroha` repository with all submodules to your host machine:

```bash
git clone --recursive https://github.com/hyperledger/iroha
cd iroha
```

Then, build `iroha-dev` image using [latest docker-compose](https://github.com/docker/compose/releases) [^1]:
```bash
docker-compose build
```

Run container:
```bash
docker-compose run iroha-dev bash
```

You got shell access into container with all dependencies for `iroha`. To build `iroha`, go to `$IROHA_HOME` folder and run `build.sh`[^2]:
```bash
cd $IROHA_HOME
./build.sh
```

If you want to remove container for some reason, use [^1]:
```bash
docker-compose down
```


[^1]: You must be in the same folder with `docker-compose.yml` file.
[^2]: `build.sh` must be executed from `$IROHA_HOME` direcory inside docker container.

# How to use docker and docker-compose for production

***TBD***
75 changes: 75 additions & 0 deletions iroha-dev/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#-----------------------------------------------------------------------
# iroha-dev - IROHA development container (base image for iroha)
#
# build : docker build -t hyperledger/iroha-dev .
#
# Copyright (c) 2016 Soramitsu,Co.,Ltd.
# All Rights Reserved.
#-----------------------------------------------------------------------
FROM ubuntu

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

USER root

ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64
ENV IROHA_HOME /opt/iroha

# we use single RUN instruction to reduce number of "layers" in docker image: https://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices
RUN groupadd -g 168 iroha && \
useradd -u 168 -c "IROHA Administrator" -s /bin/bash -m -p $(perl -e "print(crypt('passw0rd', 'sa'));") -g iroha iroha && \
usermod -G adm,sudo iroha && \
echo "export IROHA_HOME=${IROHA_HOME}" >>/home/iroha/.bashrc && \
echo "export JAVA_HOME=${JAVA_HOME}" >>/home/iroha/.bashrc && \
echo "export IROHA_HOME=${IROHA_HOME}" >>/root/.bashrc && \
echo "export JAVA_HOME=${JAVA_HOME}" >>/root/.bashrc; \

# install dependencies
apt-get update && apt-get -y upgrade; \
apt-get -y install \
software-properties-common \
python-software-properties \
curl \
git \
make \
g++-5 \
gcc-5 \
default-jdk \
libhdf5-serial-dev \
libleveldb-dev \
libsnappy-dev\
liblmdb-dev \
libssl-dev \
snappy \
unzip \
xsltproc \
zlib1g-dev \
autoconf \
automake \
libtool \
pkg-config ; \
add-apt-repository -y ppa:ubuntu-toolchain-r/test; \
update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 20; \
update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++-5 20; \
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 20; \
update-alternatives --install /usr/bin/cc cc /usr/bin/gcc-5 20; \
curl -sSL https://cmake.org/files/v3.5/cmake-3.5.2-Linux-x86_64.tar.gz | tar -xzC /opt; \
ln -s /opt/cmake*/bin/c* /usr/local/bin; \

# install protobuf v3.0.0
cd /tmp; \
git clone -b v3.0.0 https://github.com/google/protobuf.git; \
cd protobuf; \
(git cherry-pick 1760feb621a913189b90fe8595fffb74bce84598; echo Force continue) && \
./autogen.sh && \
./configure --prefix=/usr && \
make -j4 && make install; \

# install grpc
cd /tmp; \
git clone --recursive -b $(curl -L http://grpc.io/release) https://github.com/grpc/grpc; \
cd grpc; \
make && make install


CMD ["/bin/bash"]

0 comments on commit 61101cc

Please sign in to comment.