Skip to content

Commit

Permalink
Run data-restorer without docker (#2240)
Browse files Browse the repository at this point in the history
* Introduce CONFIG_PATH_ENV and do not use unnecessary envs

Signed-off-by: deniallugo <[email protected]>

* Introduce pg_path_env

Signed-off-by: deniallugo <[email protected]>

* Use zksync_home for target

Signed-off-by: deniallugo <[email protected]>
  • Loading branch information
Deniallugo authored May 10, 2022
1 parent 1468bf6 commit 7ab9907
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
6 changes: 4 additions & 2 deletions core/bin/data_restore/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,13 @@ async fn main() {
vlog::info!("Restoring zkSync state from the contract");
let _vlog_guard = vlog::init();
let connection_pool = ConnectionPool::new(Some(1));
let config_opts = ETHClientConfig::from_env();

let opt = Opt::from_args();

let web3_url = opt.web3_url.unwrap_or_else(|| config_opts.web3_url());
let web3_url = opt.web3_url.unwrap_or_else(|| {
let config_opts = ETHClientConfig::from_env();
config_opts.web3_url()
});

let transport = Http::new(&web3_url).expect("failed to start web3 transport");

Expand Down
2 changes: 2 additions & 0 deletions docker/data-restore/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@ COPY docker/data-restore/data-restore-entry.sh /bin/
# Setup the environment
ENV ZKSYNC_HOME=/usr/src/zksync
ENV PATH="${ZKSYNC_HOME}/bin:${PATH}"
ENV CONFIG_PATH=/usr/src/configs
ENV PG_DUMP_PATH=/pg_restore

ENTRYPOINT ["data-restore-entry.sh"]
14 changes: 9 additions & 5 deletions docker/data-restore/data-restore-entry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ function migrate() {
diesel migration run
cd $ZKSYNC_HOME
}

cd $ZKSYNC_HOME

# Wait for the database to be ready.
Expand Down Expand Up @@ -67,14 +66,19 @@ esac
if [[ -n $PG_DUMP && "$COMMAND" == "--continue" ]]
then
# Do not drop db if the file doesn't exist.
[ -f /pg_restore/$PG_DUMP ] || { echo "$PG_DUMP not found" ; exit 1 ; }
[ -f $PG_DUMP_PATH/$PG_DUMP ] || { echo "$PG_DUMP_PATH/$PG_DUMP not found" ; exit 1 ; }

migrate

echo "Applying $PG_DUMP"
pg_restore -j 8 -d $DATABASE_URL --clean --if-exists /pg_restore/$PG_DUMP
pg_restore -j 8 -d $DATABASE_URL --clean --if-exists $PG_DUMP_PATH/$PG_DUMP
fi

CONFIG_FILE="/usr/src/configs/${NETWORK}.json"
if [[ -z $CONFIG_PATH ]]
then
CONFIG_FILE="${ZKSYNC_HOME}/docker/exit-tool/configs/${NETWORK}.json"
else
CONFIG_FILE="${CONFIG_PATH}/${NETWORK}.json"
fi

./target/release/zksync_data_restore $COMMAND $MODE --config $CONFIG_FILE --web3 $WEB3_URL || exit 1
$ZKSYNC_HOME/target/release/zksync_data_restore $COMMAND $MODE --config $CONFIG_FILE --web3 $WEB3_URL || exit 1

0 comments on commit 7ab9907

Please sign in to comment.