Skip to content

Commit

Permalink
fix(docker for local development) (#523)
Browse files Browse the repository at this point in the history
* fix(docker for local development)

* Update Dockerfile

* Compile contracts

* Remove comment

Co-authored-by: Marcelo <[email protected]>
  • Loading branch information
mhalambek and mfornet authored Aug 6, 2021
1 parent 0a20a93 commit 656da3e
Show file tree
Hide file tree
Showing 10 changed files with 199 additions and 27 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
**/node_modules
Dockerfile
9 changes: 6 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
node_modules
artifacts
cache
coverage
coverage.json
testdata
node_modules
target
testdata
vendor

# Ignore ethashproof binaries
eth2near/ethashproof/cmd/cache/cache
eth2near/ethashproof/cmd/epoch/epoch
eth2near/ethashproof/cmd/relayer/relayer
eth2near/ethashproof/cmd/cache/cache

33 changes: 20 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
FROM ubuntu:18.04
FROM ubuntu:20.04

RUN apt-get update && apt-get install -y \
COPY . /usr/src/
ENV RUSTUP_HOME=/usr/local/rustup \
CARGO_HOME=/usr/local/cargo \
PATH=/usr/local/cargo/bin:$PATH \
LC_ALL=C.UTF-8 \
LANG=C.UTF-8 \
PATH=~/.local/bin:$PATH \
DEBIAN_FRONTEND=noninteractive

RUN apt-get update -qq && apt-get install -y \
build-essential \
Expand All @@ -15,20 +20,22 @@ RUN apt-get update -qq && apt-get install -y \
netcat \
pkg-config \
python3 \
&& rm -rf /var/lib/apt/lists/*

RUN curl -sL https://deb.nodesource.com/setup_12.x | bash -
RUN apt-get install nodejs && npm -g install ganache-cli
python3-pip \
&& rm -rf /var/lib/apt/lists/* \
&& curl -sL https://deb.nodesource.com/setup_12.x | bash -

ENV RUSTUP_HOME=/usr/local/rustup \
CARGO_HOME=/usr/local/cargo \
PATH=/usr/local/cargo/bin:$PATH
RUN apt-get install nodejs && npm -g install ganache-cli yarn

RUN curl https://sh.rustup.rs -sSf | \
sh -s -- -y --no-modify-path --default-toolchain nightly-2020-05-15

COPY . /usr/src/
COPY config* ~/.rainbow
RUN curl -L https://golang.org/dl/go1.16.linux-amd64.tar.gz --output go1.16.linux-amd64.tar.gz && \
tar -C /usr/local -xzf go1.16.linux-amd64.tar.gz

WORKDIR /usr/src
RUN node index.js prepare
COPY . .
RUN yarn
ENV PATH /usr/local/go/bin:$PATH
RUN go version
RUN sh -c "./utils/scripts/docker_prepare.sh"
CMD ["sh", "-c", "./utils/scripts/docker_start.sh"]
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
],
"dependencies": {},
"devDependencies": {
"http-server": "^0.12.3",
"prettier": "^2.2.1",
"prettier-plugin-solidity": "^1.0.0-beta.5",
"standard": "*"
Expand All @@ -41,4 +42,4 @@
"testing",
"utils"
]
}
}
2 changes: 1 addition & 1 deletion utils/scripts/clean_start.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/bash
#!/bin/bash
set -xeo pipefail

./cli/index.js clean
Expand Down
23 changes: 23 additions & 0 deletions utils/scripts/docker_prepare.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash
set -xeo pipefail

pip3 install nearup
./cli/index.js clean
./cli/index.js prepare
mkdir -p ~/.near/localnet/node0
echo '{"account_id":"node0","public_key":"ed25519:7PGseFbWxvYVgZ89K1uTJKYoKetWs7BJtbyXDzfbAcqX","secret_key":"ed25519:3D4YudUQRE39Lc4JHghuB5WM8kbgDDa34mnrEP5DdTApVH81af7e2dWgNPEaiQfdJnZq1CNPp5im4Rg5b733oiMP"}' > ~/.near/localnet/node0/validator_key.json
echo '{"account_id":"","public_key":"ed25519:7PGseFbWxvYVgZ89K1uTJKYoKetWs7BJtbyXDzfbAcqX","secret_key":"ed25519:3D4YudUQRE39Lc4JHghuB5WM8kbgDDa34mnrEP5DdTApVH81af7e2dWgNPEaiQfdJnZq1CNPp5im4Rg5b733oiMP"}' > ~/.near/localnet/node0/node_key.json

./cli/index.js start near-node
./cli/index.js start ganache
sleep 10
./cli/index.js init-near-contracts
./cli/index.js init-eth-ed25519
./cli/index.js init-eth-client --eth-client-lock-eth-amount 1000000000 --eth-client-lock-duration 10
./cli/index.js init-eth-prover
./cli/index.js init-eth-erc20
./cli/index.js init-eth-locker
./cli/index.js init-near-token-factory

./cli/index.js stop near-node
./cli/index.js stop ganache
19 changes: 19 additions & 0 deletions utils/scripts/docker_start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
set -xeo pipefail

if [ -f "/root/.nearup/node.pid" ]; then
rm /root/.nearup/node.pid
fi

if [ -f "/root/.nearup/watcher.pid" ]; then
rm /root/.nearup/watcher.pid
fi

nearup run localnet --num-nodes 1 --binary-path ~/.rainbow/core/target/debug
./cli/index.js start ganache
sleep 10
./cli/index.js start eth2near-relay --metrics-port 8080
./cli/index.js start near2eth-relay --eth-master-sk 0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501201 --metrics-port 8181
./cli/index.js start bridge-watchdog --eth-master-sk 0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501202
nohup ./node_modules/.bin/http-server ~/.near/localnet/node0/ -p 9000 -d &
./node_modules/.bin/pm2 logs
17 changes: 14 additions & 3 deletions utils/scripts/prepare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,20 @@ if test -z "$LOCAL_CORE_SRC"
then
echo "near-core home not specified..."
if [ "$MACHINE" == "Linux" ]; then
NEAR_CORE_LATEST_COMMIT="$(git ls-remote git://github.com/near/nearcore.git | grep refs/heads/master | cut -f 1)"
NEAR_CORE_BINARY_URL="https://s3-us-west-1.amazonaws.com/build.nearprotocol.com/nearcore/Linux/master/$NEAR_CORE_LATEST_COMMIT/neard"
if [[ -z "$NEAR_CHAIN_ID" ]]; then
NEAR_CHAIN_ID=testnet
fi
NEAR_RELEASE=$(curl https://s3-us-west-1.amazonaws.com/build.nearprotocol.com/nearcore-deploy/$NEAR_CHAIN_ID/latest_release)
NEAR_DEPLOY=$(curl https://s3-us-west-1.amazonaws.com/build.nearprotocol.com/nearcore-deploy/$NEAR_CHAIN_ID/latest_deploy)
NEAR_CORE_BINARY_URL="https://s3-us-west-1.amazonaws.com/build.nearprotocol.com/nearcore/Linux/$NEAR_RELEASE/$NEAR_DEPLOY/neard"
NEAR_CORE_BINARY_DIR="$CORE_SRC/target/debug"
NEAR_CORE_BINARY_PATH="$NEAR_CORE_BINARY_DIR/neard"
mkdir -p $NEAR_CORE_BINARY_DIR
curl $NEAR_CORE_BINARY_URL > $NEAR_CORE_BINARY_PATH
status=$(curl $NEAR_CORE_BINARY_URL --output $NEAR_CORE_BINARY_PATH --write-out "%{http_code}")
if [ "$status" != "200" ]; then
echo "Download neard failed"
exit 1
fi
chmod +x $NEAR_CORE_BINARY_PATH
else
git clone "https://github.com/nearprotocol/nearcore" $CORE_SRC
Expand All @@ -68,6 +76,9 @@ if [ -d .git ]; then
fi

yarn
(cd contracts/eth/nearbridge/ && yarn && yarn build)
(cd contracts/eth/nearprover/ && yarn && yarn build)

echo "Installed CLI dependencies"

cd $BRIDGE_SRC/testing/vendor/ganache
Expand Down
2 changes: 1 addition & 1 deletion utils/scripts/start_ganache.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ set -euo pipefail
SCRIPTS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" 2>&1 && pwd )"
cd ${SCRIPTS_DIR}/../../testing/vendor/ganache
ganache_block_time=${GANACHE_BLOCK_TIME:-12}
node_modules/.bin/ganache-cli --port 9545 --blockTime $ganache_block_time --gasLimit 10000000 --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501200,10000000000000000000000000000" --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501201,10000000000000000000000000000" --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501202,10000000000000000000000000000"
node_modules/.bin/ganache-cli --port 9545 --blockTime $ganache_block_time --gasLimit 10000000 --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501200,10000000000000000000000000000" --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501201,10000000000000000000000000000" --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501202,10000000000000000000000000000" --db localnet -h 0.0.0.0
Loading

0 comments on commit 656da3e

Please sign in to comment.