mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 04:11:07 +00:00
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:
@@ -0,0 +1,2 @@
|
||||
doc
|
||||
target
|
||||
@@ -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"]
|
||||
@@ -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
|
||||
----
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"]
|
||||
@@ -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
|
||||
|
||||
@@ -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/*
|
||||
@@ -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.
|
||||
|
||||
@@ -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 "-----------------------------------------"
|
||||
Executable
+28
@@ -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
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
set -e
|
||||
|
||||
PROJECT_ROOT=`git rev-parse --show-toplevel`
|
||||
source `dirname "$0"`/common.sh
|
||||
|
||||
export CARGO_INCREMENTAL=0
|
||||
@@ -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
|
||||
|
||||
@@ -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/"
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user