Skip to content

Commit

Permalink
Docker image for data-restore
Browse files Browse the repository at this point in the history
  • Loading branch information
slumber committed Jun 24, 2021
1 parent a66e0ae commit 772759d
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 1 deletion.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
!docker/prover/prover-entry.sh
!docker/exit-tool/exit-tool-entry.sh
!docker/exit-tool/configs
!docker/data-restore/data-restore-entry.sh
!docker/keybase-secrets/entrypoint.sh
!docker/ci-integration-test/entrypoint.sh
!docker/zk/entrypoint.sh
Expand Down
45 changes: 45 additions & 0 deletions docker/data-restore/Dockerfile
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"]
53 changes: 53 additions & 0 deletions docker/data-restore/data-restore-entry.sh
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
3 changes: 2 additions & 1 deletion infrastructure/zk/src/docker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ const IMAGES = [
'dev-liquidity-token-watcher',
'ci-integration-test',
'zk-environment',
'event-listener'
'event-listener',
'data-restore'
];

async function dockerCommand(command: 'push' | 'build', image: string) {
Expand Down

0 comments on commit 772759d

Please sign in to comment.