From bab23aa7b122c8a6e7c6b4e7c168f5f04538cb55 Mon Sep 17 00:00:00 2001 From: ldoublewood Date: Thu, 5 Dec 2019 11:31:32 +0800 Subject: [PATCH 1/3] add docker support --- .dockerignore | 1 + Dockerfile | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++ Makefile | 2 +- 3 files changed, 93 insertions(+), 1 deletion(-) create mode 120000 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 120000 index 000000000..3e4e48b0b --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +.gitignore \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..dab96ea34 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,91 @@ +FROM golang:1.13.4-buster +MAINTAINER ldoublewood + +ENV SRC_DIR /lotus + +RUN apt-get update && apt-get install -y && apt-get install -y ca-certificates llvm clang mesa-opencl-icd ocl-icd-opencl-dev + +RUN curl -sSf https://sh.rustup.rs | sh -s -- -y + + +# Get su-exec, a very minimal tool for dropping privileges, +# and tini, a very minimal init daemon for containers +ENV SUEXEC_VERSION v0.2 +ENV TINI_VERSION v0.18.0 +RUN set -x \ + && cd /tmp \ + && git clone https://github.com/ncopa/su-exec.git \ + && cd su-exec \ + && git checkout -q $SUEXEC_VERSION \ + && make \ + && cd /tmp \ + && wget -q -O tini https://github.com/krallin/tini/releases/download/$TINI_VERSION/tini \ + && chmod +x tini + +# Download packages first so they can be cached. +COPY go.mod go.sum $SRC_DIR/ +COPY extern/ $SRC_DIR/extern/ +RUN cd $SRC_DIR \ + && go mod download + +COPY Makefile $SRC_DIR + +# Because extern/filecoin-ffi building script need to get version number from git +COPY .git/ $SRC_DIR/.git/ +COPY .gitmodules $SRC_DIR/ + +# Download dependence first +RUN cd $SRC_DIR \ + && mkdir $SRC_DIR/build \ + && . $HOME/.cargo/env \ + && make clean \ + && make deps + + +COPY . $SRC_DIR + +# Build the thing. +RUN cd $SRC_DIR \ + && . $HOME/.cargo/env \ + && make + +# Now comes the actual target image, which aims to be as small as possible. +FROM busybox:1-glibc +MAINTAINER ldoublewood + +# Get the executable binary and TLS CAs from the build container. +ENV SRC_DIR /lotus +COPY --from=0 $SRC_DIR/lotus /usr/local/bin/lotus +COPY --from=0 $SRC_DIR/lotus-storage-miner /usr/local/bin/lotus-storage-miner +COPY --from=0 /tmp/su-exec/su-exec /sbin/su-exec +COPY --from=0 /tmp/tini /sbin/tini +COPY --from=0 /etc/ssl/certs /etc/ssl/certs + + +# This shared lib (part of glibc) doesn't seem to be included with busybox. +COPY --from=0 /lib/x86_64-linux-gnu/libdl-2.28.so /lib/libdl.so.2 +COPY --from=0 /lib/x86_64-linux-gnu/libutil-2.28.so /lib/libutil.so.1 +COPY --from=0 /usr/lib/x86_64-linux-gnu/libOpenCL.so.1.0.0 /lib/libOpenCL.so.1 +COPY --from=0 /lib/x86_64-linux-gnu/librt-2.28.so /lib/librt.so.1 +COPY --from=0 /lib/x86_64-linux-gnu/libgcc_s.so.1 /lib/libgcc_s.so.1 + +# WS port +EXPOSE 1234 +# P2P port +EXPOSE 5678 + + +# Create the home directory and switch to a non-privileged user. +ENV HOME_PATH /data +ENV PARAMCACHE_PATH /var/tmp/filecoin-proof-parameters + +RUN mkdir -p $HOME_PATH \ + && adduser -D -h $HOME_PATH -u 1000 -G users lotus \ + && chown lotus:users $HOME_PATH + + +VOLUME $HOME_PATH +VOLUME $PARAMCACHE_PATH + +# Execute the daemon subcommand by default +CMD ["/sbin/tini", "--", "lotus", "daemon"] diff --git a/Makefile b/Makefile index 90e5828ed..103a391df 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,7 @@ FFI_DEPS:=$(addprefix $(FFI_PATH),$(FFI_DEPS)) $(FFI_DEPS): build/.filecoin-install ; build/.filecoin-install: $(FFI_PATH) - $(MAKE) -C $(FFI_PATH) $(FFI_DEPS:$(FFI_PATH)%=%) + FFI_BUILD_FROM_SOURCE=1 $(MAKE) -C $(FFI_PATH) $(FFI_DEPS:$(FFI_PATH)%=%) @touch $@ MODULES+=$(FFI_PATH) From eda726ec34056a58cbd0054f0790fe1659e8627a Mon Sep 17 00:00:00 2001 From: ldoublewood Date: Thu, 5 Dec 2019 14:47:23 +0800 Subject: [PATCH 2/3] restore Makefile --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 103a391df..90e5828ed 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,7 @@ FFI_DEPS:=$(addprefix $(FFI_PATH),$(FFI_DEPS)) $(FFI_DEPS): build/.filecoin-install ; build/.filecoin-install: $(FFI_PATH) - FFI_BUILD_FROM_SOURCE=1 $(MAKE) -C $(FFI_PATH) $(FFI_DEPS:$(FFI_PATH)%=%) + $(MAKE) -C $(FFI_PATH) $(FFI_DEPS:$(FFI_PATH)%=%) @touch $@ MODULES+=$(FFI_PATH) From 63a5124f57060cc4aeeac638a6efd768699bc18b Mon Sep 17 00:00:00 2001 From: eshon <1017762+eshon@users.noreply.github.com> Date: Fri, 24 Jan 2020 21:47:14 +0100 Subject: [PATCH 3/3] Moving lotus PR 745 into a tools/dockers/ directory and adding some other examples --- tools/dockers/README.md | 3 ++ tools/dockers/docker-examples/README.md | 34 +++++++++++++++++++ .../api-hosted-debian-nginx/README.md | 10 ++++++ .../docker-examples/api-local-arch/README.md | 8 +++++ .../basic-miner-busybox/Dockerfile | 0 .../basic-miner-busybox/README.md | 4 +++ 6 files changed, 59 insertions(+) create mode 100644 tools/dockers/README.md create mode 100644 tools/dockers/docker-examples/README.md create mode 100644 tools/dockers/docker-examples/api-hosted-debian-nginx/README.md create mode 100644 tools/dockers/docker-examples/api-local-arch/README.md rename Dockerfile => tools/dockers/docker-examples/basic-miner-busybox/Dockerfile (100%) create mode 100644 tools/dockers/docker-examples/basic-miner-busybox/README.md diff --git a/tools/dockers/README.md b/tools/dockers/README.md new file mode 100644 index 000000000..66bfdc2e3 --- /dev/null +++ b/tools/dockers/README.md @@ -0,0 +1,3 @@ +## About + +In [docker-examples/](docker-examples/) are community-contributed Docker and Docker Compose examples. diff --git a/tools/dockers/docker-examples/README.md b/tools/dockers/docker-examples/README.md new file mode 100644 index 000000000..24a6c3d2f --- /dev/null +++ b/tools/dockers/docker-examples/README.md @@ -0,0 +1,34 @@ +## About + +In this `docker-examples/` directory are community-contributed Docker and Docker Compose examples. + +#### Example Use Cases + +- **For a miner** + - basic storage miner (`miner-basic-`) + - distributed storage miner +- **For API endpoints for building apps** + - local node for a developer (`api-local-`) + - hosted endpoint for apps / multiple developers (`api-hosted-`) +- **For a local devnet or shared devnet** + - basic local devnet (also see [lotus docs on setting up a local devnet](https://lotu.sh/en+setup-local-dev-net)) + - shared devnet + + +## Contributions + +- `miner-basic-busybox` - from @ldoublewood ([lotus PR 745](https://github.com/filecoin-project/lotus/pull/745)) +- `api-local-arch` - from @mateodelnorte +- `api-hosted-debian-nginx` - from @RTradeLtd + +#### More examples: +- [Issue 1143](https://github.com/filecoin-project/lotus/issues/1143) +- [PR 1047](https://github.com/filecoin-project/lotus/pull/1047/files) + +## Contributing + +:whale: Have a new type of Docker to share? + +Make a PR with a new folder for it, describe its purpose and link to the repo or provide the Docker files. Add it to *Contributions* above. + +:beetle: See a bug? File an Issue so we can keep these up-to-date. diff --git a/tools/dockers/docker-examples/api-hosted-debian-nginx/README.md b/tools/dockers/docker-examples/api-hosted-debian-nginx/README.md new file mode 100644 index 000000000..b41e399d4 --- /dev/null +++ b/tools/dockers/docker-examples/api-hosted-debian-nginx/README.md @@ -0,0 +1,10 @@ +## Description + +- **For API endpoints for building apps** + - hosted endpoint for multiple developers + +Another container spins up a simple block explorer. + +## Repo + +https://github.com/RTradeLtd/lotus-infra \ No newline at end of file diff --git a/tools/dockers/docker-examples/api-local-arch/README.md b/tools/dockers/docker-examples/api-local-arch/README.md new file mode 100644 index 000000000..a31403f68 --- /dev/null +++ b/tools/dockers/docker-examples/api-local-arch/README.md @@ -0,0 +1,8 @@ +## Description + +- **For API endpoints for building apps** + - local node for a developer + +## Repo + +https://github.com/mateodelnorte/filecoin-lotus-docker \ No newline at end of file diff --git a/Dockerfile b/tools/dockers/docker-examples/basic-miner-busybox/Dockerfile similarity index 100% rename from Dockerfile rename to tools/dockers/docker-examples/basic-miner-busybox/Dockerfile diff --git a/tools/dockers/docker-examples/basic-miner-busybox/README.md b/tools/dockers/docker-examples/basic-miner-busybox/README.md new file mode 100644 index 000000000..067f87d10 --- /dev/null +++ b/tools/dockers/docker-examples/basic-miner-busybox/README.md @@ -0,0 +1,4 @@ +## Description + +- **For a miner** + - basic storage miner