Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 8f414ab

Browse files
chevdorgavofyork
authored andcommitted
Add docker image (#375)
* Add Dockerfile Add documentation Ref #375 * Add PORT, VOLUME and reduce size of the docker image significantly Fix doc and reduce image size Fix #375 * Fix docker compose
1 parent 90a6dd5 commit 8f414ab

File tree

8 files changed

+196
-2
lines changed

8 files changed

+196
-2
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ substrate/pwasm-libc/Cargo.lock
1212
demo/runtime/wasm/target/
1313
**/._*
1414
.vscode
15-
polkadot.*
15+
polkadot.*
16+
.DS_Store

README.adoc

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
Implementation of a https://polkadot.network node in Rust.
88

9+
910
== To play
1011

1112
If you'd like to play with Polkadot, you'll need to install a client like this
@@ -46,6 +47,7 @@ polkadot --dev
4647

4748
You can muck around by cloning and building the http://github.com/paritytech/polka-ui and http://github.com/paritytech/polkadot-ui or just heading to https://polkadot.js.org/apps.
4849

50+
4951
== Local Two-node Testnet
5052

5153
If you want to see the multi-node consensus algorithm in action locally, then
@@ -62,6 +64,7 @@ polkadot --chain=local --validator --key Bob -d /tmp/bob --port 30334 --bootnode
6264
Ensure you replace `ALICE_BOOTNODE_ID_HERE` with the node ID from the output of
6365
the first terminal.
6466

67+
6568
== Hacking on Polkadot
6669

6770
If you'd actually like hack on Polkadot, you can just grab the source code and
@@ -74,7 +77,7 @@ rustup update nightly
7477
rustup target add wasm32-unknown-unknown --toolchain nightly
7578
rustup update stable
7679
cargo install --git https://github.com/alexcrichton/wasm-gc
77-
sudo apt install cmake pkg-config libssl-dev
80+
sudo apt install cmake pkg-config libssl-dev git
7881
----
7982

8083
Then, grab the Polkadot source code:
@@ -103,4 +106,91 @@ You can start a development chain with:
103106
[source, shell]
104107
cargo run -- --dev
105108

109+
110+
== Using Docker
111+
112+
=== The easiest way
113+
114+
The easiest/faster option is to use the latest image.
115+
116+
Let´s first check the version we have. The first time you run this command, the polkadot docker image will be downloaded. This takes a bit of time and bandwidth, be patient:
117+
118+
[source, shell]
119+
docker run --rm -it chevdor/polkadot:0.2.0 ./version
120+
121+
You can also pass any argument/flag that polkadot supports:
122+
123+
[source, shell]
124+
docker run --rm -it chevdor/polkadot:0.2.0 polkadot --name "PolkaDocker"
125+
126+
Once you are done experimenting and picking the best node name :) you can start polkadot as daemon, exposes the polkadot ports and mount a volume that will keep your blockchain data locally:
127+
128+
[source, shell]
129+
docker run -d -p 30333:30333 -p 9933:9933 -v /my/local/folder:/data chevdor/polkadot:0.2.0 polkadot
130+
131+
132+
=== Build your own image
133+
134+
To get up and running with the smallest footprint on your system, you may use the Polkadot Docker image.
135+
You can either build it yourself (it takes a while...):
136+
137+
[source, shell]
138+
----
139+
ccd docker
140+
./build.sh
141+
----
142+
143+
=== Reporting issues
144+
145+
If you run into issues with polkadot when using docker, please run the following command
146+
(replace the tag with the appropriate one if you do not use latest):
147+
148+
[source, shell]
149+
docker run --rm -it chevdor/polkadot:latest version
150+
151+
This will show you the polkadot version as well as the git commit ref that was used to build your container.
152+
Just paste that in the issue you create.
153+
154+
155+
== Shell completion
156+
157+
The Polkadot cli command supports shell auto-completion. For this to work, you will need to run the completion script matching you build and system.
158+
159+
Assuming you built a release version using `cargo build --release` and use `bash` run the following:
160+
161+
[source, shell]
162+
source target/release/completion-scripts/polkadot.bash
163+
164+
You can find completion scripts for:
165+
- bash
166+
- fish
167+
- zsh
168+
- elvish
169+
- powershell
170+
171+
To make this change persistent, you can proceed as follow:
172+
173+
=== First install
174+
175+
[source, shell]
176+
----
177+
COMPL_DIR=$HOME/.completion
178+
mkdir -p $COMPL_DIR
179+
cp -f target/release/completion-scripts/polkadot.bash $COMPL_DIR/
180+
echo "source $COMPL_DIR/polkadot.bash" >> $HOME/.bash_profile
181+
source $HOME/.bash_profile
182+
----
183+
184+
=== Update
185+
186+
When you build a new version of Polkadot, the following will ensure you auto-completion script matches the current binary:
187+
188+
[source, shell]
189+
----
190+
COMPL_DIR=$HOME/.completion
191+
mkdir -p $COMPL_DIR
192+
cp -f target/release/completion-scripts/polkadot.bash $COMPL_DIR/
193+
source $HOME/.bash_profile
194+
----
195+
106196
include::doc/packages.adoc[]

docker/Dockerfile

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
FROM phusion/baseimage:0.10.1
2+
LABEL maintainer "[email protected]"
3+
4+
ARG PROFILE=release
5+
6+
RUN mkdir -p polkadot && \
7+
apt-get update && \
8+
apt-get upgrade -y && \
9+
apt-get install -y cmake pkg-config libssl-dev git && \
10+
apt-get clean && \
11+
mkdir -p /root/.local/share/Polkadot && \
12+
ln -s /root/.local/share/Polkadot /data
13+
14+
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y && \
15+
export PATH=$PATH:$HOME/.cargo/bin && \
16+
rustup update nightly && \
17+
rustup target add wasm32-unknown-unknown --toolchain nightly && \
18+
rustup update stable && \
19+
cargo install --git https://github.com/alexcrichton/wasm-gc && \
20+
git clone https://github.com/paritytech/polkadot.git && \
21+
cd polkadot && \
22+
./build.sh && \
23+
cargo build --$PROFILE && \
24+
mv target/$PROFILE/polkadot /usr/local/bin && \
25+
cargo clean && \
26+
rm -rf /root/.cargo /root/.rustup /tmp/*
27+
28+
COPY version /polkadot
29+
WORKDIR /polkadot
30+
EXPOSE 30333 9933
31+
VOLUME ["/data"]
32+
33+
CMD ["/bin/sh", "polkadot"]

docker/build.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
# Find the current version from Cargo.toml
5+
VERSION=`grep "^version" ../Cargo.toml | egrep -o "([0-9\.]+)"`
6+
GITUSER=chevdor
7+
GITREPO=polkadot
8+
9+
# Build the image
10+
echo "Building ${GITREPO}:$VERSION docker image, hang on!"
11+
time docker build --build-arg PROFILE=release -t ${GITUSER}/${GITREPO}:$VERSION .
12+
13+
# Show the list of available images for this repo
14+
echo "Image is ready"
15+
docker images | grep ${GITREPO}
16+
17+
echo -e "\nIf you just built the latest, you may want to update your tag:"
18+
echo " $ docker tag ${GITUSER}/${GITREPO}:$VERSION ${GITUSER}/${GITREPO}:latest"

docker/cleanup.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
# This script helps reduce the size of the built image
3+
# It removes data that is not required.
4+
5+
export PATH=$PATH:$HOME/.cargo/bin
6+
7+
cargo clean
8+
rm -rf /root/.cargo /root/.rustup /tmp/*

docker/docker-compose.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
version: '3'
2+
services:
3+
polkadot:
4+
build:
5+
context: .
6+
ports:
7+
- "127.0.0.1:30333:30333/tcp"
8+
- "127.0.0.1:9933:9933/tcp"
9+
image: chevdor/polkadot:latest
10+
volumes:
11+
- "polkadot-data:/data"
12+
command: polkadot
13+
14+
volumes:
15+
polkadot-data:

docker/readme-docker.adoc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
== Polkadot Docker
3+
4+
=== Start a Polkadot docker container
5+
6+
Run the following command
7+
8+
docker run -d chevdor/polkadot:latest polkadot
9+
10+
=== Building the image
11+
12+
To build your own image from the source, you can run the following command:
13+
14+
./build.sh
15+
16+
NOTE: Building the image takes a while. Count at least 30min on a good machine.

docker/version

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env bash
2+
# This script show the polkadot version and commit ref that was
3+
# used to build the image.
4+
# If you report an issue, call this script to get all details.
5+
# This script will no longer be required once the polkadot cli
6+
# can report its commit ref.
7+
8+
echo "-----------------------------------------"
9+
printf "Polkadot Docker Container: "
10+
polkadot --version
11+
printf " "
12+
git rev-parse HEAD
13+
echo "-----------------------------------------"

0 commit comments

Comments
 (0)