Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker files #713

Merged
merged 27 commits into from
Aug 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
2c5a41b
Add docker build scripts
airenas Aug 17, 2022
bc1e82d
Fix lotus version in dockerfile
airenas Aug 17, 2022
c57b7cd
Add lotus, lotus-miner to boost image
airenas Aug 18, 2022
36af488
Make clearer var names
airenas Aug 18, 2022
01553ea
Fix nginx proxy
airenas Aug 18, 2022
5a43acb
Add sample script for making a demo deal
airenas Aug 18, 2022
13129d6
Add sample docker-compose for starting devnet
airenas Aug 18, 2022
c66d462
Decorate output of sample script
airenas Aug 18, 2022
dd5a14d
Add task to push all docker containers
airenas Aug 18, 2022
0c4ba86
Add info about building docker images
airenas Aug 18, 2022
d522193
Add info on how to inspect devnet in docker
airenas Aug 18, 2022
7f083c7
Fix port extract command
airenas Aug 18, 2022
b78d9e8
Fix typos
airenas Aug 18, 2022
ef2314b
Update scripts for docker compose v2
airenas Aug 19, 2022
3a93633
Fix typo
airenas Aug 19, 2022
3706af3
Expose default ports
airenas Aug 19, 2022
3bddb42
Add resolver for nginx docker dns
airenas Aug 19, 2022
0b1eb1f
Fix new lines
airenas Aug 19, 2022
8e9dfce
Update readme for devnet
airenas Aug 19, 2022
385c9c2
Add script on timer to reload nginx conf
airenas Aug 22, 2022
6c637a2
Fix problem with failing publishing
airenas Aug 30, 2022
4951b8d
Mimic devnet params from boost sample
airenas Aug 30, 2022
38bf867
Build boost from git source not from a local one
airenas Aug 30, 2022
eb78773
Add publish and retrieve tasks into demo script
airenas Aug 30, 2022
7a7d707
Update examples/devnet/docker-compose.yaml
airenas Aug 30, 2022
1f7a8bf
Update filecoin proofs dir for lotus-miner
airenas Aug 30, 2022
a7bbc49
Reduce WaitDealsDelay
airenas Aug 30, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
examples
34 changes: 34 additions & 0 deletions build/devnet/Makefile
Original file line number Diff line number Diff line change
@@ -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:
##################################################################################
30 changes: 30 additions & 0 deletions build/devnet/README.md
Original file line number Diff line number Diff line change
@@ -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=<some_user>
```
## How to run devnet in docker:

Follow the instructions in the [docker-compose devnet guide](../../examples/devnet/README.md)
39 changes: 39 additions & 0 deletions build/devnet/boost-gui/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
17 changes: 17 additions & 0 deletions build/devnet/boost-gui/Makefile
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions build/devnet/boost-gui/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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;'
28 changes: 28 additions & 0 deletions build/devnet/boost-gui/nginx.conf.in
Original file line number Diff line number Diff line change
@@ -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;
}
}
64 changes: 64 additions & 0 deletions build/devnet/boost/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
18 changes: 18 additions & 0 deletions build/devnet/boost/Makefile
Original file line number Diff line number Diff line change
@@ -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
74 changes: 74 additions & 0 deletions build/devnet/boost/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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
Loading