forked from matter-labs/zksync
-
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.
- Loading branch information
Showing
4 changed files
with
101 additions
and
1 deletion.
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
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,45 @@ | ||
# syntax=docker/dockerfile:experimental | ||
FROM rust:1.52 as builder | ||
RUN --mount=type=cache,target=/usr/local/cargo/registry \ | ||
cargo install sccache | ||
WORKDIR /usr/src/zksync | ||
COPY . . | ||
RUN --mount=type=cache,target=/usr/local/cargo/registry \ | ||
--mount=type=cache,target=/root/.cache/sccache \ | ||
RUSTC_WRAPPER=/usr/local/cargo/bin/sccache \ | ||
cargo build --release --bin zksync_data_restore | ||
|
||
FROM debian:buster-slim | ||
RUN apt update && apt install wget openssl npm curl libpq5 libpq-dev lsb-release -y | ||
# PostgreSQL Apt Repository is used to install the compatible psql version. | ||
# Create the file repository configuration: | ||
RUN sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' | ||
# Import the repository signing key: | ||
RUN wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - | ||
# Update the package lists: | ||
RUN apt update | ||
RUN apt install postgresql-12 -y | ||
RUN curl -sL https://deb.nodesource.com/setup_14.x | bash | ||
RUN apt install nodejs -y | ||
RUN npm install -g yarn | ||
|
||
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 | ||
|
||
COPY --from=builder /usr/src/zksync/ /usr/src/zksync/ | ||
|
||
# Copy configuration files for data restore. | ||
COPY docker/exit-tool/configs /usr/src/configs | ||
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 IN_DOCKER=true | ||
|
||
RUN cd $ZKSYNC_HOME && zk | ||
|
||
ENTRYPOINT ["data-restore-entry.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,53 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
cd $ZKSYNC_HOME | ||
|
||
zk db wait | ||
|
||
if [[ -z $COMMAND || -z $NETWORK || -z $WEB3_URL ]] | ||
then | ||
echo "Couldn't start the data restore, environment variables are missing" | ||
exit 1 | ||
fi | ||
|
||
case $COMMAND in | ||
genesis) | ||
echo "Resetting the database" | ||
zk db drop || true | ||
zk db basic-setup | ||
COMMAND="--genesis" | ||
;; | ||
continue) | ||
COMMAND="--continue" | ||
;; | ||
*) | ||
echo "Unknown Data Restore command" | ||
exit 1 | ||
;; | ||
esac | ||
|
||
case $NETWORK in | ||
mainnet | rinkeby | ropsten) | ||
;; | ||
*) | ||
echo "Unknown Ethereum network" | ||
exit 1 | ||
;; | ||
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 ; } | ||
|
||
zk db drop || true | ||
export $(cat $ZKSYNC_HOME/etc/env/docker.env | sed 's/#.*//g' | xargs) | ||
echo "Applying $PG_DUMP" | ||
pg_restore -j 8 -d $DATABASE_URL /pg_restore/$PG_DUMP | ||
fi | ||
|
||
CONFIG_FILE="/usr/src/configs/${NETWORK}.json" | ||
|
||
zk f ./target/release/zksync_data_restore $COMMAND --finite --config $CONFIG_FILE --web3 $WEB3_URL || exit 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