diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..1e107f52e --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +examples diff --git a/build/devnet/Makefile b/build/devnet/Makefile new file mode 100644 index 000000000..98b860e99 --- /dev/null +++ b/build/devnet/Makefile @@ -0,0 +1,34 @@ +################################################################################## +lotus_version?=1.17.1-rc2 +boost_version?=1.3.0-rc1 +docker_user?=filecoin + +lotus_test_image=$(docker_user)/lotus-test:$(lotus_version) +################################################################################## +lotus-$(lotus_version): + git clone --depth 1 --branch v$(lotus_version) https://github.com/filecoin-project/lotus $@ + +prepare/lotus-test: | lotus-$(lotus_version) + cd lotus-$(lotus_version) && docker build -f Dockerfile.lotus --target lotus-test -t $(lotus_test_image) . +.PHONY: prepare/lotus-test +################################################################################## +build/%: prepare/lotus-test + cd $* && make dbuild +push/%: prepare/lotus-test + cd $* && make dpush +################################################################################## +build/all: build/lotus build/lotus-miner build/boost build/boost-gui +.PHONY: build/all +################################################################################## +push/all: push/lotus push/lotus-miner push/boost push/boost-gui +.PHONY: push/all +################################################################################## +clean: clean/lotus-test +.PHONY: clean + +clean/lotus-test: + rm -rf lotus-$(lotus_version) +.PHONY: clean/lotus-test + +.EXPORT_ALL_VARIABLES: +################################################################################## diff --git a/build/devnet/README.md b/build/devnet/README.md new file mode 100644 index 000000000..a116f1d91 --- /dev/null +++ b/build/devnet/README.md @@ -0,0 +1,30 @@ +# Devnet docker images for lotus and boost + +This dir contains scripts for building docker images that are required to start the lotus devnet with the boost as a storage provider. It is a realization of [devnet guide](../../documentation/devnet.md) in docker containers. `lotus` and `lotus-miner` images are based on the [official lotus image file](https://github.com/filecoin-project/lotus/blob/master/Dockerfile.lotus). Because there is no image with lotus in debug mode published on Dockerhub so we rebuild lotus containers locally. + +NOTE: These docker images are for demo and devs ONLY. They MUST NOT/CAN NOT be used in production environments. + +## Building images: + +1. Select lotus version, for example: `lotus_version=1.17.1-rc2`. It must be the tag name of [the lotus git repo](https://github.com/filecoin-project/lotus/tags) without `v` prefix. +2. Select boost version, for example: `boost_version=1.3.0-rc1`. Docker images for the boost will be built on the current code base. The `boost_version` is just used to tag images. If you want to build images for a specific boost version then you have to checkout that version first. +3. Build images + +``` +make build/all lotus_version=1.17.1-rc2 boost_version=1.3.0-rc1 +``` +## Publishing images: + +1. Log in to docker with the `filecoin` user. +2. Publish +``` +make push/all lotus_version=1.17.1-rc2 boost_version=1.3.0-rc1 +``` +3. If you want to publish using a non `filecoin` account (for some testing purposes) + +``` +make push/all lotus_version=1.17.1-rc2 boost_version=1.3.0-rc1 docker_user= +``` +## How to run devnet in docker: + +Follow the instructions in the [docker-compose devnet guide](../../examples/devnet/README.md) diff --git a/build/devnet/boost-gui/Dockerfile b/build/devnet/boost-gui/Dockerfile new file mode 100644 index 000000000..32d90e087 --- /dev/null +++ b/build/devnet/boost-gui/Dockerfile @@ -0,0 +1,39 @@ +######################################################################################### +######################################################################################### +FROM node:16.16-alpine3.15 AS builder + +RUN apk --no-cache --update add git + +ARG BUILD_VERSION=0.1 +WORKDIR /src +RUN git clone --depth 1 --branch v${BUILD_VERSION} https://github.com/filecoin-project/boost + +WORKDIR /src/boost/react + +#TODO remove force after fixing npm dependencies +RUN npm install --force + +RUN npm run build +##################################################################################### +FROM nginx:1.23-alpine + +ARG BUILD_VERSION=0.1 + +LABEL org.opencontainers.image.version=$BUILD_VERSION \ + org.opencontainers.image.authors="Boost Dev Team" \ + name="boost-gui" \ + maintainer="Boost Dev Team" \ + vendor="Boost Dev Team" \ + version=$BUILD_VERSION \ + release=$BUILD_VERSION \ + summary="This image is used to host the boost-gui service" \ + description="This image is used to host the boost-gui service" + +EXPOSE 8000 +ENV BOOST_URL=http://boost:8080 + +COPY --from=builder /src/boost/react/build usr/share/nginx/html +COPY nginx.conf.in /app/nginx.conf.in +COPY entrypoint.sh /app/entrypoint.sh + +ENTRYPOINT ["/app/entrypoint.sh"] diff --git a/build/devnet/boost-gui/Makefile b/build/devnet/boost-gui/Makefile new file mode 100644 index 000000000..cdf63504f --- /dev/null +++ b/build/devnet/boost-gui/Makefile @@ -0,0 +1,17 @@ +##################################################################################### +service=$(docker_user)/boost-gui +version=$(boost_version) +########### DOCKER ################################################################## +tag=$(service):$(version) + +dbuild: + docker build -t $(tag) --build-arg BUILD_VERSION=$(version) . + +dpush: dbuild + docker push $(tag) + +dscan: dbuild + docker scan --accept-license $(tag) +##################################################################################### +.PHONY: + dbuild dpush dscan diff --git a/build/devnet/boost-gui/entrypoint.sh b/build/devnet/boost-gui/entrypoint.sh new file mode 100755 index 000000000..8d7ad27f0 --- /dev/null +++ b/build/devnet/boost-gui/entrypoint.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env sh +set -e + +echo Preparing config with BOOST_URL=${BOOST_URL} +cat /app/nginx.conf.in | envsubst '$BOOST_URL' > /etc/nginx/conf.d/default.conf + +echo Starting nginx +exec nginx -g 'daemon off;' diff --git a/build/devnet/boost-gui/nginx.conf.in b/build/devnet/boost-gui/nginx.conf.in new file mode 100644 index 000000000..9b8c2f654 --- /dev/null +++ b/build/devnet/boost-gui/nginx.conf.in @@ -0,0 +1,28 @@ +server { + listen 8000; + charset utf-8; + sendfile on; + root /usr/share/nginx/html; + + location / { + expires -1; + add_header Pragma "no-cache"; + add_header Cache-Control "no-store, no-cache, must-revalidate, post-check=0, pre-check=0"; + + try_files $uri $uri/ /index.html; + } + + location /graphql { + resolver 127.0.0.11 valid=30s; + proxy_pass ${BOOST_URL}/graphql; + } + + location /graphql/subscription { + resolver 127.0.0.11 valid=30s; + proxy_pass ${BOOST_URL}/graphql/subscription; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "Upgrade"; + proxy_set_header Host $host; + } +} diff --git a/build/devnet/boost/Dockerfile b/build/devnet/boost/Dockerfile new file mode 100644 index 000000000..186e2c034 --- /dev/null +++ b/build/devnet/boost/Dockerfile @@ -0,0 +1,64 @@ +######################################################################################### +######################################################################################### +ARG LOTUS_TEST_IMAGE=filecoin/lotus-test:latest +FROM ${LOTUS_TEST_IMAGE} as lotus-dev +######################################################################################### +FROM golang:1.18-bullseye as builder + +RUN apt update && apt install -y \ + build-essential \ + bzr pkg-config \ + clang \ + curl \ + gcc git \ + hwloc \ + jq \ + libhwloc-dev wget \ + mesa-opencl-icd \ + ocl-icd-opencl-dev + +WORKDIR /go/src/ + +ARG BUILD_VERSION=0.1 +RUN git clone --depth 1 --branch v${BUILD_VERSION} https://github.com/filecoin-project/boost + +RUN cd boost && make debug +######################################################################################### +FROM ubuntu:20.04 as runner + +RUN apt update && apt install -y \ + curl \ + hwloc \ + jq + +ARG BUILD_VERSION=0.1 + +LABEL org.opencontainers.image.version=$BUILD_VERSION \ + org.opencontainers.image.authors="Boost Dev Team" \ + name="boost-dev" \ + maintainer="Boost Dev Team" \ + vendor="Boost Dev Team" \ + version=$BUILD_VERSION \ + release=$BUILD_VERSION \ + summary="This image is used to host the boost-dev storage provider" \ + description="This image is used to host the boost-dev storage provider" + +WORKDIR /app +ENV BOOST_PATH /var/lib/boost +VOLUME /var/lib/boost +EXPOSE 8080 + +COPY --from=builder /go/src/boost/boostd /usr/local/bin/ +COPY --from=builder /go/src/boost/boost /usr/local/bin/ +COPY --from=builder /go/src/boost/boostx /usr/local/bin/ +COPY --from=lotus-dev /usr/local/bin/lotus /usr/local/bin/ +COPY --from=lotus-dev /usr/local/bin/lotus-miner /usr/local/bin/ +## Fix missing lib libhwloc.so.5 +RUN ls -1 /lib/x86_64-linux-gnu/libhwloc.so.* | head -n 1 | xargs -n1 -I {} ln -s {} /lib/x86_64-linux-gnu/libhwloc.so.5 +## Smoke test for the boost and lotus +RUN lotus -v && boost -v + +COPY entrypoint.sh /app/ +COPY sample/* /app/sample/ + +ENTRYPOINT ["./entrypoint.sh"] diff --git a/build/devnet/boost/Makefile b/build/devnet/boost/Makefile new file mode 100644 index 000000000..4dc33870d --- /dev/null +++ b/build/devnet/boost/Makefile @@ -0,0 +1,18 @@ +##################################################################################### +service=$(docker_user)/boost-dev +version=$(boost_version) +########### DOCKER ################################################################## +tag=$(service):$(version) + +dbuild: + docker build --build-arg LOTUS_TEST_IMAGE=$(lotus_test_image) --build-arg BUILD_VERSION=$(version) \ + -t $(tag) . + +dpush: dbuild + docker push $(tag) + +dscan: dbuild + docker scan --accept-license $(tag) +##################################################################################### +.PHONY: + dbuild dpush dscan diff --git a/build/devnet/boost/entrypoint.sh b/build/devnet/boost/entrypoint.sh new file mode 100755 index 000000000..57d29ae0e --- /dev/null +++ b/build/devnet/boost/entrypoint.sh @@ -0,0 +1,74 @@ +#!/usr/bin/env bash +set -e + +echo Wait for lotus is ready ... +lotus wait-api +echo Wait for lotus-miner is ready ... +lotus-miner wait-api +echo BOOST_PATH=$BOOST_PATH +export DEFAULT_WALLET=`lotus wallet default` +export FULLNODE_API_INFO=`lotus auth api-info --perm=admin | cut -f2 -d=` +export MINER_API_INFO=`lotus-miner auth api-info --perm=admin | cut -f2 -d=` + +if [ ! -f $BOOST_PATH/.init.boost ]; then + echo Init wallets ... + export COLLAT_WALLET=`lotus wallet new bls` + export PUBMSG_WALLET=`lotus wallet new bls` + export CLIENT_WALLET=`lotus wallet new bls` + echo MINER_API_INFO=$MINER_API_INFO + echo FULLNODE_API_INFO=$FULLNODE_API_INFO + echo PUBMSG_WALLET=$PUBMSG_WALLET + echo COLLAT_WALLET=$COLLAT_WALLET + + lotus send --from $DEFAULT_WALLET $COLLAT_WALLET 10 + lotus send --from $DEFAULT_WALLET $PUBMSG_WALLET 10 + lotus send --from $DEFAULT_WALLET $CLIENT_WALLET 10 + lotus wallet market add --from $DEFAULT_WALLET --address $CLIENT_WALLET 5 + lotus wallet market add --address $COLLAT_WALLET 5 + + until lotus-miner actor control set --really-do-it ${PUBMSG_WALLET}; do echo Waiting for storage miner API ready ...; sleep 1; done + + echo Init boost on first run ... + + boostd -vv --boost-repo $BOOST_PATH init --api-sealer=$MINER_API_INFO \ + --api-sector-index=$MINER_API_INFO \ + --wallet-publish-storage-deals=$PUBMSG_WALLET \ + --wallet-deal-collateral=$COLLAT_WALLET \ + --max-staging-deals-bytes=2000000000 + + # echo exit code: $? + + echo Setting port in boost config... + sed -i 's|ip4/0.0.0.0/tcp/0|ip4/0.0.0.0/tcp/50000|g' $BOOST_PATH/config.toml + + echo Done + touch $BOOST_PATH/.init.boost +fi + +if [ ! -f $BOOST_PATH/.register.boost ]; then + echo Temporary starting boost to get maddr... + + boostd -vv run &> $BOOST_PATH/boostd.log & + BOOST_PID=`echo $!` + echo Got boost PID = $BOOST_PID + + until cat $BOOST_PATH/boostd.log | grep maddr; do echo "Waiting for boost..."; sleep 1; done + echo Looks like boost started and initialized... + + echo Registering to lotus-miner... + MADDR=`cat $BOOST_PATH/boostd.log | grep maddr | cut -f3 -d"{" | cut -f1 -d:` + echo Got maddr=${MADDR} + + lotus-miner actor set-peer-id ${MADDR} + lotus-miner actor set-addrs /dns/boost/tcp/50000 + echo Registered + + touch $BOOST_PATH/.register.boost + echo Try to stop boost... + kill -15 $BOOST_PID || kill -9 $BOOST_PID + rm -f $BOOST_PATH/boostd.log + echo Super. DONE! Boostd is now configured and will be started soon +fi + +echo Starting boost in dev mode... +exec boostd -vv run diff --git a/build/devnet/boost/sample/make-a-deal.sh b/build/devnet/boost/sample/make-a-deal.sh new file mode 100755 index 000000000..e95277d76 --- /dev/null +++ b/build/devnet/boost/sample/make-a-deal.sh @@ -0,0 +1,138 @@ +#!/usr/bin/env bash +################################################################################### +# sample demo script for making a deal with boost client +################################################################################### +set -e +# colors +cb="\e[1m" +ci="\e[3m" +cn="\e[0m" +################################################################################### +printf "\n +###################################################################################\n \ +Hello to the demo script that makes a storage deal using the boost client\n \ +###################################################################################\n \ +1. The boost client needs to know how to connect to the lotus instance. \ +We need to set ${cb}FULLNODE_API_INFO${cn} env var. We have the lotus client here that will provide a connection token.\n \ + : ${ci}lotus auth api-info --perm=admin${cn} - returns lotus connection token \n\n" +read -rsp $'Press any key to export variable...\n' -n1 key +export `lotus auth api-info --perm=admin` + +printf "\nExported FULLNODE_API_INFO=$FULLNODE_API_INFO\n \ +###################################################################################\n" +################################################################################### +printf "2. The boost client needs to be initialized by calling \n${ci}boost init${cn} \n\n" +read -rsp $'Press any key to execute it...\n\n' -n1 key + +boost init + +printf "\n\nGreat. Boost client has been initialized.\n \ +###################################################################################\n" +################################################################################### +printf "3. Now add some funds from lotus to boost wallet. We will use the lotus client:\n\n \ + : ${ci}lotus wallet default${cn} - returns default lotus wallet\n \ + : ${ci}boost wallet default${cn} - returns default wallet for the current boost client actor\n \ + : ${ci}lotus send --from=`lotus wallet default` `boost wallet default` 10${cn} - sends 10 FIL\n" +read -rsp $'Press any key to execute it...\n\n' -n1 key + +lotus send --from=`lotus wallet default` `boost wallet default` 10 + +printf "\n\nDone. Funds transfer was initiated\n \ +###################################################################################\n" +################################################################################### +printf "4. Now add some funds to the market actor\n \ + : ${ci}boostx market-add 1${cn}\n\n" +read -rsp $'Press any key to execute it...\n' -n1 key + +until boostx market-add 1; do printf "\nOpps, maybe funds not added yet.\nNeed to wait some time. \n"; read -rsp $'Press any key to try again...\n' -n1 key; done + +printf "\n\nYes. We can make a deal now.\n \ +###################################################################################\n" +################################################################################### +printf "5. Let's generate a sample file in ${ci}/app/public/sample.txt${cn}. We will use it as a demo file.\n\n" +read -rsp $'Press any key to generate it...\n\n' -n1 key +rm -f /app/public/sample.txt +for i in {1..57}; do echo "Hi Boost, $i times" >> /app/public/sample.txt; done + +printf "\n\nFile content:\n\n" +cat /app/public/sample.txt +printf "\n\n \ +###################################################################################\n" +################################################################################### + +printf "6. After that, you need to generate a car file for data you want to store on Filecoin (${ci}/app/public/sample.txt${cn}), \ +and note down its ${ci}payload-cid${cn}. \ +We will use the ${ci}boostx${cn} utility\n \ + : ${ci}boostx generate-car /app/public/sample.txt /app/public/sample.car${cn}\n\n" +read -rsp $'Press any key to execute it...\n\n' -n1 key + +boostx generate-car /app/public/sample.txt /app/public/sample.car + +PAYLOAD_CID=`boostx generate-car /app/public/sample.txt /app/public/sample.car | grep CID | cut -d: -f2 | xargs` +printf "\n\nDone. We noted payload-cid = ${ci}$PAYLOAD_CID${cn}\n \ +###################################################################################\n" +################################################################################### +printf "7. Then you need to calculate the commp and piece size for the generated car file:\n \ + : ${ci}boostx commp /app/public/sample.car${cn}\n\n" +read -rsp $'Press any key to execute it...\n\n' -n1 key + +boostx commp /app/public/sample.car + +COMMP_CID=`boostx commp /app/public/sample.car 2> /dev/null | grep CID | cut -d: -f2 | xargs` +PIECE=`boostx commp /app/public/sample.car 2> /dev/null | grep Piece | cut -d: -f2 | xargs` +CAR=`boostx commp /app/public/sample.car 2> /dev/null | grep Car | cut -d: -f2 | xargs` +printf "\n\nYes. We also have remembered these values:\n \ +Commp-cid = $COMMP_CID \n \ +Piece size = $PIECE \n \ +Car size = $CAR \n \ +###################################################################################\n" +################################################################################### +printf "8. That's it. We are ready to make the deal. \n \ + : ${ci}boost deal --verified=false --provider=t01000 \ +--http-url=http://demo-http-server/sample.car \ +--commp=$COMMP_CID --car-size=$CAR --piece-size=$PIECE \ +--payload-cid=$PAYLOAD_CID --storage-price 20000000000\n\n${cn}" +read -rsp $'Press any key to make the deal...\n\n' -n1 key + +until boost deal --verified=false \ + --provider=t01000 \ + --http-url=http://demo-http-server/sample.car \ + --commp=$COMMP_CID \ + --car-size=$CAR \ + --piece-size=$PIECE \ + --payload-cid=$PAYLOAD_CID --storage-price 20000000000 +do + printf "\nThe error has occured. Perhaps we should wait some time for funds to arrive into the market account.\n\n" + read -rsp $'Press any key to check the boost wallet...\n\n' -n1 key + boost init + read -rsp $'\n\nPress any key to try making the deal again...\n' -n1 key +done + +printf "\n\n ${cb}Congrats! You have made it.${cn}\n\n \ +###################################################################################\n" +###################################################################################" +printf "9. Deal has been made, and it will be published automatically after some time, but you can do it manually using boost's graphql API\n \ +: ${ci}curl -X POST -H \"Content-Type: application/json\" -d '{\"query\":\"mutation { dealPublishNow }\"}' http://localhost:8080/graphql/query ${cn}\n\n" +read -rsp $'Press any key to publish the deal...\n\n' -n1 key + +curl -X POST -H "Content-Type: application/json" -d '{"query":"mutation { dealPublishNow }"}' http://localhost:8080/graphql/query | jq +printf "\nDone.\n\n \ +###################################################################################\n" +################################################################################### +printf "10. To retrieve the file from the ${cb}lotus${cn} system you can use \n\ +${ci}lotus client retrieve${cn} or ${ci}lotus client cat${cn} commands.\n\ +: ${ci}lotus client cat --miner t01000 $PAYLOAD_CID ${cn}\n\n" + +read -rsp $'Press any key to show the file content...\n\n' -n1 key +until lotus client cat --miner t01000 $PAYLOAD_CID +do + printf "\nFile publishing may take time, please wait some time until the deal is finished and try again.\n\n" + read -rsp $'Press any key to try again...\n' -n1 key +done + +printf "\n\nIf you see a file content you have just completed the demo. You have succesfully:\n\n\ + 1) initiated the boost client\n\ + 2) prepared sample file\n\ + 3) sent the sample file to the Filecoin devnet\n\ + 4) retrieved the content of the file from it.\n\n\ +More info at ${cb}https://boost.filecoin.io${cn} or ${cb}https://github.com/filecoin-project/boost${cn}.\n\n\n" diff --git a/build/devnet/lotus-miner/Dockerfile b/build/devnet/lotus-miner/Dockerfile new file mode 100644 index 000000000..4507e492d --- /dev/null +++ b/build/devnet/lotus-miner/Dockerfile @@ -0,0 +1,32 @@ +ARG LOTUS_TEST_IMAGE=filecoin/lotus-test:latest +############################################################################# +FROM ${LOTUS_TEST_IMAGE} + +ARG BUILD_VERSION=0.1 + +LABEL org.opencontainers.image.version=$BUILD_VERSION \ + org.opencontainers.image.authors="Boost Dev Team" \ + name="lotus-miner-dev" \ + maintainer="Boost Dev Team" \ + vendor="Boost Dev Team" \ + version=$BUILD_VERSION \ + release=$BUILD_VERSION \ + summary="This image is used to host the lotus-miner dev service" \ + description="This image is used to host the lotus-miner dev service" + +EXPOSE 2345 +ENV LOTUS_SKIP_GENESIS_CHECK=_yes_ +ENV GENESIS_PATH=/var/lib/genesis +ENV SECTOR_SIZE=8388608 + +VOLUME /var/tmp/filecoin-proof-parameters +VOLUME /var/lib/genesis + +WORKDIR /app +RUN mkdir -p /app + +COPY entrypoint.sh /app + +USER root + +ENTRYPOINT ["./entrypoint.sh"] diff --git a/build/devnet/lotus-miner/Makefile b/build/devnet/lotus-miner/Makefile new file mode 100644 index 000000000..74f8bd1ee --- /dev/null +++ b/build/devnet/lotus-miner/Makefile @@ -0,0 +1,16 @@ +##################################################################################### +service=$(docker_user)/lotus-miner-dev +version?=$(lotus_version) +########### DOCKER ################################################################## +tag=$(service):$(version) +dbuild: + docker build -t $(tag) --build-arg LOTUS_TEST_IMAGE=$(lotus_test_image) --build-arg BUILD_VERSION=$(version) . + +dpush: dbuild + docker push $(tag) + +dscan: dbuild + docker scan --accept-license $(tag) +##################################################################################### +.PHONY: + dbuild dpush dscan diff --git a/build/devnet/lotus-miner/entrypoint.sh b/build/devnet/lotus-miner/entrypoint.sh new file mode 100755 index 000000000..e1041ebaa --- /dev/null +++ b/build/devnet/lotus-miner/entrypoint.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +set -e +echo Wait for lotus is ready ... +lotus wait-api +echo Lotus ready. Lets go +if [ ! -f $LOTUS_MINER_PATH/.init.miner ]; then + echo Import the genesis miner key ... + lotus wallet import --as-default $GENESIS_PATH/pre-seal-t01000.key + echo Set up the genesis miner ... + lotus-miner init --genesis-miner --actor=t01000 --sector-size=$SECTOR_SIZE --pre-sealed-sectors=$GENESIS_PATH --pre-sealed-metadata=$GENESIS_PATH/pre-seal-t01000.json --nosync + touch $LOTUS_MINER_PATH/.init.miner + echo Done +fi + +echo Starting lotus miner ... +exec lotus-miner run --nosync diff --git a/build/devnet/lotus/Dockerfile b/build/devnet/lotus/Dockerfile new file mode 100644 index 000000000..94fc9037d --- /dev/null +++ b/build/devnet/lotus/Dockerfile @@ -0,0 +1,32 @@ +ARG LOTUS_TEST_IMAGE=filecoin/lotus-test:latest +############################################################################# +FROM ${LOTUS_TEST_IMAGE} + +ARG BUILD_VERSION=0.1 + +LABEL org.opencontainers.image.version=$BUILD_VERSION \ + org.opencontainers.image.authors="Boost Dev Team" \ + name="lotus-dev" \ + maintainer="Boost Dev Team" \ + vendor="Boost Dev Team" \ + version=$BUILD_VERSION \ + release=$BUILD_VERSION \ + summary="This image is used to host the lotus dev service" \ + description="This image is used to host the lotus dev service" + +EXPOSE 1234 +ENV LOTUS_SKIP_GENESIS_CHECK=_yes_ +ENV GENESIS_PATH=/var/lib/genesis +ENV SECTOR_SIZE=8388608 + +VOLUME /var/tmp/filecoin-proof-parameters +VOLUME /var/lib/genesis + +WORKDIR /app +RUN mkdir -p /app + +COPY entrypoint.sh /app + +USER root + +ENTRYPOINT ["./entrypoint.sh"] diff --git a/build/devnet/lotus/Makefile b/build/devnet/lotus/Makefile new file mode 100644 index 000000000..8ac9eb49a --- /dev/null +++ b/build/devnet/lotus/Makefile @@ -0,0 +1,16 @@ +##################################################################################### +service=$(docker_user)/lotus-dev +version?=$(lotus_version) +########### DOCKER ################################################################## +tag=$(service):$(version) +dbuild: + docker build -t $(tag) --build-arg LOTUS_TEST_IMAGE=$(lotus_test_image) --build-arg BUILD_VERSION=$(version) . + +dpush: dbuild + docker push $(tag) + +dscan: dbuild + docker scan --accept-license $(tag) +##################################################################################### +.PHONY: + dbuild dpush dscan diff --git a/build/devnet/lotus/entrypoint.sh b/build/devnet/lotus/entrypoint.sh new file mode 100755 index 000000000..8c2552275 --- /dev/null +++ b/build/devnet/lotus/entrypoint.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash +set -e +if [ ! -f $LOTUS_PATH/.init.params ]; then + echo Initializing fetch params ... + lotus fetch-params $SECTOR_SIZE + touch $LOTUS_PATH/.init.params + echo Done +fi + +if [ ! -f $LOTUS_PATH/.init.genesis ]; then + echo Initializing pre seal ... + lotus-seed --sector-dir $GENESIS_PATH pre-seal --sector-size $SECTOR_SIZE --num-sectors 1 + echo Initializing genesis ... + lotus-seed --sector-dir $GENESIS_PATH genesis new $LOTUS_PATH/localnet.json + echo Initializing address ... + lotus-seed --sector-dir $GENESIS_PATH genesis add-miner $LOTUS_PATH/localnet.json $GENESIS_PATH/pre-seal-t01000.json + touch $LOTUS_PATH/.init.genesis + echo Done +fi + +echo Starting lotus deamon ... +exec lotus daemon --lotus-make-genesis=$LOTUS_PATH/devgen.car --genesis-template=$LOTUS_PATH/localnet.json --bootstrap=false diff --git a/examples/devnet/.env b/examples/devnet/.env new file mode 100644 index 000000000..3c060d4a5 --- /dev/null +++ b/examples/devnet/.env @@ -0,0 +1,5 @@ +DOCKER_USER=filecoin +LOTUS_IMAGE=${DOCKER_USER}/lotus-dev:1.17.1-rc2 +LOTUS_MINER_IMAGE=${DOCKER_USER}/lotus-miner-dev:1.17.1-rc2 +BOOST_IMAGE=${DOCKER_USER}/boost-dev:1.3.0-rc1 +BOOST_GUI_IMAGE=${DOCKER_USER}/boost-gui:1.3.0-rc1 \ No newline at end of file diff --git a/examples/devnet/.gitignore b/examples/devnet/.gitignore new file mode 100644 index 000000000..1269488f7 --- /dev/null +++ b/examples/devnet/.gitignore @@ -0,0 +1 @@ +data diff --git a/examples/devnet/Makefile b/examples/devnet/Makefile new file mode 100644 index 000000000..c1c66a960 --- /dev/null +++ b/examples/devnet/Makefile @@ -0,0 +1,20 @@ +################################################################################## +start: + docker compose up -d + docker compose logs -f +.PHONY: start +################################################################################## +ssh/boost: + docker compose exec boost /bin/bash +.PHONY: ssh/boost +################################################################################## +clean: clean/docker + rm -rf data +.PHONY: clean +clean/all: clean + rm -rf /var/tmp/filecoin-proof-parameters +.PHONY: clean/all +clean/docker: + docker compose down +.PHONY: clean/docker +################################################################################## diff --git a/examples/devnet/README.md b/examples/devnet/README.md new file mode 100644 index 000000000..35ad7a08b --- /dev/null +++ b/examples/devnet/README.md @@ -0,0 +1,45 @@ +# Devnet in docker + +The docker-compose file contains a realization of the [devnet guide](../../documentation/devnet.md) in docker containers. + +## To start devnet: + +1. Run +``` +docker compose up -d +``` +It will spin up `lotus`, `lotus-miner`, `boost`, `boost-gui` and `demo-http-server` containers. All temporary data will be saved in `./data` folder. +The initial setup could take up to 20 min or more (it takes time to download filecoin proof parameters). During the initial setup, it is normal to see error messages in the log. Containers are waiting for the lotus to be ready. It may timeout several times. Restart is expected to be managed by `docker`. + +2. Try opening the boost GUI http://localhost:8000 with a browser. Devnet is ready to operate when the URL opens and indicates no errors on the startup page. +Also, you can try to inspect the status using `docker compose logs -f`. + +## Making a deal + +The `boost` container is packed with `boost` and `lotus` clients. You can connect to the container with the command `docker compose exec boost /bin/bash` and follow instructions for [storing files with Boost guide](https://boost.filecoin.io/tutorials/how-to-store-files-with-boost-on-filecoin). But the recommended startup is to follow the semi-interactive demo first: +``` +# attach to a running boost container +docker compose exec boost /bin/bash + +# execute the demo script /app/sample/make-a-deal.sh +root@83260455bbd2:/app# ./sample/make-a-deal.sh +``` +## Accessing lotus from localhost + +By default the [docker-compose.yaml](./docker-compose.yaml) does not expose any port of the `lotus` container. To access the `lotus` from a local machine: +1. You can either expose `1234` in [docker-compose.yaml](./docker-compose.yaml) or find the IP of the `lotus` container using `docker inspect lotus | grep IPAddress` command. +2. Get the `FULLNODE_API_INFO` +``` +docker exec -it lotus lotus auth api-info --perm=admin +FULLNODE_API_INFO=eyJ...ms4:/dns/lotus/tcp/1234/http +``` +3. Change the `dns/lotus/tcp/1234/http` to `ip4/<127.0.0.1 or container's IP>/tcp/1234/http` for the use in `FULLNODE_API_INFO`. + +## Cleaning devnet + +To stop containers and drop everything: +``` +docker compose down --rmi all + +sudo rm -rf ./data +``` diff --git a/examples/devnet/docker-compose.yaml b/examples/devnet/docker-compose.yaml new file mode 100644 index 000000000..87a2b908b --- /dev/null +++ b/examples/devnet/docker-compose.yaml @@ -0,0 +1,82 @@ +version: '3.8' + +x-logging: + &default-logging + options: + max-size: '20m' + max-file: '3' + driver: json-file + +services: + lotus: + container_name: lotus + image: ${LOTUS_IMAGE} + # ports: + # - "1234:1234" + environment: + - LOTUS_API_LISTENADDRESS=/dns/lotus/tcp/1234/http + restart: unless-stopped + logging: *default-logging + volumes: + - ./data/lotus:/var/lib/lotus:rw + - ./data/genesis:/var/lib/genesis:rw + - /var/tmp/filecoin-proof-parameters:/var/tmp/filecoin-proof-parameters:rw + + lotus-miner: + container_name: lotus-miner + image: ${LOTUS_MINER_IMAGE} + # ports: + # - "2345:2345" + environment: + - LOTUS_API_LISTENADDRESS=/dns/lotus-miner/tcp/2345/http + - LOTUS_API_REMOTELISTENADDRESS=lotus-miner:2345 + - LOTUS_SEALING_BATCHPRECOMMITS=false + - LOTUS_SEALING_AGGREGATECOMMITS=false + - LOTUS_SUBSYSTEMS_ENABLEMARKETS=false + - LOTUS_SEALING_WAITDEALSDELAY=1h + restart: unless-stopped + logging: *default-logging + volumes: + - ./data/lotus-miner:/var/lib/lotus-miner:rw + - ./data/lotus:/var/lib/lotus:ro + - ./data/genesis:/var/lib/genesis:ro + - /var/tmp/filecoin-proof-parameters:/var/tmp/filecoin-proof-parameters:rw + + boost: + container_name: boost + image: ${BOOST_IMAGE} + # ports: + # - "8080:8080" + environment: + - LOTUS_PATH=/var/lib/lotus + - LOTUS_MINER_PATH=/var/lib/lotus-miner + restart: unless-stopped + logging: *default-logging + volumes: + - ./data/boost:/var/lib/boost:rw + - ./data/lotus:/var/lib/lotus:ro + - ./data/lotus-miner:/var/lib/lotus-miner:ro + - ./data/sample:/app/public:rw + + boost-gui: + container_name: boost-gui + image: ${BOOST_GUI_IMAGE} + ports: + - "8000:8000" + environment: + - BOOST_URL=http://boost:8080 + healthcheck: # try reloading nginx configuration if IP of the boost container changes + test: "nc -zv boost 8080 &> curr.ip && ( cmp curr.ip prev.ip || ( cp curr.ip prev.ip && kill -1 1 ))" + interval: "20s" + restart: unless-stopped + logging: *default-logging + + demo-http-server: + container_name: demo-http-server + image: nginx:1.23-alpine + # ports: + # - "8001:80" + restart: unless-stopped + logging: *default-logging + volumes: + - ./data/sample:/usr/share/nginx/html:ro