Skip to content

Commit

Permalink
Improve docker image size with a 2 stages image (paritytech#463)
Browse files Browse the repository at this point in the history
* Improve docker image size with a 2 stages image

* Minor doc updates

* Fix and reduce size of the docker image

* Fix paths in scripts
  • Loading branch information
chevdor authored and gavofyork committed Aug 3, 2018
1 parent 68f83a2 commit db46682
Show file tree
Hide file tree
Showing 13 changed files with 96 additions and 70 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
doc
target
38 changes: 38 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
FROM phusion/baseimage:0.10.1 as builder
LABEL maintainer "chevdor@gmail.com"
LABEL description="This is the build stage for Polkadot. Here we create the binary."

ARG PROFILE=release
WORKDIR /polkadot

COPY . /polkadot

RUN apt-get update && \
apt-get upgrade -y && \
apt-get install -y cmake pkg-config libssl-dev git

RUN curl https://sh.rustup.rs -sSf | sh -s -- -y && \
export PATH=$PATH:$HOME/.cargo/bin && \
cargo build --$PROFILE

# ===== SECOND STAGE ======

FROM phusion/baseimage:0.10.0
LABEL maintainer "chevdor@gmail.com"
LABEL description="This is the 2nd stage: a very small image where we copy the Polkadot binary."
ARG PROFILE=release
COPY --from=builder /polkadot/target/$PROFILE/polkadot /usr/local/bin

RUN mv /usr/share/ca* /tmp && \
rm -rf /usr/share/* && \
mv /tmp/ca-certificates /usr/share/ && \
rm -rf /usr/lib/python* && \
mkdir -p /root/.local/share/Polkadot && \
ln -s /root/.local/share/Polkadot /data

RUN rm -rf /usr/bin /usr/sbin

EXPOSE 30333 9933 9944
VOLUME ["/data"]

CMD ["/usr/local/bin/polkadot"]
9 changes: 4 additions & 5 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ Then build the code:

[source, shell]
----
./build.sh # Builds the WebAssembly binaries
./scripts/build.sh # Builds the WebAssembly binaries
cargo build # Builds all native code
----

Expand All @@ -118,7 +118,7 @@ The easiest/faster option is to use the latest image.
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:

[source, shell]
docker run --rm -it chevdor/polkadot:latest ./version
docker run --rm -it chevdor/polkadot:latest pokadot --version


.Polkadot arguments
Expand Down Expand Up @@ -149,8 +149,7 @@ You can either build it yourself (it takes a while...):

[source, shell]
----
cd docker
./build.sh
./docker/build.sh
----

=== Reporting issues
Expand All @@ -159,7 +158,7 @@ If you run into issues with polkadot when using docker, please run the following
(replace the tag with the appropriate one if you do not use latest):

[source, shell]
docker run --rm -it chevdor/polkadot:latest version
docker run --rm -it chevdor/polkadot:latest polkadot --version

This will show you the polkadot version as well as the git commit ref that was used to build your container.
Just paste that in the issue you create.
Expand Down
5 changes: 3 additions & 2 deletions ci/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ case $TARGET in

"wasm")
# Install prerequisites and build all wasm projects
./init.sh
./build.sh
./scripts/init.sh
./scripts/build.sh
./scripts/build-demos.sh
;;
esac
33 changes: 0 additions & 33 deletions docker/Dockerfile

This file was deleted.

18 changes: 13 additions & 5 deletions docker/build.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
#!/usr/bin/env bash
set -e

pushd .

# The following line ensure we run from the project root
PROJECT_ROOT=`git rev-parse --show-toplevel`
cd $PROJECT_ROOT

# Find the current version from Cargo.toml
VERSION=`grep "^version" ../Cargo.toml | egrep -o "([0-9\.]+)"`
VERSION=`grep "^version" ./Cargo.toml | egrep -o "([0-9\.]+)"`
GITUSER=chevdor
GITREPO=polkadot

# Build the image
echo "Building ${GITREPO}:$VERSION docker image, hang on!"
time docker build --build-arg PROFILE=release -t ${GITUSER}/${GITREPO}:$VERSION .
echo "Building ${GITUSER}/${GITREPO}:latest docker image, hang on!"
time docker build -f ./docker/Dockerfile --build-arg PROFILE=release -t ${GITUSER}/${GITREPO}:latest .

# Show the list of available images for this repo
echo "Image is ready"
docker images | grep ${GITREPO}

echo -e "\nIf you just built the latest, you may want to update your tag:"
echo " $ docker tag ${GITUSER}/${GITREPO}:$VERSION ${GITUSER}/${GITREPO}:latest"
echo -e "\nIf you just built version ${VERSION}, you may want to update your tag:"
echo " $ docker tag ${GITUSER}/${GITREPO}:$VERSION ${GITUSER}/${GITREPO}:${VERSION}"

popd
8 changes: 0 additions & 8 deletions docker/cleanup.sh

This file was deleted.

4 changes: 2 additions & 2 deletions docker/readme-docker.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

Run the following command

docker run -d chevdor/polkadot:latest polkadot
docker run -d -P --name polkadot chevdor/polkadot:latest

=== Building the image

To build your own image from the source, you can run the following command:

./build.sh
./docker/build.sh

NOTE: Building the image takes a while. Count at least 30min on a good machine.
13 changes: 0 additions & 13 deletions docker/version

This file was deleted.

28 changes: 28 additions & 0 deletions scripts/build-demos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash

# This script assumes that all pre-requisites are installed.

set -e

PROJECT_ROOT=`git rev-parse --show-toplevel`
source `dirname "$0"`/common.sh

export CARGO_INCREMENTAL=0

# Save current directory.
pushd .

cd $ROOT

for DEMO in "${DEMOS[@]}"
do
echo "*** Building wasm binaries in $DEMO"
cd "$PROJECT_ROOT/$DEMO"

./build.sh

cd - >> /dev/null
done

# Restore initial directory.
popd
3 changes: 2 additions & 1 deletion build.sh → scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

set -e

PROJECT_ROOT=`git rev-parse --show-toplevel`
source `dirname "$0"`/common.sh

export CARGO_INCREMENTAL=0
Expand All @@ -16,7 +17,7 @@ cd $ROOT
for SRC in "${SRCS[@]}"
do
echo "*** Building wasm binaries in $SRC"
cd $SRC
cd "$PROJECT_ROOT/$SRC"

./build.sh

Expand Down
3 changes: 3 additions & 0 deletions common.sh → scripts/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ ROOT=`dirname "$0"`
SRCS=(
"polkadot/runtime/wasm"
"substrate/executor/wasm"
)

DEMOS=(
"demo/runtime/wasm"
"substrate/test-runtime/wasm"
"polkadot/test-parachains/"
Expand Down
2 changes: 1 addition & 1 deletion init.sh → scripts/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -e

echo "*** Initilising WASM build environment"
echo "*** Initialising WASM build environment"

rustup update nightly
rustup target add wasm32-unknown-unknown --toolchain nightly
Expand Down

0 comments on commit db46682

Please sign in to comment.