Skip to content

Commit 7a93c1a

Browse files
author
Christian Groeschel
authored
Merge pull request #191 from DataHighway-DHX/christian/dockerBuilds
MMD-1102 multi staged slim docker builds
2 parents ad83af6 + 2a2f92b commit 7a93c1a

19 files changed

Lines changed: 971 additions & 41 deletions

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**/target

.gitignore

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,3 @@ datahighway
1010
pallets/.DS_Store
1111
.DS_Store
1212
.env
13-
.env.babe.json
14-
.env.gran.json
15-
16-
*-babe.json
17-
*-gran.json

Dockerfile

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
1-
FROM debian:buster
1+
# build stage
2+
FROM rust as builder
3+
# create a project folder
4+
WORKDIR /dhx/node
25

3-
ARG CHAIN_VERSION
4-
ENV _CHAIN_VERSION=${CHAIN_VERSION}
5-
RUN echo "DataHighway chain version ${_CHAIN_VERSION}"
6-
7-
WORKDIR /dhx
8-
9-
# FIXME - only copy necessary files to reduce size of image, and try using intermediate stages again
106
COPY . .
117

128
RUN apt-get update && apt-get install -y build-essential wget cmake pkg-config libssl-dev \
139
openssl git gcc clang libclang-dev curl vim unzip screen bash \
1410
&& curl https://getsubstrate.io -sSf | bash -s -- --fast \
15-
&& . ~/.cargo/env \
1611
&& wget -O - https://sh.rustup.rs | sh -s -- -y \
1712
&& PATH=$PATH:/root/.cargo/bin \
1813
&& rustup update stable \
@@ -25,4 +20,11 @@ RUN apt-get update && apt-get install -y build-essential wget cmake pkg-config l
2520
&& rustc --version \
2621
&& cargo build --release
2722

28-
WORKDIR /dhx/scripts
23+
# runtime stage
24+
FROM rust as runtime
25+
# set path for docker scripts in case used, to override below default entrypoint
26+
WORKDIR /dhx/node/scripts
27+
28+
COPY --from=builder /dhx/node/target/release/datahighway /usr/local/bin
29+
30+
ENTRYPOINT ["/usr/local/bin/datahighway"]

docker-compose-dev.yml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ services:
1717
- 9933:9933 # RPC
1818
volumes:
1919
- basePath:/tmp
20-
- ./scripts:/dhx/scripts
20+
- ./scripts:/dhx/node/scripts
21+
- ./node/src/chain-built:/dhx/node/node/src/chain-built
2122
restart: always
2223
entrypoint:
2324
- ./docker-entrypoint-alice.sh
@@ -32,7 +33,8 @@ services:
3233
- 9934:9933
3334
volumes:
3435
- basePath:/tmp
35-
- ./scripts:/dhx/scripts
36+
- ./scripts:/dhx/node/scripts
37+
- ./node/src/chain-built:/dhx/node/node/src/chain-built
3638
restart: always
3739
entrypoint:
3840
- ./docker-entrypoint-bob.sh
@@ -47,7 +49,8 @@ services:
4749
- 9935:9933
4850
volumes:
4951
- basePath:/tmp
50-
- ./scripts:/dhx/scripts
52+
- ./scripts:/dhx/node/scripts
53+
- ./node/src/chain-built:/dhx/node/node/src/chain-built
5154
restart: always
5255
entrypoint:
5356
- ./docker-entrypoint-charlie.sh
@@ -62,7 +65,8 @@ services:
6265
- 9936:9933
6366
volumes:
6467
- basePath:/tmp
65-
- ./scripts:/dhx/scripts
68+
- ./scripts:/dhx/node/scripts
69+
- ./node/src/chain-built:/dhx/node/node/src/chain-built
6670
restart: always
6771
entrypoint:
6872
- ./docker-entrypoint-dave.sh
@@ -77,7 +81,8 @@ services:
7781
- 9937:9933
7882
volumes:
7983
- basePath:/tmp
80-
- ./scripts:/dhx/scripts
84+
- ./scripts:/dhx/node/scripts
85+
- ./node/src/chain-built:/dhx/node/node/src/chain-built
8186
restart: always
8287
entrypoint:
8388
- ./docker-entrypoint-eve.sh

node/src/chain-built/chain_def_dev.json

Lines changed: 163 additions & 0 deletions
Large diffs are not rendered by default.

node/src/chain-built/chain_def_local.json

Lines changed: 243 additions & 0 deletions
Large diffs are not rendered by default.

node/src/chain-built/chain_spec_dev.json

Lines changed: 194 additions & 0 deletions
Large diffs are not rendered by default.

node/src/chain-built/chain_spec_local.json

Lines changed: 324 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
#!/bin/bash
2+
CHAIN_VERSION=$1
23

3-
echo "Docker Build Chain Spec"
4+
echo "Build Chain Spec for ${CHAIN_VERSION}"
45

56
# Generate the chain specification JSON file from src/chain_spec.rs
7+
# Note that this requires the native binary built first
8+
# Pass network name as parameter 1 eg. ./build-chain-spec.sh dev
69
../target/release/datahighway build-spec \
710
--chain=${CHAIN_VERSION} > ../node/src/chain-built/chain_spec_${CHAIN_VERSION}.json
811
# Build "raw" chain definition for the new chain from it

scripts/docker-entrypoint-alice.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ echo "Node Key is ${NODE_KEY}"
55
echo "Node Env is ${NODE_ENV}"
66
echo "Chain Version is ${CHAIN_VERSION}"
77

8-
../target/release/datahighway --validator \
8+
/usr/local/bin/datahighway --validator \
99
--unsafe-ws-external \
1010
--unsafe-rpc-external \
1111
--rpc-cors=all \
1212
--base-path /tmp/polkadot-chains/alice \
1313
--keystore-path "/tmp/polkadot-chains/alice/keys" \
14-
--chain ../node/src/chain-built/chain_def_${CHAIN_VERSION}.json \
14+
--chain /dhx/node/node/src/chain-built/chain_def_${CHAIN_VERSION}.json \
1515
--node-key ${NODE_KEY} \
1616
--alice \
1717
--name "${NODE_ENV} Validator Alice" \

0 commit comments

Comments
 (0)