Improve docker image size with a 2 stages image (#463)

* Improve docker image size with a 2 stages image

* Minor doc updates

* Fix and reduce size of the docker image

* Fix paths in scripts
This commit is contained in:
Chevdor
2018-08-03 19:34:53 +02:00
committed by Gav Wood
parent 46c9333fff
commit 1bd19d8511
13 changed files with 96 additions and 70 deletions
-33
View File
@@ -1,33 +0,0 @@
FROM phusion/baseimage:0.10.1
LABEL maintainer "chevdor@gmail.com"
ARG PROFILE=release
RUN mkdir -p polkadot && \
apt-get update && \
apt-get upgrade -y && \
apt-get install -y cmake pkg-config libssl-dev git && \
apt-get clean && \
mkdir -p /root/.local/share/Polkadot && \
ln -s /root/.local/share/Polkadot /data
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y && \
export PATH=$PATH:$HOME/.cargo/bin && \
rustup update nightly && \
rustup target add wasm32-unknown-unknown --toolchain nightly && \
rustup update stable && \
cargo install --git https://github.com/alexcrichton/wasm-gc && \
git clone https://github.com/paritytech/polkadot.git && \
cd polkadot && \
./build.sh && \
cargo build --$PROFILE && \
mv target/$PROFILE/polkadot /usr/local/bin && \
cargo clean && \
rm -rf /root/.cargo /root/.rustup /tmp/*
COPY version /polkadot
WORKDIR /polkadot
EXPOSE 30333 9933 9944
VOLUME ["/data"]
CMD ["/bin/sh", "polkadot"]
+13 -5
View File
@@ -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
View File
@@ -1,8 +0,0 @@
#!/usr/bin/env bash
# This script helps reduce the size of the built image
# It removes data that is not required.
export PATH=$PATH:$HOME/.cargo/bin
cargo clean
rm -rf /root/.cargo /root/.rustup /tmp/*
+2 -2
View File
@@ -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
View File
@@ -1,13 +0,0 @@
#!/usr/bin/env bash
# This script show the polkadot version and commit ref that was
# used to build the image.
# If you report an issue, call this script to get all details.
# This script will no longer be required once the polkadot cli
# can report its commit ref.
echo "-----------------------------------------"
printf "Polkadot Docker Container: "
polkadot --version
printf " "
git rev-parse HEAD
echo "-----------------------------------------"