Skip to content

Commit

Permalink
Create initial dockerfile for exit tool
Browse files Browse the repository at this point in the history
  • Loading branch information
popzxc committed Oct 21, 2020
1 parent dbb2dc2 commit 70d27a0
Show file tree
Hide file tree
Showing 12 changed files with 131 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
*
!docker/prover/prover-entry.sh
!docker/exit-tool/exit-tool-entry.sh
!docker/keybase-secrets/entrypoint.sh
!etc/env/dev.env.example
!etc/tokens
!keys/packed
!docker/nginx/nginx.conf
!bin/
Expand Down
9 changes: 6 additions & 3 deletions bin/.setup_env
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@

pushd `dirname $0`/.. > /dev/null

cd $ZKSYNC_HOME

# Setup the git hooks folder.
if ! git config --local core.hooksPath > /dev/null; then
git config --local core.hooksPath $ZKSYNC_HOME/.githooks/ > /dev/null
if [ -d .git ]; then
if ! git config --local core.hooksPath > /dev/null; then
git config --local core.hooksPath $ZKSYNC_HOME/.githooks/ > /dev/null
fi
fi

# Setup env itself
if [ -z "$ZKSYNC_ENV" ]
then

if [ -f etc/env/current ]; then
export ZKSYNC_ENV=`cat etc/env/current`
else
Expand Down
12 changes: 12 additions & 0 deletions bin/db-check-sqlx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

set -e

# Check generated sqlx data
if ! cargo sqlx prepare --check
then
# Prepare sqlx bindings
# We're going to do it even on CI, since it seems that this file can be invalidated after several subsequent compilations.
echo "Going to rerun 'sqlx prepare'"
cargo sqlx prepare
fi
16 changes: 8 additions & 8 deletions bin/db-setup
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ diesel migration run
# We don't need this file for sqlx
rm src/schema.rs.generated

# Check generated sqlx data
if ! cargo sqlx prepare --check
then
# Prepare sqlx bindings
# We're going to do it even on CI, since it seems that this file can be invalidated after several subsequent compilations.
echo "Going to rerun 'sqlx prepare'"
cargo sqlx prepare
fi
# # Check generated sqlx data
# if ! cargo sqlx prepare --check
# then
# # Prepare sqlx bindings
# # We're going to do it even on CI, since it seems that this file can be invalidated after several subsequent compilations.
# echo "Going to rerun 'sqlx prepare'"
# cargo sqlx prepare
# fi
1 change: 1 addition & 0 deletions bin/init
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ zksync yarn || true # It can fail.
zksync plonk-setup check || zksync plonk-setup download
zksync verify-keys unpack
zksync db-setup
zksync db-check-sqlx
zksync build-dev-contracts
zksync deploy-erc20 dev
zksync build-contracts
Expand Down
12 changes: 11 additions & 1 deletion core/bin/data_restore/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ async fn main() {

let cli = App::new("Data restore driver")
.author("Matter Labs")
.arg(
Arg::with_name("web3-url")
.long("web3")
.help("Sets the web3 API to be used to interact with the Ethereum blockchain"),
)
.arg(
Arg::with_name("genesis")
.long("genesis")
Expand All @@ -81,7 +86,12 @@ async fn main() {
)
.get_matches();

let transport = Http::new(&config_opts.web3_url).expect("failed to start web3 transport");
let web3_url = cli
.value_of("web3-url")
.map(|value| value.to_string())
.unwrap_or(config_opts.web3_url);

let transport = Http::new(&web3_url).expect("failed to start web3 transport");
let governance_addr = config_opts.governance_eth_addr;
let genesis_tx_hash = config_opts.genesis_tx_hash;
let contract_addr = config_opts.contract_eth_addr;
Expand Down
2 changes: 1 addition & 1 deletion core/bin/server/examples/generate_exit_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async fn main() {
.author("Matter Labs")
.arg(
Arg::with_name("Account id")
.long("accound_id")
.long("account_id")
.takes_value(true)
.required(true)
.help("Account id of the account"),
Expand Down
1 change: 1 addition & 0 deletions core/lib/storage/.env.backup
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DATABASE_URL=postgres://postgres@localhost/plasma
30 changes: 30 additions & 0 deletions docker/exit-tool/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# syntax=docker/dockerfile:experimental
FROM debian:buster-slim

WORKDIR /usr/src/zksync

# Prepare dependencies
RUN apt-get update && apt-get install -y bash git nodejs npm postgresql openssl libssl-dev gcc g++ curl libpq-dev pkg-config software-properties-common
RUN apt-get install -y libpq5 ca-certificates && rm -rf /var/lib/apt/lists/*
RUN npm install -g yarn

# Install Rust and required cargo packages
ENV RUSTUP_HOME=/usr/local/rustup \
CARGO_HOME=/usr/local/cargo \
PATH=/usr/local/cargo/bin:$PATH
RUN curl https://sh.rustup.rs -sSf | bash -s -- -y
RUN cargo install diesel_cli --no-default-features --features postgres
RUN cargo install --version=0.1.0-beta.1 sqlx-cli

# Copy workspace
COPY . .

# Build all the required zkSync binaries
RUN cargo build --release
RUN cargo build --release --example generate_exit_proof

COPY docker/exit-tool/exit-tool-entry.sh /usr/local/bin/

# Setup the environment
ENV ZKSYNC_HOME=/usr/src/zksync
ENV PATH="${ZKSYNC_HOME}/bin:${PATH}"
12 changes: 12 additions & 0 deletions docker/exit-tool/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: '3.2'
services:
postgres:
image: "postgres:12"
ports:
- "5432:5432"
volumes:
- type: bind
source: ./volumes/postgres
target: /var/lib/postgresql/data
environment:
- POSTGRES_HOST_AUTH_METHOD=trust
44 changes: 44 additions & 0 deletions docker/exit-tool/exit-tool-entry.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash

# 1. Check whether database `plasma` exists
# 2. If not, run all the migrations
# 3. Run data-restore in the finite mode
# 4. Run gen-exit-proof

USAGE="exit_tool_entry.sh init|restart|run|continue account_id token web3_url"

. .setup_env

cd $ZKSYNC_HOME

if [ -z $ZKSYNC_ENV ];
then
echo "$USAGE"
exit 1
fi

COMMAND=$1

case $COMMAND in
init)
f db-setup
echo "Database set up"
exit 0
;;
run)
f cargo run --bin zksync_data_restore --release -- --genesis --finite
;;
continue)
f cargo run --bin zksync_data_restore --release -- --continue --finite
;;
-h | --help)
echo "$USAGE"
exit 0
;;
*)
echo "Unknown Data Restore command"
echo "$USAGE"
exit 1
;;
esac

2 changes: 2 additions & 0 deletions docker/exit-tool/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# 1. Download keys
# 2. Run the binary with the keys directory mapped to the `/keys/setup` in container

0 comments on commit 70d27a0

Please sign in to comment.