cardano-foundation / cardano-rosetta

An implementation of Rosetta for Cardano
https://www.rosetta-api.org
Apache License 2.0
98 stars 50 forks source link

chore: build the Haskell parts with haskell.nix #537

Open michalrus opened 1 year ago

michalrus commented 1 year ago

Description

We discovered with @rhyslbw that the current master no longer builds (fails on Haskell compilation), so the build process is not very reproducible.

Proposed Solution

Let’s reuse the 100% reproducible build definitions signed off by the cardano-node team. For both cardano-node, and cardano-db-sync.

Node’s build process is too complicated and fragile, and it's very hard to reproduce it reliably here. We can just use their definitions, which work, and are used in official releases.

We also have an option to disable the IOG binary cache, and build the world from source (see a comment added inside the Dockerfile).

Important Changes Introduced

The external interface doesn’t change.

Testing

The external interface doesn’t change.

michalrus commented 1 year ago

Okay, I think I made everything work now (including ARM builds! :apple:):

❯ docker top cardano-rosetta
UID                 PID                 PPID                C                   STIME               TTY                 TIME                CMD
102                 24931               24913               1                   13:19               pts/0               00:00:00            node /usr/bin/pm2-runtime start ecosystem.config.js --env production
102                 25070               24931               0                   13:19               ?                   00:00:00            /usr/lib/postgresql/12/bin/postgres -D /data/postgresql -c config_file=/etc/postgresql/12/main/postgresql.conf
102                 25071               24931               52                  13:19               ?                   00:00:07            /opt/cardano-node/lib/ld-linux-x86-64.so.2 /opt/cardano-node/exe/cardano-node run --config /config/cardano-node/config.json --database-path /data/node-db --socket-path /ipc/node.socket --topology /config/cardano-node/topology.json
102                 25082               24931               29                  13:19               ?                   00:00:04            /opt/cardano-db-sync/lib/ld-linux-x86-64.so.2 /opt/cardano-db-sync/exe/cardano-db-sync --config /config/cardano-db-sync/config.json --schema-dir /cardano-db-sync/schema/ --socket-path /ipc/node.socket --state-dir /data/db-sync
102                 25084               24931               18                  13:19               ?                   00:00:02            node /cardano-rosetta-server/dist/src/server/index.js
102                 25092               25070               0                   13:19               ?                   00:00:00            postgres: 12/main: checkpointer
102                 25093               25070               0                   13:19               ?                   00:00:00            postgres: 12/main: background writer
102                 25094               25070               0                   13:19               ?                   00:00:00            postgres: 12/main: walwriter
102                 25095               25070               0                   13:19               ?                   00:00:00            postgres: 12/main: autovacuum launcher
102                 25096               25070               0                   13:19               ?                   00:00:00            postgres: 12/main: stats collector
102                 25097               25070               0                   13:19               ?                   00:00:00            postgres: 12/main: logical replication launcher
102                 25509               25070               24                  13:19               ?                   00:00:00            postgres: 12/main: postgres cexplorer [local] idle

stdout/stderr:

Cardano Rosetta
Initializing DB
Starting
2023-10-03T11:19:19: PM2 log: Launching in no daemon mode
2023-10-03T11:19:19: PM2 log: App [postgres:0] starting in -fork mode-
2023-10-03T11:19:19: PM2 log: App [postgres:0] online
2023-10-03T11:19:19: PM2 log: App [cardano-node:1] starting in -fork mode-
2023-10-03T11:19:19: PM2 log: App [cardano-node:1] online
2023-10-03T11:19:19: PM2 log: App [cardano-db-sync:2] starting in -fork mode-
2023-10-03T11:19:19: PM2 log: App [cardano-db-sync:2] online
2023-10-03T11:19:19: PM2 log: App [cardano-rosetta-server:3] starting in -fork mode-
2023-10-03T11:19:19: PM2 log: App [cardano-rosetta-server:3] online

[…]

[559f2da7:cardano.node.ChainDB:Notice:36] [2023-10-03 11:19:43.37 UTC] Chain extended, new tip: 6c9c08b1ee251b60104b15c075e76f464ae6222359899ca24f894be9994c9397 at slot 9701
[db-sync-node:Info:68] [2023-10-03 11:19:43.77 UTC] Took a ledger snapshot at /data/db-sync/9998-5afa460d82.lstate. It took 0.004161365s.
[db-sync-node:Info:68] [2023-10-03 11:19:43.77 UTC] insertByronBlock: epoch 0, slot 9999, block 10000, hash e6a510ff8ae57fdc1c9d66692fbf32502e00e3f88ad94471f0c851b5ec5eb847
[559f2da7:cardano.node.ChainDB:Notice:36] [2023-10-03 11:19:45.56 UTC] Chain extended, new tip: 5193c28c91ce814b5cf85df25bb621a146adf7582290c72adeb853ac5f1ec41f at slot 10402

[…]
michalrus commented 1 year ago

It would be better to make the binary cache opt-in behind a Docker build arg, to better align with the Rosetta spec intent.

Fixed in 3eb8d5b92ec209539a77d84b9064c32e5d55478d.