forked from singnet/wiki
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request singnet#45 from vsbogd/docker-image-for-workshop
Docker image for workshop
- Loading branch information
Showing
17 changed files
with
421 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,110 @@ | ||
FROM ubuntu:18.04 | ||
|
||
# setup environment variables | ||
ENV ROOT /singnet | ||
ENV GOPATH ${ROOT} | ||
ENV BIN ${GOPATH}/bin | ||
ENV PATH ${BIN}:${PATH} | ||
ENV LOG ${ROOT}/log | ||
ENV IPFS ${ROOT}/ipfs | ||
ENV SINGNET ${GOPATH}/src/github.com/singnet | ||
|
||
# setup folders needed | ||
RUN mkdir -p ${BIN} | ||
RUN mkdir -p ${LOG} | ||
RUN mkdir -p ${IPFS} | ||
RUN mkdir -p ${SINGNET} | ||
|
||
# update apt | ||
RUN apt-get update | ||
# install git | ||
RUN apt-get install -y git | ||
# install golang dev environment | ||
RUN apt-get install -y golang go-dep golang-goprotobuf-dev golint | ||
# install NodeJS dev environment | ||
RUN apt-get install -y nodejs npm | ||
RUN npm install -g ganache-cli truffle | ||
# install Python dev environment | ||
RUN apt-get install -y python3 python3-pip | ||
# install other libraries | ||
RUN apt-get install -y libudev-dev libusb-1.0-0-dev | ||
# additional tools | ||
RUN apt-get install -y net-tools screen vim | ||
|
||
# install IPFS | ||
ENV IPFS_PATH ${IPFS} | ||
RUN apt-get install -y curl | ||
COPY ./install_ipfs.sh ${GOPATH}/bin/ | ||
RUN install_ipfs.sh | ||
# setup IPFS | ||
RUN ipfs init | ||
RUN ipfs bootstrap rm --all | ||
RUN ipfs config Addresses.API /ip4/127.0.0.1/tcp/5002 | ||
RUN ipfs config Addresses.Gateway /ip4/0.0.0.0/tcp/8081 | ||
|
||
# token-contracts | ||
WORKDIR ${SINGNET} | ||
RUN git clone https://github.com/singnet/token-contracts | ||
WORKDIR ${SINGNET}/token-contracts | ||
RUN git checkout -b demo v1.0.0 | ||
|
||
# plaform-contracts | ||
WORKDIR ${SINGNET} | ||
RUN git clone https://github.com/singnet/platform-contracts | ||
WORKDIR ${SINGNET}/platform-contracts | ||
RUN git checkout -b demo v0.2.4 | ||
RUN npm install | ||
RUN truffle compile | ||
|
||
# snet-cli | ||
WORKDIR ${SINGNET} | ||
RUN git clone https://github.com/singnet/snet-cli | ||
WORKDIR ${SINGNET}/snet-cli | ||
RUN git checkout -b demo v0.1.8 | ||
RUN ./scripts/blockchain install | ||
RUN pip3 install -e . | ||
|
||
# snet-daemon | ||
WORKDIR ${SINGNET} | ||
RUN git clone https://github.com/singnet/snet-daemon | ||
WORKDIR ${SINGNET}/snet-daemon | ||
RUN git checkout -b demo v0.1.3 | ||
RUN ./scripts/install | ||
RUN ./scripts/build linux amd64 | ||
RUN cp ./build/snetd-linux-amd64 ${GOPATH}/bin | ||
|
||
# wiki | ||
WORKDIR ${SINGNET} | ||
RUN git clone https://github.com/singnet/wiki | ||
|
||
# publish Ethereum related environment variables | ||
ENV NETWORK_ID 12345 | ||
ENV DEPLOYER_ADDR 0x592E3C0f3B038A0D673F19a18a773F993d4b2610 | ||
ENV DEPLOYER_KEY 0xc71478a6d0fe44e763649de0a0deb5a080b788eefbbcf9c6f7aef0dd5dbd67e0 | ||
ENV CLIENT_ADDR 0x3b2b3C2e2E7C93db335E69D827F3CC4bC2A2A2cB | ||
ENV CLIENT_KEY 0x04899d5fd471ce68f84a5ec64e2e4b6b045d8b850599a57f5b307024be01f262 | ||
ENV PUBLISHER_ADDR 0x0067b427E299Eb2A4CBafc0B04C723F77c6d8a18 | ||
ENV PUBLISHER_KEY 0xba398df3130586b0d5e6ef3f757bf7fe8a1299d4b7268fdaae415952ed30ba87 | ||
ENV TOKEN_ADDR 0x6e5f20669177f5bdf3703ec5ea9c4d4fe3aabd14 | ||
ENV REGISTRY_ADDR 0x4e74fefa82e83e0964f0d9f53c68e03f7298a8b2 | ||
ENV MULTIPARTYESCROW_ADDR 0x5c7a4290f6f8ff64c69eeffdfafc8644a4ec3a4e | ||
|
||
# setup snet-cli | ||
#RUN snet network create --force local http://127.0.0.1:8545 | ||
RUN snet || true | ||
COPY ./add_local_network.sh ${GOPATH}/bin | ||
RUN add_local_network.sh | ||
RUN snet identity create deployer key --private-key ${DEPLOYER_KEY} | ||
RUN snet identity create client key --private-key ${CLIENT_KEY} | ||
RUN snet identity deployer | ||
RUN snet network local | ||
RUN snet set default_ipfs_endpoint http://localhost:5002 | ||
RUN snet set current_singularitynettoken_at ${TOKEN_ADDR} | ||
RUN snet set current_registry_at ${REGISTRY_ADDR} | ||
RUN snet set current_multipartyescrow_at ${MULTIPARTYESCROW_ADDR} | ||
|
||
# copy examples | ||
COPY examples ${SINGNET}/ | ||
|
||
COPY ./start_environment.sh ${GOPATH}/bin/ | ||
CMD start_environment.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,69 @@ | ||
# SingularityNet workshop examples | ||
|
||
Docker image and number of simple application examples which demonstrate how to | ||
work with SingularityNet platform. | ||
|
||
For the sake of clarity and simplicity it is a prepared environment which | ||
simulates behaviour of the Ethereum testnet like Kovan. But all things you are | ||
doing happens in your own instance of Ganache and doesn’t affect any public | ||
networks. | ||
|
||
Prerequisites: | ||
* [Docker CE](https://docs.docker.com/engine/installation/) | ||
* [Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) | ||
|
||
Hardware requirements: | ||
* 1 Gb free RAM to run docker image | ||
* 4 Gb free disk space to keep docker image | ||
|
||
Clone repository: | ||
```sh | ||
git clone https://github.com/singnet/wiki | ||
cd wiki/workshop/docker | ||
``` | ||
|
||
Build docker image: | ||
```sh | ||
docker build -t singnet . | ||
``` | ||
|
||
Run docker image: | ||
```sh | ||
docker run -ti singnet | ||
``` | ||
|
||
After docker image is up you will be in the `singnet` folder which contains all | ||
main SingularityNet git repositories and SingularityNet examples. | ||
|
||
Please start with reading `00-snet-cli/README` file and follow instructions. | ||
|
||
# Preparations made in image | ||
|
||
What is done in the docker image: | ||
|
||
* local IPFS instance is deployed and started (see [deploy local IPFS | ||
instance](https://github.com/singnet/wiki/blob/master/multiPartyEscrowContract/front-to-back-examples/Build-and-deploy-SingularityNET-locally.md#deploy-local-ipfs-instance) | ||
and [start local IPFS | ||
instance](https://github.com/singnet/wiki/blob/master/multiPartyEscrowContract/front-to-back-examples/Build-and-deploy-SingularityNET-locally.md#start-local-ipfs-instance) | ||
* Ganache instance is started with predefined network number and mnemonic to | ||
generate predictable accounts numbers and private keys (see [start local | ||
ethereum | ||
network](https://github.com/singnet/wiki/blob/master/multipartyescrowcontract/front-to-back-examples/build-and-deploy-singularitynet-locally.md#start-local-ethereum-network)); | ||
* local network id is exported as `$NETWORK_ID` environment variable; | ||
* all contracts are already deployed and their addresses are written to | ||
`snet-cli` configuration and exported as environment variables: | ||
`$TOKEN_ADDR`, `$REGISTRY_ADDR`, `$MULTIPARTYESCROW_ADDR`; | ||
* local Ethereum node and IPFS instance are added into snet-cli configuration | ||
[setup snet-cli | ||
interface](https://github.com/singnet/wiki/blob/master/multiPartyEscrowContract/front-to-back-examples/Build-and-deploy-SingularityNET-locally.md#setup-snet-command-line-interface); | ||
* all addresses and private keys generated by Ganache are exported as | ||
environment variables: `$DEPLOYER_ADDR`, `$DEPLOYER_KEY`, `$CLIENT_ADDR`, | ||
`$CLIENT_KEY`, `$PUBLISHER_ADDR`, `$PUBLISHED_KEY`; | ||
* couple of `snet-cli` identities are created: `deployer` and `client`, which | ||
are first and second identities generated by ganache-cli on start | ||
respectively. | ||
|
||
In order to see full list of preparations you need to work with local Ethereum | ||
network you need to look at page [build and deploy SingularityNet | ||
locally](https://github.com/singnet/wiki/blob/master/multiPartyEscrowContract/front-to-back-examples/Build-and-deploy-SingularityNET-locally.md). | ||
|
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,7 @@ | ||
#!/bin/sh | ||
|
||
cat <<EOF >> /root/.snet/config | ||
[network.local] | ||
default_eth_rpc_endpoint = http://127.0.0.1:8545 | ||
default_gas_price = 1000000000 | ||
EOF |
24 changes: 24 additions & 0 deletions
24
workshop/docker/examples/00-build-and-deploy-singularitynet/README
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 @@ | ||
# This example shows you how to build and deploy different SingularityNet | ||
# components from source. | ||
|
||
# Build and deploy SingularityNet contracts | ||
cd ${SINGNET}/platform-contracts # go to the platform-contracts repository | ||
npm install # install dependencies | ||
npm run compile # compile contracts | ||
npm run test # run contract tests | ||
cat truffle.js # add local network to the Truffle configuration | ||
truffle migrate --network local # deploy contracts to the local network | ||
|
||
# Build and install snet-cli | ||
cd ${SINGNET}/snet-cli # go to the snet-cli repository | ||
./scripts/blockchain install # install contract dependencies | ||
pip install -e . # install snet-cli | ||
cat ~/.snet/config # look at snet-cli configuration | ||
|
||
# Build and install SingularityNet daemon | ||
cd ${SINGNET}/snet-daemon # go to the daemon repository | ||
./scripts/install # install dependencies | ||
./scripts/build linux amd64 # build daemon | ||
cp ./build/snetd-linux-amd64 ${GOPATH}/bin # copy binary to the $PATH | ||
|
||
# next example |
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,21 @@ | ||
# This example demonstrates how to use snet-cli tool | ||
|
||
# transfer tokens to the client | ||
snet identity deployer | ||
snet client balance | ||
snet contract SingularityNetToken transferTokens $CLIENT_ADDR 100000000000 --transact --yes | ||
|
||
# deposit tokents into MultiPartyEscrow contract | ||
snet identity client | ||
snet client balance | ||
snet client deposit 1000 -y | ||
snet client balance | ||
|
||
# create publisher identity | ||
snet identity create --private-key $PUBLISHER_KEY publisher key | ||
|
||
# create organization | ||
snet identity publisher | ||
snet organization create ExampleOrganization --yes | ||
|
||
# next example |
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,29 @@ | ||
# compile service API | ||
cat echo_service.proto | ||
python3 -m grpc_tools.protoc -I. --python_out=. --grpc_python_out=. ./echo_service.proto | ||
|
||
# start service server | ||
cat echo_service.py | ||
screen -d -m python3 echo_service.py | ||
|
||
# check that service works | ||
cat echo_client.py | ||
python3 echo_client.py | ||
|
||
# publish service to the Registry | ||
snet identity publisher | ||
snet service metadata_init . EchoService $PUBLISHER_ADDR --encoding proto --service_type grpc | ||
snet service metadata_set_fixed_price 3 | ||
snet service metadata_add_endpoints http://127.0.0.1:8080 | ||
cat service_metadata.json | ||
snet service publish ExampleOrganization EchoService --yes | ||
|
||
# start daemon | ||
cat snetd.config.json | ||
screen -d -m snetd-linux-amd64 | ||
|
||
# call service via SingularityNet | ||
snet identity client | ||
snet client open_init_channel_registry ExampleOrganization EchoService 50 57600 -y | ||
snet client call 0 3 localhost:8080 echo '{"message": "hello"}' | ||
|
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,16 @@ | ||
import grpc | ||
|
||
import echo_service_pb2 | ||
import echo_service_pb2_grpc | ||
|
||
def main(): | ||
channel = grpc.insecure_channel('localhost:12345') | ||
service = echo_service_pb2_grpc.EchoServiceStub(channel) | ||
|
||
request = echo_service_pb2.EchoRequest() | ||
request.message = "test" | ||
response = service.echo(request) | ||
print(response) | ||
|
||
if __name__ == "__main__": | ||
main() |
13 changes: 13 additions & 0 deletions
13
workshop/docker/examples/02-grpc-service/echo_service.proto
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,13 @@ | ||
syntax = "proto3"; | ||
|
||
service EchoService { | ||
rpc echo(EchoRequest) returns (EchoResponse); | ||
} | ||
|
||
message EchoRequest { | ||
string message = 1; | ||
} | ||
|
||
message EchoResponse { | ||
string message = 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,28 @@ | ||
from concurrent import futures | ||
import grpc | ||
import time | ||
|
||
import echo_service_pb2 | ||
import echo_service_pb2_grpc | ||
|
||
class EchoServiceServicer(echo_service_pb2_grpc.EchoServiceServicer): | ||
|
||
def echo(self, request, context): | ||
response = echo_service_pb2.EchoResponse() | ||
response.message = "echo: " + request.message | ||
return response | ||
|
||
|
||
def main(): | ||
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) | ||
echo_service_pb2_grpc.add_EchoServiceServicer_to_server( | ||
EchoServiceServicer(), | ||
server) | ||
server.add_insecure_port('127.0.0.1:12345') | ||
server.start() | ||
|
||
while True: | ||
time.sleep(1) | ||
|
||
if __name__ == "__main__": | ||
main() |
17 changes: 17 additions & 0 deletions
17
workshop/docker/examples/02-grpc-service/snetd.config.json
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,17 @@ | ||
{ | ||
"blockchain_enabled": true, | ||
"daemon_end_point": "http://127.0.0.1:8080", | ||
"ethereum_json_rpc_endpoint": "http://127.0.0.1:8545", | ||
"ipfs_end_point": "http://localhost:5002/", | ||
"log": { | ||
"level": "debug", | ||
"output": { | ||
"type": "stdout" | ||
} | ||
}, | ||
"organization_name": "ExampleOrganization", | ||
"passthrough_enabled": true, | ||
"registry_address_key": "0x4e74fefa82e83e0964f0d9f53c68e03f7298a8b2", | ||
"service_name": "EchoService", | ||
"passthrough_endpoint": "http://127.0.0.1:12345" | ||
} |
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,16 @@ | ||
# publish service to the Registry | ||
snet identity publisher | ||
snet service metadata_init . ProcessService $PUBLISHER_ADDR --encoding json --service_type process | ||
snet service metadata_set_fixed_price 3 | ||
snet service metadata_add_endpoints http://127.0.0.1:8080 | ||
cat service_metadata.json | ||
snet service publish ExampleOrganization ProcessService --yes | ||
|
||
# start daemon | ||
cat snetd.config.json | ||
screen -d -m snetd-linux-amd64 | ||
|
||
# call service | ||
snet identity client | ||
snet client open_init_channel_registry ExampleOrganization ProcessService 50 57600 -y | ||
snet client call 1 3 localhost:8080 echo '{"message": "hello"}' |
13 changes: 13 additions & 0 deletions
13
workshop/docker/examples/03-process-service/echo_service.proto
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,13 @@ | ||
syntax = "proto3"; | ||
|
||
service EchoService { | ||
rpc echo(EchoRequest) returns (EchoResponse); | ||
} | ||
|
||
message EchoRequest { | ||
string message = 1; | ||
} | ||
|
||
message EchoResponse { | ||
string message = 1; | ||
} |
17 changes: 17 additions & 0 deletions
17
workshop/docker/examples/03-process-service/echo_service.py
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,17 @@ | ||
#!/usr/bin/env python3 | ||
import sys | ||
import json | ||
|
||
def echo(): | ||
request = json.load(sys.stdin) | ||
request['message'] = 'echo: ' + request['message'] | ||
json.dump(request, sys.stdout) | ||
|
||
def main(): | ||
if sys.argv[1] == 'echo': | ||
echo() | ||
else: | ||
sys.exit(1) | ||
|
||
if __name__ == '__main__': | ||
main() |
Oops, something went wrong.