Skip to content

Commit

Permalink
upgraded to Explorer 3.5 + fixed database waiting script
Browse files Browse the repository at this point in the history
  • Loading branch information
Yann committed Sep 7, 2018
1 parent 20c5562 commit 7f6a37b
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 14 deletions.
26 changes: 19 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,33 @@ git config --global core.longpaths true

In case you already set up the environment, here are some useful cleanup commands

1. Clean all containers containing "blockchain-explorer" in their name
1. Clean containers and volumes

```bash
docker-compose down
```

2. Clean all containers containing "blockchain-explorer" in their name

```bash
docker stop $(docker ps -a --filter="name=blockchain-explorer")
docker rm $(docker ps -a --filter="name=blockchain-explorer")
```

2. Clean all images with name starting with "hyperledger-blockchain-explorer" or "dev-peer"
3. Clean all images with name starting with "hyperledger-blockchain-explorer" or "dev-peer"

```bash
docker rmi $(docker images hyperledger-blockchain-explorer* -q)
```

3. Prune networks and volumes
4. Prune networks and volumes

```bash
docker network prune
docker volume prune
```

4. Remove crypto materials
5. Remove crypto materials

```bash
rm -rf app/config/crypto-config/
Expand All @@ -83,6 +89,7 @@ The **Hyperledger network** in which I ran this example is composed of :
- 1 channel _my-channel_ joined by both peer0 from both organizations
- 1 Go chaincode
- 4 Kafka nodes and 3 Zookeeper (as recommended)
- 2 Certification authorities (one per organization)

See _app/config/configtx.yaml_ and _app/config/crypto-config.yaml_ for example configuration and [Hyperledger Fabric documentation](https://hyperledger-fabric.readthedocs.io/en/release-1.2/) for the setup.

Expand All @@ -91,19 +98,24 @@ See _app/config/configtx.yaml_ and _app/config/crypto-config.yaml_ for example c
I have build a **custom setup**, that I think is simpler than the mentioned steps (from the [official repository](https://github.com/hyperledger/blockchain-explorer) _readme_ file) which consist of downloading the whole repository and then modify the files.

Instead of downloading the repository locally and doing the modification in the sources,
I get the repository directly into a **Docker** container and then link local configuration files to it using volumes.
I get the repository directly from a **Docker** container and then link local configuration files to it using volumes.

I used the **release-3.5** branch.
You may change the `EXPLORER_BRANCH` argument in the _docker-compose.yml_ file if you want to use a different branch (may requires other modifications).

I have implemented a **Compose** file (_docker-compose.yaml_) that builds the images/containers for the application and the database.
The containers will be attached to the existing Docker network of our Fabric network.

:warning: Make sure you use the same Docker network as your existing Hyperledger Fabric network in the _docker-compose.yaml_ file. Mine is `config_mynw`.

The Application will attach to the database once it is ready (I used a `wait.sh` script to wait for the database to be up).
The initialization scripts are retrieved from the official repository in the **PostGreSQL Dockerfile**.

So all that you need is in the _config_ directory :
All that you need is in the _config_ directory :
1. _config.json_ : file representing the network configuration
2. _crypto-config_ : folder containing the network certificates

So just adapt the _config.json_ file and copy the _crypto-config_ folder from the one generated during your **Fabric** setup.
You can regenerate the cryptographic materials from the _app/config/configtx.yaml_ and _app/config/crypto-config.yaml_ files if needed.

Then simply run :
Expand All @@ -114,7 +126,7 @@ docker-compose up

This will run 2 containers :
- `hyperledger_explorer_app` : the application
- `hyperledger_explorer_postgresql` : the database
- `hyperledger_explorer_postgresql` : the PostGreSQL database

You should be able to reach http://localhost:8092

Expand Down
7 changes: 5 additions & 2 deletions app/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ ENV DATABASE_NAME fabricexplorer
ENV DATABASE_USERNAME hppoc
ENV DATABASE_PASSWD password

# Get argument from compose file
ARG EXPLORER_BRANCH

# install required dependencies : python, make, g++, git
RUN apk add --no-cache --virtual npm-deps python make g++ git && \
python -m ensurepip && \
Expand All @@ -23,8 +26,8 @@ RUN apk add --no-cache findutils
RUN npm install -g yarn && \
chmod 777 /usr/local/bin/yarn

# get sources (only master branch and last revision)
RUN git clone --single-branch -b master --depth 1 https://github.com/hyperledger/blockchain-explorer /opt/explorer
# get sources (only specified branch and last revision)
RUN git clone --single-branch -b $EXPLORER_BRANCH --depth 1 https://github.com/hyperledger/blockchain-explorer /opt/explorer

# install NPM dependencies
RUN cd /opt/explorer && npm install && npm build
Expand Down
6 changes: 3 additions & 3 deletions app/wait.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Wait until PostGreSQL is ready
RETRIES=5
until psql -h postgresql -U postgres -d fabricexplorer -c "select 1" > /dev/null 2>&1 || [ $RETRIES -eq 0 ]; do
echo "Waiting for postgres server, $((RETRIES--)) remaining attempts..."
sleep 3
until $(nc -zv postgresql 5432 || [ $RETRIES -eq 0 ]); do
echo "Waiting for postgres container to be up, $((RETRIES--)) remaining attempts..."
sleep 2
done
4 changes: 4 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ services:
container_name: hyperledger_explorer_app
build:
context: ./app
args:
EXPLORER_BRANCH: 'release-3.5'
expose:
- "8092"
links:
Expand All @@ -29,6 +31,8 @@ services:
container_name: hyperledger_explorer_postgresql
build:
context: ./postgresql
args:
EXPLORER_BRANCH: 'release-3.5'
volumes:
- hyperledger_explorer_postgresql_data:/usr/local/pgsql/data
ports:
Expand Down
12 changes: 10 additions & 2 deletions postgresql/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ ENV USERNAME hppoc
ENV PGPASSWORD password
ENV POSTGRES_PASSWORD password

# Get argument from compose file
ARG EXPLORER_BRANCH

# Get script for database creation/initialization
RUN wget https://raw.githubusercontent.com/hyperledger/blockchain-explorer/master/app/persistence/postgreSQL/db/explorerpg.sql -O /docker-entrypoint-initdb.d/explorerpg.sql
RUN wget https://raw.githubusercontent.com/hyperledger/blockchain-explorer/master/app/persistence/postgreSQL/db/updatepg.sql -O /docker-entrypoint-initdb.d/updatepg.sql
RUN wget https://raw.githubusercontent.com/hyperledger/blockchain-explorer/$EXPLORER_BRANCH/app/persistence/postgreSQL/db/explorerpg.sql -O /docker-entrypoint-initdb.d/explorerpg.sql && \
wget https://raw.githubusercontent.com/hyperledger/blockchain-explorer/$EXPLORER_BRANCH/app/persistence/postgreSQL/db/updatepg.sql -O /docker-entrypoint-initdb.d/updatepg.sql

# Replace :user, :passwd and :dbname variables in the explorerpg.sql script
RUN sed -i 's/:user/hppoc/g' /docker-entrypoint-initdb.d/explorerpg.sql && \
sed -i "s/:passwd/'password'/g" /docker-entrypoint-initdb.d/explorerpg.sql && \
sed -i 's/:dbname/fabricexplorer/g' /docker-entrypoint-initdb.d/explorerpg.sqls://raw.githubusercontent.com/hyperledger/blockchain-explorer/master/app/persistence/postgreSQL/db/updatepg.sql -O /docker-entrypoint-initdb.d/updatepg.sql

0 comments on commit 7f6a37b

Please sign in to comment.