Skip to content

Commit

Permalink
fix: ensure DB is always created, enhance docs
Browse files Browse the repository at this point in the history
  • Loading branch information
rhyslbw committed Nov 10, 2021
1 parent 55aa8ec commit 1529731
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 18 deletions.
94 changes: 77 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ build with local source by replacing the GitHub link with `.`
```console
DOCKER_BUILDKIT=1 \
docker build \
--build-arg BUILDKIT_INLINE_CACHE=1 \
--cache-from=inputoutput/cardano-rosetta:master \
-t inputoutput/cardano-rosetta:1.5.0 \
https://github.com/input-output-hk/cardano-rosetta.git#1.5.0
--build-arg BUILDKIT_INLINE_CACHE=1 \
--cache-from=inputoutput/cardano-rosetta:master \
-t inputoutput/cardano-rosetta:1.5.0 \
https://github.com/input-output-hk/cardano-rosetta.git#1.5.0
```

</details>
Expand All @@ -30,11 +30,11 @@ docker build \
```console
DOCKER_BUILDKIT=1 \
docker build \
--build-arg BUILDKIT_INLINE_CACHE=1 \
--build-arg NETWORK=testnet \
--cache-from=inputoutput/cardano-rosetta:master \
-t inputoutput/cardano-rosetta:1.5.0-testnet \
https://github.com/input-output-hk/cardano-rosetta.git#1.5.0
--build-arg BUILDKIT_INLINE_CACHE=1 \
--build-arg NETWORK=testnet \
--cache-from=inputoutput/cardano-rosetta:master \
-t inputoutput/cardano-rosetta:1.5.0-testnet \
https://github.com/input-output-hk/cardano-rosetta.git#1.5.0
```

</details>
Expand Down Expand Up @@ -105,18 +105,77 @@ following approached:

#### 1. Apply a Trusted `cardano-db-sync` Snapshot
Run the build command with the addition of an argument providing a version and network-specific
link, sourced from the
`cardano-db-sync` [release
notes](https://github.com/input-output-hk/cardano-db-sync/releases). For example version 11 on
_testnet_, captured at block `3022711`:
link, sourced from the `cardano-db-sync` [release notes](https://github.com/input-output-hk/cardano-db-sync/releases).
For example:

##### Build
<details open>
<summary>mainnet</summary>

```console
DOCKER_BUILDKIT=1 \
docker build \
--build-arg BUILDKIT_INLINE_CACHE=1 \
--build-arg SNAPSHOT_URL=https://update-cardano-mainnet.iohk.io/cardano-db-sync/11/db-sync-snapshot-schema-11-block-6426045-x86_64.tgz \
--cache-from=inputoutput/cardano-rosetta:master \
-t inputoutput/cardano-rosetta:1.5.0-apply-snapshot \
https://github.com/input-output-hk/cardano-rosetta.git#1.5.0
```

</details>

<details>
<summary>testnet</summary>

```console
DOCKER_BUILDKIT=1 \
docker build \
--build-arg BUILDKIT_INLINE_CACHE=1 \
--build-arg NETWORK=testnet \
--build-arg SNAPSHOT_URL=https://updates-cardano-testnet.s3.amazonaws.com/cardano-db-sync/11/db-sync-snapshot-schema-11-block-3022711-x86_64.tgz \
--cache-from=inputoutput/cardano-rosetta:master \
-t inputoutput/cardano-rosetta:1.5.0-testnet-apply-snapshot \
https://github.com/input-output-hk/cardano-rosetta.git#1.5.0
```

</details>

##### Run

<details open>
<summary>mainnet</summary>

```console
docker run \
--name cardano-rosetta \
-p 8080:8080 \
-v cardano-rosetta:/data \
--shm-size=2g \
inputoutput/cardano-rosetta:1.5.0-apply-snapshot
```
--build-arg SNAPSHOT_URL=https://updates-cardano-testnet.s3.amazonaws.com/cardano-db-sync/11/db-sync-snapshot-schema-11-block-3022711-x86_64.tgz

</details>

<details>
<summary>testnet</summary>

```console
docker run \
--name cardano-rosetta-testnet \
-p 8081:8080 \
-v cardano-rosetta-testnet:/data \
--shm-size=2g \
inputoutput/cardano-rosetta:1.5.0-testnet-apply-snapshot
```
... then start a container as per usual.

</details>

:information_source: _Build a new image as per the [standard build instructions] if you need to
recreate the container, otherwise the data will be dropped and restored again._

:information_source: _The snapshot will not be applied if there is no prior `cardano-node` state,
since the benefit of using the snapshot would be eliminated given `cardano-db-sync` would be
rolling back to genesis. For best results, ensure the node is close to the network tip prior to
since the benefit of using it would be eliminated given `cardano-db-sync` rolls back to genesis
under these conditions. For best results, ensure the node is close to the network tip prior to
upgrading._

#### 2. Re-sync From Genesis
Expand Down Expand Up @@ -160,6 +219,7 @@ docker run --rm -v cardano-rosetta:/data ubuntu rm -rf /data/postgresql /data/db
[Docker run reference]: https://docs.docker.com/engine/reference/run/
[modes]: https://www.rosetta-api.org/docs/node_deployment.html#multiple-modes
[docs]: cardano-rosetta-server/README.md
[standard build instructions]: #build
[Construction API Documentation]: https://www.rosetta-api.org/docs/construction_api_introduction.html
[Data API Documentation]: https://www.rosetta-api.org/docs/data_api_introduction.html
[Cardano Rosetta Docs]: ./docs
Expand Down
4 changes: 3 additions & 1 deletion scripts/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ elif [ "$MODE" == "online" ]; then
else
echo 'Skipping snapshot restoration as cardano-node will be syncing from genesis';
fi
elif [ ! "$( gosu postgres psql -tAc "SELECT 1 FROM pg_database WHERE datname='${DB_NAME}'" )" = '1' ]; then
fi

if [ ! "$( gosu postgres psql -tAc "SELECT 1 FROM pg_database WHERE datname='${DB_NAME}'" )" = '1' ]; then
echo 'Initializing DB';
createDb
fi
Expand Down

0 comments on commit 1529731

Please sign in to comment.