From f806ce80a451768c8c23aa1f9d10011791c7aa40 Mon Sep 17 00:00:00 2001 From: dylanVerstraete Date: Fri, 22 Jan 2021 16:10:58 +0100 Subject: [PATCH] move and create dockerfiles --- graphql/.env => .env | 4 +- .../docker-compose.yml => docker-compose.yml | 6 +- substrate-node/Cargo.lock | 70 +++++++++---------- substrate-node/Dockerfile | 55 +++++++++++++++ substrate-node/docker/Dockerfile.back | 32 +++++++++ substrate-node/node/Cargo.toml | 4 +- substrate-node/scripts/Dockerfile | 30 ++++++++ 7 files changed, 159 insertions(+), 42 deletions(-) rename graphql/.env => .env (95%) rename graphql/docker-compose.yml => docker-compose.yml (93%) create mode 100644 substrate-node/Dockerfile create mode 100644 substrate-node/docker/Dockerfile.back create mode 100644 substrate-node/scripts/Dockerfile diff --git a/graphql/.env b/.env similarity index 95% rename from graphql/.env rename to .env index c15ad0282..6c43175da 100644 --- a/graphql/.env +++ b/.env @@ -36,8 +36,8 @@ REDIS_URI=redis://localhost:6379/0 ########################### # Where the mapping scripts are located, relative to ./generated/indexer -MAPPINGS_LOCATION=../../mappings -# TYPES_JSON=../../client/types.json +MAPPINGS_LOCATION=./graphql/mappings +# TYPES_JSON=./api-client/types.json # Indexer GraphQL API endpoint to fetch indexed events INDEXER_ENDPOINT_URL=http://localhost:4000/graphql diff --git a/graphql/docker-compose.yml b/docker-compose.yml similarity index 93% rename from graphql/docker-compose.yml rename to docker-compose.yml index 3075fcb01..96a4e0734 100644 --- a/graphql/docker-compose.yml +++ b/docker-compose.yml @@ -17,7 +17,7 @@ services: image: hydra-kit:latest restart: unless-stopped build: - dockerfile: docker/Dockerfile.hydra + dockerfile: ./graphql/docker/Dockerfile.hydra context: ./ env_file: - .env @@ -43,7 +43,7 @@ services: - TYPES_JSON=/types.json volumes: - type: bind - source: /home/dylan/Projects/substrate-tfgrid/client/types.json + source: ./api-client/types.json target: /home/hydra-indexer/types.json depends_on: - db @@ -54,7 +54,7 @@ services: image: hydra-kit:latest restart: unless-stopped build: - dockerfile: docker/Dockerfile.hydra + dockerfile: ./graphql/docker/Dockerfile.hydra context: ./ env_file: - .env diff --git a/substrate-node/Cargo.lock b/substrate-node/Cargo.lock index c5186ec85..40086742f 100644 --- a/substrate-node/Cargo.lock +++ b/substrate-node/Cargo.lock @@ -3229,41 +3229,6 @@ dependencies = [ "void", ] -[[package]] -name = "node-template" -version = "2.0.0" -dependencies = [ - "frame-benchmarking", - "frame-benchmarking-cli", - "jsonrpc-core", - "node-template-runtime", - "pallet-transaction-payment-rpc", - "sc-basic-authorship", - "sc-cli", - "sc-client-api", - "sc-consensus", - "sc-consensus-aura", - "sc-executor", - "sc-finality-grandpa", - "sc-rpc", - "sc-rpc-api", - "sc-service", - "sc-transaction-pool", - "sp-api", - "sp-block-builder", - "sp-blockchain", - "sp-consensus", - "sp-consensus-aura", - "sp-core", - "sp-finality-grandpa", - "sp-inherents", - "sp-runtime", - "sp-transaction-pool", - "structopt", - "substrate-build-script-utils", - "substrate-frame-rpc-system", -] - [[package]] name = "node-template-runtime" version = "2.0.0" @@ -6585,6 +6550,41 @@ dependencies = [ "syn", ] +[[package]] +name = "substrate" +version = "2.0.0" +dependencies = [ + "frame-benchmarking", + "frame-benchmarking-cli", + "jsonrpc-core", + "node-template-runtime", + "pallet-transaction-payment-rpc", + "sc-basic-authorship", + "sc-cli", + "sc-client-api", + "sc-consensus", + "sc-consensus-aura", + "sc-executor", + "sc-finality-grandpa", + "sc-rpc", + "sc-rpc-api", + "sc-service", + "sc-transaction-pool", + "sp-api", + "sp-block-builder", + "sp-blockchain", + "sp-consensus", + "sp-consensus-aura", + "sp-core", + "sp-finality-grandpa", + "sp-inherents", + "sp-runtime", + "sp-transaction-pool", + "structopt", + "substrate-build-script-utils", + "substrate-frame-rpc-system", +] + [[package]] name = "substrate-bip39" version = "0.4.2" diff --git a/substrate-node/Dockerfile b/substrate-node/Dockerfile new file mode 100644 index 000000000..88b158027 --- /dev/null +++ b/substrate-node/Dockerfile @@ -0,0 +1,55 @@ +# Note: We don't use Alpine and its packaged Rust/Cargo because they're too often out of date, +# preventing them from being used to build Substrate/Polkadot. + +FROM phusion/baseimage:0.11 as builder +LABEL maintainer="chevdor@gmail.com" +LABEL description="This is the build stage for Substrate. Here we create the binary." + +ENV DEBIAN_FRONTEND=noninteractive + +ARG PROFILE=release +WORKDIR /substrate + +COPY . /substrate + +RUN apt-get update && \ + apt-get dist-upgrade -y -o Dpkg::Options::="--force-confold" && \ + apt-get install -y cmake pkg-config libssl-dev git clang + +RUN curl https://sh.rustup.rs -sSf | sh -s -- -y && \ + export PATH="$PATH:$HOME/.cargo/bin" && \ + rustup install nightly-2020-10-01 && \ + rustup target add wasm32-unknown-unknown --toolchain nightly-2020-10-01 && \ + rustup default stable && \ + cargo +nightly-2020-10-01 build "--$PROFILE" + +# ===== SECOND STAGE ====== + +FROM phusion/baseimage:0.11 +LABEL maintainer="chevdor@gmail.com" +LABEL description="This is the 2nd stage: a very small image where we copy the Substrate binary." +ARG PROFILE=release + +RUN mv /usr/share/ca* /tmp && \ + rm -rf /usr/share/* && \ + mv /tmp/ca-certificates /usr/share/ && \ + useradd -m -u 1000 -U -s /bin/sh -d /substrate substrate && \ + mkdir -p /substrate/.local/share/substrate && \ + chown -R substrate:substrate /substrate/.local && \ + ln -s /substrate/.local/share/substrate /data + +COPY --from=builder /substrate/target/$PROFILE/substrate /usr/local/bin + +# checks +RUN ldd /usr/local/bin/substrate && \ + /usr/local/bin/substrate --version + +# Shrinking +RUN rm -rf /usr/lib/python* && \ + rm -rf /usr/bin /usr/sbin /usr/share/man + +USER substrate +EXPOSE 30333 9933 9944 9615 +VOLUME ["/data"] + +CMD ["/usr/local/bin/substrate --ws-external"] \ No newline at end of file diff --git a/substrate-node/docker/Dockerfile.back b/substrate-node/docker/Dockerfile.back new file mode 100644 index 000000000..2b33bf927 --- /dev/null +++ b/substrate-node/docker/Dockerfile.back @@ -0,0 +1,32 @@ +FROM debian:stretch-slim +# show backtraces +ENV RUST_BACKTRACE 1 + +# install tools and dependencies +RUN apt-get update && \ + DEBIAN_FRONTEND=noninteractive apt-get upgrade -y && \ + DEBIAN_FRONTEND=noninteractive apt-get install -y \ + libssl1.1 \ + ca-certificates \ + glibc \ + curl && \ + +# apt cleanup + apt-get autoremove -y && \ + apt-get clean && \ + find /var/lib/apt/lists/ -type f -not -name lock -delete; \ +# add user + useradd -m -u 1000 -U -s /bin/sh -d /node-template substrate + +# add substrate binary to docker image +COPY ./node-template /usr/local/bin + +USER substrate + +# check if executable works in this container +RUN /usr/local/bin/node-template --version + +EXPOSE 30333 9933 9944 +VOLUME ["./node-template"] + +ENTRYPOINT ["/usr/local/bin/node-template --ws-external"] \ No newline at end of file diff --git a/substrate-node/node/Cargo.toml b/substrate-node/node/Cargo.toml index b30aea1af..415968479 100644 --- a/substrate-node/node/Cargo.toml +++ b/substrate-node/node/Cargo.toml @@ -5,12 +5,12 @@ description = 'A fresh FRAME-based Substrate node, ready for hacking.' edition = '2018' homepage = 'https://substrate.dev' license = 'Unlicense' -name = 'node-template' +name = 'substrate' repository = 'https://github.com/substrate-developer-hub/substrate-node-template/' version = '2.0.0' [[bin]] -name = 'node-template' +name = 'substrate' [package.metadata.docs.rs] targets = ['x86_64-unknown-linux-gnu'] diff --git a/substrate-node/scripts/Dockerfile b/substrate-node/scripts/Dockerfile new file mode 100644 index 000000000..2c3f21ff0 --- /dev/null +++ b/substrate-node/scripts/Dockerfile @@ -0,0 +1,30 @@ +FROM debian:stretch-slim +# show backtraces +ENV RUST_BACKTRACE 1 + +# install tools and dependencies +RUN apt-get update && \ + DEBIAN_FRONTEND=noninteractive apt-get upgrade -y && \ + DEBIAN_FRONTEND=noninteractive apt-get install -y \ + libssl1.1 \ + ca-certificates \ + curl && \ +# apt cleanup + apt-get autoremove -y && \ + apt-get clean && \ + find /var/lib/apt/lists/ -type f -not -name lock -delete; \ +# add user + useradd -m -u 1000 -U -s /bin/sh -d /node-template substrate + +# add substrate binary to docker image +COPY ../target/release/node-template /usr/local/bin + +USER substrate + +# check if executable works in this container +RUN /usr/local/bin/node-template --version + +EXPOSE 30333 9933 9944 +VOLUME ["../target/release/node-template"] + +ENTRYPOINT ["/usr/local/bin/node-template --ws-external"] \ No newline at end of file