Przeglądaj źródła

Add first version

Ricardo Maltez 1 rok temu
commit
9a38e0ddd5

+ 6 - 0
.env.example

@@ -0,0 +1,6 @@
+CHAIN_NAME=ephesus
+JOYSTREAM_BRANCH=ephesus
+RUNTIME_PROFILE=PLAYGROUND
+
+GRAPHQL_SERVER_PORT=8081
+NODE_PORT=9944

+ 1 - 0
.gitignore

@@ -0,0 +1 @@
+.env

+ 19 - 0
Dockerfile

@@ -0,0 +1,19 @@
+FROM siddiquesa/dind-debian-latest:latest
+
+ARG RUNTIME_PROFILE==PLAYGROUND
+ARG JOYSTREAM_BRANCH
+
+ENV RUNTIME_PROFILE=$RUNTIME_PROFILE
+
+RUN apt-get update && apt install -y sudo git
+
+RUN git clone https://github.com/Joystream/joystream.git \
+    && cd joystream \
+    && git checkout ${JOYSTREAM_BRANCH}
+
+COPY container-scripts/init.sh /scripts/init.sh
+RUN bash /scripts/init.sh
+
+CMD bash
+
+EXPOSE 9944/tcp 8081/tcp

+ 23 - 0
README.md

@@ -0,0 +1,23 @@
+# Joystream AIO Docker Image 
+This docker image allows to run multiple validators nodes and query nodes in the same machine without the problem of name collission.  
+Just run one container from this image for each different network you want to run in the same machine.  
+The process of getting this image ready was split in two parts: 
+- Regular docker build (which will clone the joystream monorepo, checkout the selected branch, do the initial setup and build the necessary things).
+- Build of the joystream-node docker image, generate the chain spec file, start the validator node and the query node. 
+
+## Setup
+Create the '.env (you can check the .env.example) with: 
+- The name of the chain you want to run (this will be used as sufix for the docker containers, so must be unique)
+- Branch name to be used on the joystream monorepo
+- Node and query node port's  
+
+## First run
+```
+./first-run.sh
+```
+
+## Next run's
+After running the docker container the first time, just execute the run.sh script to start the container and start the joystream-node validator inside the container.
+``` 
+./run.sh
+```

+ 55 - 0
container-scripts/generate-chain-spec.sh

@@ -0,0 +1,55 @@
+#!/usr/bin/env bash
+
+set -e
+
+DATA_PATH=$PWD/../data
+
+cd ../joystream
+
+# The docker image tag to use for joystream/node
+RUNTIME=${RUNTIME:=$(scripts/runtime-code-shasum.sh)}
+
+# Source of funds for all new accounts that are created in the tests.
+TREASURY_INITIAL_BALANCE=${TREASURY_INITIAL_BALANCE:="100000000"}
+TREASURY_ACCOUNT_URI=${TREASURY_ACCOUNT_URI:="//Bob"}
+TREASURY_ACCOUNT=$(docker run --rm joystream/node:${RUNTIME} key inspect ${TREASURY_ACCOUNT_URI} --output-type json | jq .ss58Address -r)
+
+>&2 echo "treasury account from suri: ${TREASURY_ACCOUNT}"
+
+# Default initial balances
+echo "{
+  \"balances\":[
+    [\"$TREASURY_ACCOUNT\", $TREASURY_INITIAL_BALANCE]
+  ],
+  \"vesting\":[]
+}" > ${DATA_PATH}/initial-balances.json
+
+# Override initial balances from external source
+if [[ $INITIAL_BALANCES == http* ]];
+then
+  >&2 echo "fetching ${INITIAL_BALANCES}"
+  wget -O ${DATA_PATH}/initial-balances.json ${INITIAL_BALANCES}
+else
+  if [ ! -z "$INITIAL_BALANCES" ]; then
+    if jq -e . >/dev/null 2>&1 <<<"$INITIAL_BALANCES"; then
+      >&2 echo "Detected some valid JSON in INITIAL_BALANCES"
+      echo $INITIAL_BALANCES > ${DATA_PATH}/initial-balances.json
+    else
+      >&2 echo "Failed to parse INITIAL_BALANCES as JSON, or got false/null"
+    fi
+  fi
+fi
+
+# Create a chain spec file
+docker run --rm -v ${DATA_PATH}:/spec --entrypoint ./chain-spec-builder joystream/node:${RUNTIME} \
+  new \
+  --fund-accounts \
+  --authorities //Alice \
+  --deployment dev \
+  --chain-spec-path /spec/chain-spec.json \
+  --initial-balances-path /spec/initial-balances.json
+
+# Convert the chain spec file to a raw chainspec file
+docker run --rm -v ${DATA_PATH}:/spec joystream/node:${RUNTIME} build-spec \
+  --raw --disable-default-bootnode \
+  --chain /spec/chain-spec.json > ${DATA_PATH}/chain-spec-raw.json

+ 8 - 0
container-scripts/init.sh

@@ -0,0 +1,8 @@
+#!/usr/bin/env bash
+
+touch /root/.bash_profile
+
+cd joystream
+bash setup.sh
+source /root/.bashrc
+yarn build:packages

+ 14 - 0
container-scripts/start-node.sh

@@ -0,0 +1,14 @@
+#!/usr/bin/env bash
+
+DATA_PATH=$PWD/../data
+
+cd joystream
+
+RUNTIME=${RUNTIME:=$(scripts/runtime-code-shasum.sh)}
+
+export JOYSTREAM_NODE_TAG=${RUNTIME}
+docker-compose run --rm -d -v ${DATA_PATH}:/spec --name joystream-node \
+  -p 9944:9944 -p 9933:9933 joystream-node \
+  --alice --validator --unsafe-ws-external --unsafe-rpc-external \
+  --rpc-methods Unsafe --rpc-cors=all -l runtime \
+  --chain /spec/chain-spec-raw.json -d /spec/chain --pruning=archive --no-telemetry

+ 2 - 0
data/.gitignore

@@ -0,0 +1,2 @@
+*
+!.gitignore

+ 28 - 0
docker-compose.yml

@@ -0,0 +1,28 @@
+version: '3.4'
+services:
+  joystream-aio:
+    tty: true
+    container_name: joystream-aio-$CHAIN_NAME
+    privileged: true
+    image: joystream-aio
+    build:
+      context: ./
+      args:
+        - "JOYSTREAM_BRANCH=${JOYSTREAM_BRANCH}"
+        - "RUNTIME_PROFILE=${RUNTIME_PROFILE}"
+
+    volumes:
+      - type: bind
+        source: ./data
+        target: /data
+
+      - type: bind
+        source: ./container-scripts
+        target: /scripts
+
+    ports:
+      - "${GRAPHQL_SERVER_PORT}:8081"
+      - "${NODE_PORT}:9944"
+    command: bash
+
+  

+ 14 - 0
first-run.sh

@@ -0,0 +1,14 @@
+#!/usr/bin/env bash
+
+source .env
+mkdir -p data
+sudo rm -rf data/chain
+
+docker-compose up -d
+
+sleep 1 # we need to wait for the container to start the docker service
+
+docker exec -it -w /joystream joystream-aio-${CHAIN_NAME} bash -c "source /root/.bashrc && ./build-node-docker.sh"
+docker exec -it joystream-aio-${CHAIN_NAME} bash -c "source /root/.bashrc && scripts/generate-chain-spec.sh"
+docker exec -it joystream-aio-${CHAIN_NAME} bash -c "source /root/.bashrc && scripts/start-node.sh"
+docker exec -it -w /joystream joystream-aio-${CHAIN_NAME} bash -c "source /root/.bashrc && query-node/start.sh" 

+ 9 - 0
run.sh

@@ -0,0 +1,9 @@
+#!/usr/bin/env bash
+
+source .env
+
+docker-compose up -d
+
+sleep 1 # we need to wait for the container to start the docker service
+
+docker exec -it joystream-aio-${CHAIN_NAME} bash scripts/start-node.sh