|
| 1 | +# Docker compose file to run a local devnet. |
| 2 | +# The devnet consists of a: |
| 3 | +# - Lotus node (2k build), |
| 4 | +# - Lotus miner (2k build), |
| 5 | +# - Forest node. |
| 6 | + |
| 7 | +version: "3.8" |
| 8 | + |
| 9 | +services: |
| 10 | + # Basic devnet initialisation. This will populate Lotus data volume with necessary artifacts |
| 11 | + # to run a devnet. The initialisation is a lengthy process and occurs only at the first |
| 12 | + # `docker-compose up`. |
| 13 | + lotus_init: |
| 14 | + build: |
| 15 | + context: . |
| 16 | + dockerfile: lotus.dockerfile |
| 17 | + volumes: |
| 18 | + - filecoin-proofs:${FILECOIN_PROOFS_DIR} |
| 19 | + - lotus-data:${LOTUS_DATA_DIR} |
| 20 | + env_file: |
| 21 | + - lotus.env |
| 22 | + entrypoint: ["/bin/bash", "-c" ] |
| 23 | + command: |
| 24 | + - | |
| 25 | + if [ ! -f ${LOTUS_DATA_DIR}/NODE_INITIALISED ]; then |
| 26 | + lotus fetch-params 2048 |
| 27 | + lotus-seed --sector-dir ${LOTUS_DATA_DIR}/genesis-sectors pre-seal --sector-size 2KiB --num-sectors 2 |
| 28 | + lotus-seed --sector-dir ${LOTUS_DATA_DIR}/genesis-sectors genesis new ${LOTUS_DATA_DIR}/localnet.json |
| 29 | + lotus-seed --sector-dir ${LOTUS_DATA_DIR}/genesis-sectors genesis add-miner ${LOTUS_DATA_DIR}/localnet.json ${LOTUS_DATA_DIR}/genesis-sectors/pre-seal-t01000.json |
| 30 | + touch ${LOTUS_DATA_DIR}/NODE_INITIALISED |
| 31 | + fi |
| 32 | +
|
| 33 | + # Lotus node that communicates with the miner and the Forest node. |
| 34 | + # The RPC and P2P listening ports are exposed so Forest does not necessarily need to be running inside Docker. |
| 35 | + # For development purposes it might be practical to comment out Forest part altogether and use a local build. |
| 36 | + lotus_node: |
| 37 | + depends_on: |
| 38 | + lotus_init: |
| 39 | + condition: service_completed_successfully |
| 40 | + build: |
| 41 | + context: . |
| 42 | + dockerfile: lotus.dockerfile |
| 43 | + healthcheck: |
| 44 | + test: >- |
| 45 | + curl -s -x post -h "content-type: application/json" |
| 46 | + --data '{ "jsonrpc": "2.0", "method": "filecoin.chainhead", "params": [], "id": 1 }' |
| 47 | + http://lotus_node:${LOTUS_RPC_PORT}/rpc/v0 || exit 1 |
| 48 | + interval: 10s |
| 49 | + retries: 10 |
| 50 | + timeout: 5s |
| 51 | + container_name: lotus |
| 52 | + networks: |
| 53 | + - devnet |
| 54 | + volumes: |
| 55 | + - filecoin-proofs:${FILECOIN_PROOFS_DIR} |
| 56 | + - lotus-data:${LOTUS_DATA_DIR} |
| 57 | + ports: |
| 58 | + - ${LOTUS_RPC_PORT}:${LOTUS_RPC_PORT} |
| 59 | + - ${LOTUS_P2P_PORT}:${LOTUS_P2P_PORT} |
| 60 | + env_file: |
| 61 | + - lotus.env |
| 62 | + entrypoint: ["/bin/bash", "-c" ] |
| 63 | + command: |
| 64 | + - | |
| 65 | + lotus daemon --lotus-make-genesis=${LOTUS_DATA_DIR}/devgen.car --genesis-template=${LOTUS_DATA_DIR}/localnet.json --bootstrap=false |
| 66 | +
|
| 67 | + # Lotus miner container. It communicates only with Lotus and not with Forest. |
| 68 | + lotus_miner: |
| 69 | + depends_on: |
| 70 | + lotus_node: |
| 71 | + condition: service_healthy |
| 72 | + build: |
| 73 | + context: . |
| 74 | + dockerfile: lotus.dockerfile |
| 75 | + container_name: lotus-miner |
| 76 | + healthcheck: |
| 77 | + test: >- |
| 78 | + curl -s http://lotus-miner:${MINER_RPC_PORT} || exit 1 |
| 79 | + interval: 20s |
| 80 | + retries: 5 |
| 81 | + start_period: 6000s |
| 82 | + timeout: 10s |
| 83 | + networks: |
| 84 | + - devnet |
| 85 | + volumes: |
| 86 | + - filecoin-proofs:${FILECOIN_PROOFS_DIR} |
| 87 | + - lotus-data:${LOTUS_DATA_DIR} |
| 88 | + ports: |
| 89 | + - ${MINER_RPC_PORT}:${MINER_RPC_PORT} |
| 90 | + env_file: |
| 91 | + - lotus-miner.env |
| 92 | + restart: on-failure # lotus node might not be ready |
| 93 | + entrypoint: ["/bin/bash", "-c" ] |
| 94 | + command: |
| 95 | + - | |
| 96 | + if [ ! -f ${LOTUS_DATA_DIR}/MINER_INITIALISED ]; then |
| 97 | + lotus wallet import --as-default ${LOTUS_DATA_DIR}/genesis-sectors/pre-seal-t01000.key |
| 98 | + lotus-miner init --genesis-miner --actor=t01000 --sector-size=2KiB --pre-sealed-sectors=${LOTUS_DATA_DIR}/genesis-sectors --pre-sealed-metadata=${LOTUS_DATA_DIR}/genesis-sectors/pre-seal-t01000.json --nosync |
| 99 | + touch ${LOTUS_DATA_DIR}/MINER_INITIALISED |
| 100 | + fi |
| 101 | + lotus-miner run --nosync |
| 102 | +
|
| 103 | + # This container dumps relevant (for Forest) Lotus configuration to the shared volume. |
| 104 | + lotus_config: |
| 105 | + depends_on: |
| 106 | + lotus_node: |
| 107 | + condition: service_healthy |
| 108 | + build: |
| 109 | + context: . |
| 110 | + dockerfile: lotus.dockerfile |
| 111 | + volumes: |
| 112 | + - lotus-data:${LOTUS_DATA_DIR} |
| 113 | + entrypoint: ["/bin/bash", "-c" ] |
| 114 | + env_file: |
| 115 | + - lotus.env |
| 116 | + networks: |
| 117 | + - devnet |
| 118 | + command: |
| 119 | + - lotus net id > ${LOTUS_DATA_DIR}/PEER_ID |
| 120 | + |
| 121 | + forest: |
| 122 | + user: root |
| 123 | + depends_on: |
| 124 | + lotus_config: |
| 125 | + condition: service_completed_successfully |
| 126 | + build: |
| 127 | + context: ../../. |
| 128 | + dockerfile: Dockerfile |
| 129 | + container_name: forest |
| 130 | + healthcheck: |
| 131 | + test: | |
| 132 | + export TOKEN=$$(cat ${FOREST_DATA_DIR}/token.jwt) |
| 133 | + export FULLNODE_API_INFO=$$TOKEN:/ip4/127.0.0.1/tcp/${FOREST_RPC_PORT}/http |
| 134 | + forest-cli sync status || exit 1 |
| 135 | + interval: 10s |
| 136 | + retries: 10 |
| 137 | + timeout: 5s |
| 138 | + start_period: 15s |
| 139 | + volumes: |
| 140 | + - lotus-data:${LOTUS_DATA_DIR} |
| 141 | + - filecoin-proofs:${FILECOIN_PROOFS_DIR} |
| 142 | + - forest-data:${FOREST_DATA_DIR} |
| 143 | + - ./forest_config.toml.tpl:/forest/forest_config.toml.tpl |
| 144 | + environment: |
| 145 | + - FIL_PROOFS_PARAMETER_CACHE=${FILECOIN_PROOFS_DIR} |
| 146 | + networks: |
| 147 | + - devnet |
| 148 | + ports: |
| 149 | + - ${FOREST_RPC_PORT}:${FOREST_RPC_PORT} |
| 150 | + entrypoint: ["/bin/bash", "-c" ] |
| 151 | + command: |
| 152 | + - | |
| 153 | + set -eu |
| 154 | + if [ ! -f ${FOREST_DATA_DIR}/forest_config.toml ]; then |
| 155 | + export NETWORK_NAME=$$(grep -o \"localnet.*\" ${LOTUS_DATA_DIR}/localnet.json) |
| 156 | + cp /forest/forest_config.toml.tpl ${FOREST_DATA_DIR}/forest_config.toml |
| 157 | + echo name = $$NETWORK_NAME >> ${FOREST_DATA_DIR}/forest_config.toml |
| 158 | + fi |
| 159 | + forest --genesis ${LOTUS_DATA_DIR}/devgen.car --config ${FOREST_DATA_DIR}/forest_config.toml --save-token ${FOREST_DATA_DIR}/token.jwt --rpc-address 0.0.0.0:${FOREST_RPC_PORT} |
| 160 | +
|
| 161 | + # At the moment of writing, Forest was not able to connect to a devnet node using its config. |
| 162 | + # This is a workaround to force the connection. |
| 163 | + forest_connecter: |
| 164 | + user: root |
| 165 | + depends_on: |
| 166 | + forest: |
| 167 | + condition: service_healthy |
| 168 | + build: |
| 169 | + context: ../../. |
| 170 | + dockerfile: Dockerfile |
| 171 | + volumes: |
| 172 | + - lotus-data:${LOTUS_DATA_DIR} |
| 173 | + - forest-data:${FOREST_DATA_DIR} |
| 174 | + networks: |
| 175 | + - devnet |
| 176 | + entrypoint: ["/bin/bash", "-c" ] |
| 177 | + command: |
| 178 | + - | |
| 179 | + set -eu |
| 180 | + export TOKEN=$$(cat ${FOREST_DATA_DIR}/token.jwt) |
| 181 | + export FULLNODE_API_INFO=$$TOKEN:/dns/forest/tcp/${FOREST_RPC_PORT}/http |
| 182 | + forest-cli net connect /dns/lotus/tcp/${LOTUS_P2P_PORT}/p2p/$$(cat ${LOTUS_DATA_DIR}/PEER_ID) |
| 183 | +
|
| 184 | +volumes: |
| 185 | + # Shared proof parameter files. It is re-used by both Lotus and Forest. |
| 186 | + filecoin-proofs: |
| 187 | + # Lotus node, miner and network data. |
| 188 | + lotus-data: |
| 189 | + forest-data: |
| 190 | + |
| 191 | +networks: |
| 192 | + devnet: |
0 commit comments