GHW for building and publishing docker images (#1391)

* add ghw and scripts for docker image deployment

* debug

* add permissions for content

* fix path to the bin folder

* add tags

* rename env

* fix path to docker file

* make polkadot-parachain executable

* fix typo

* fix more typos

* test

* revert back  use of  working directory

* mke bin executable in the artifacts folder

* use cd instead of working directory

* change path to cash

* fix path to cash

* change cache key

* delete old flows

* addressed PR comments

* fix path

* reorg docker files
This commit is contained in:
Egor_P
2023-09-06 16:11:10 +02:00
committed by GitHub
parent 4c077b209b
commit eeb368ed9c
55 changed files with 783 additions and 676 deletions
@@ -0,0 +1,48 @@
FROM docker.io/parity/base-bin
# This file allows building a Generic container image
# based on one or multiple pre-built Linux binaries.
# Some defaults are set to polkadot but all can be overriden.
SHELL ["/bin/bash", "-c"]
# metadata
ARG VCS_REF
ARG BUILD_DATE
ARG IMAGE_NAME
# That can be a single one or a comma separated list
ARG BINARY=polkadot
ARG BIN_FOLDER=.
ARG DOC_URL=https://github.com/paritytech/polkadot-sdk
ARG DESCRIPTION="Polkadot: a platform for web3"
ARG AUTHORS="devops-team@parity.io"
ARG VENDOR="Parity Technologies"
LABEL io.parity.image.authors=${AUTHORS} \
io.parity.image.vendor="${VENDOR}" \
io.parity.image.revision="${VCS_REF}" \
io.parity.image.title="${IMAGE_NAME}" \
io.parity.image.created="${BUILD_DATE}" \
io.parity.image.documentation="${DOC_URL}" \
io.parity.image.description="${DESCRIPTION}" \
io.parity.image.source="https://github.com/paritytech/polkadot-sdk/blob/${VCS_REF}/docker/dockerfiles/binary_injected.Dockerfile"
USER root
WORKDIR /app
# add polkadot binary to docker image
# sample for polkadot: COPY ./polkadot ./polkadot-*-worker /usr/local/bin/
COPY entrypoint.sh .
COPY "bin/*" "/usr/local/bin/"
RUN chmod -R a+rx "/usr/local/bin"
USER parity
ENV BINARY=${BINARY}
# ENTRYPOINT
ENTRYPOINT ["/app/entrypoint.sh"]
# We call the help by default
CMD ["--help"]
@@ -10,7 +10,7 @@ LABEL io.parity.image.authors="devops-team@parity.io" \
io.parity.image.vendor="Parity Technologies" \
io.parity.image.title="${IMAGE_NAME}" \
io.parity.image.description="Injected adder-collator Docker image" \
io.parity.image.source="https://github.com/paritytech/polkadot/blob/${VCS_REF}/scripts/ci/dockerfiles/collator_injected.Dockerfile" \
io.parity.image.source="https://github.com/paritytech/polkadot/blob/${VCS_REF}/docker/dockerfiles/collator_injected.Dockerfile" \
io.parity.image.revision="${VCS_REF}" \
io.parity.image.created="${BUILD_DATE}" \
io.parity.image.documentation="https://github.com/paritytech/polkadot/"
@@ -61,7 +61,7 @@ services:
genesis_state:
build:
context: .
dockerfile: ./docker/test-parachain-collator.dockerfile
dockerfile: ./docker/dockerfiles/test-parachain-collator.dockerfile
image: "ctpc:latest"
volumes:
- "genesis-state:/data"
@@ -73,7 +73,7 @@ services:
collator:
build:
context: .
dockerfile: ./docker/test-parachain-collator.dockerfile
dockerfile: ./docker/dockerfiles/test-parachain-collator.dockerfile
target: collator
image: "ctpc:collator"
volumes:
@@ -90,7 +90,7 @@ services:
runtime:
build:
context: .
dockerfile: ./docker/test-parachain-collator.dockerfile
dockerfile: ./docker/dockerfiles/test-parachain-collator.dockerfile
target: runtime
image: "ctpc:runtime"
volumes:
@@ -100,7 +100,7 @@ services:
registrar:
build:
context: .
dockerfile: ./docker/parachain-registrar.dockerfile
dockerfile: ./docker/dockerfiles/parachain-registrar.dockerfile
image: para-reg:latest
volumes:
- "genesis-state:/genesis"
@@ -9,7 +9,7 @@ CMD [ "--version" ]
# To use the pjs build stage to access the blockchain from the host machine:
#
# docker build -f docker/parachain-registrar.dockerfile --target pjs -t parachain-registrar:pjs .
# docker build -f docker/dockerfiles/parachain-registrar.dockerfile --target pjs -t parachain-registrar:pjs .
# alias pjs='docker run --rm --net cumulus_testing_net parachain-registrar:pjs --ws ws://172.28.1.1:9944'
#
# Then, as long as the chain is running, you can use the polkadot-js-api CLI like:
@@ -9,7 +9,7 @@ LABEL io.parity.image.authors="devops-team@parity.io" \
io.parity.image.vendor="Parity Technologies" \
io.parity.image.title="${IMAGE_NAME}" \
io.parity.image.description="Cumulus, the Polkadot collator." \
io.parity.image.source="https://github.com/paritytech/cumulus/blob/${VCS_REF}/scripts/docker/polkadot-parachain-debug_unsigned_injected.Dockerfile" \
io.parity.image.source="https://github.com/paritytech/cumulus/blob/${VCS_REF}/docker/dockerfiles/polkadot-parachain/polkadot-parachain-debug_unsigned_injected.Dockerfile" \
io.parity.image.revision="${VCS_REF}" \
io.parity.image.created="${BUILD_DATE}" \
io.parity.image.documentation="https://github.com/paritytech/cumulus/"
@@ -1,4 +1,4 @@
# This file is sourced from https://github.com/paritytech/polkadot/blob/master/scripts/ci/dockerfiles/polkadot/polkadot_builder.Dockerfile
# This file is sourced from https://github.com/paritytech/polkadot/blob/master/docker/dockerfiles/polkadot/polkadot_builder.Dockerfile
# This is the build stage for polkadot-parachain. Here we create the binary in a temporary image.
FROM docker.io/paritytech/ci-linux:production as builder
@@ -14,7 +14,7 @@ LABEL io.parity.image.type="builder" \
io.parity.image.authors="devops-team@parity.io" \
io.parity.image.vendor="Parity Technologies" \
io.parity.image.description="Multistage Docker image for polkadot-parachain" \
io.parity.image.source="https://github.com/paritytech/polkadot/blob/${VCS_REF}/scripts/ci/dockerfiles/polkadot/polkadot-parachain_builder.Dockerfile" \
io.parity.image.source="https://github.com/paritytech/polkadot/blob/${VCS_REF}/docker/dockerfiles/polkadot-parachain/polkadot-parachain_builder.Dockerfile" \
io.parity.image.documentation="https://github.com/paritytech/cumulus"
COPY --from=builder /cumulus/target/release/polkadot-parachain /usr/local/bin
@@ -0,0 +1,38 @@
FROM docker.io/parity/base-bin
# metadata
ARG VCS_REF
ARG BUILD_DATE
ARG IMAGE_NAME
LABEL io.parity.image.authors="devops-team@parity.io" \
io.parity.image.vendor="Parity Technologies" \
io.parity.image.title="${IMAGE_NAME}" \
io.parity.image.description="Cumulus, the Polkadot collator." \
io.parity.image.source="https://github.com/paritytech/polkadot-sdk/blob/${VCS_REF}/docker/dockerfiles/polkadot-parachain/polkadot-parachain_injected.Dockerfile" \
io.parity.image.revision="${VCS_REF}" \
io.parity.image.created="${BUILD_DATE}" \
io.parity.image.documentation="https://github.com/paritytech/polkadot-sdk/"
# show backtraces
ENV RUST_BACKTRACE 1
USER root
RUN mkdir -p /specs
# add polkadot-parachain binary to the docker image
COPY bin/* /usr/local/bin/
COPY specs/* /specs/
RUN chmod -R a+rx "/usr/local/bin"
USER parity
# check if executable works in this container
RUN /usr/local/bin/polkadot-parachain --version
EXPOSE 30333 9933 9944 9615
VOLUME ["/polkadot", "/specs"]
ENTRYPOINT ["/usr/local/bin/polkadot-parachain"]
+9
View File
@@ -0,0 +1,9 @@
# Self built Docker image
The Polkadot repo contains several options to build Docker images for Polkadot.
This folder contains a self-contained image that does not require a Linux pre-built binary.
Instead, building the image is possible on any host having docker installed and will
build Polkadot inside Docker. That also means that no Rust toolchain is required on the host
machine for the build to succeed.
@@ -0,0 +1,50 @@
version: '3'
services:
node_alice:
ports:
- "30333:30333"
- "9933:9933"
- "9944:9944"
- "9615:9615"
image: parity/polkadot:latest
volumes:
- "polkadot-data-alice:/data"
command: |
--chain=polkadot-local
--alice
-d /data
--node-key 0000000000000000000000000000000000000000000000000000000000000001
networks:
testing_net:
ipv4_address: 172.28.1.1
node_bob:
ports:
- "30344:30333"
- "9935:9933"
- "9945:9944"
- "29615:9615"
image: parity/polkadot:latest
volumes:
- "polkadot-data-bob:/data"
links:
- "node_alice:alice"
command: |
--chain=polkadot-local
--bob
-d /data
--bootnodes '/ip4/172.28.1.1/tcp/30333/p2p/QmRpheLN4JWdAnY7HGJfWFNbfkQCb6tFf4vvA6hgjMZKrR'
networks:
testing_net:
ipv4_address: 172.28.1.2
volumes:
polkadot-data-alice:
polkadot-data-bob:
networks:
testing_net:
ipam:
driver: default
config:
- subnet: 172.28.0.0/16
@@ -0,0 +1,22 @@
version: '3'
services:
polkadot:
image: parity/polkadot:latest
ports:
- "127.0.0.1:30333:30333/tcp"
- "127.0.0.1:9933:9933/tcp"
- "127.0.0.1:9944:9944/tcp"
- "127.0.0.1:9615:9615/tcp"
volumes:
- "polkadot-data:/data"
command: |
--unsafe-rpc-external
--unsafe-ws-external
--rpc-cors all
--prometheus-external
volumes:
polkadot-data:
@@ -0,0 +1,7 @@
# Polkadot official Docker image
## [Polkadot](https://polkadot.network/)
## [GitHub](https://github.com/paritytech/polkadot)
## [Polkadot Wiki](https://wiki.polkadot.network/)
@@ -0,0 +1,36 @@
# This is the build stage for Polkadot. Here we create the binary in a temporary image.
FROM docker.io/paritytech/ci-linux:production as builder
WORKDIR /polkadot
COPY . /polkadot
RUN cargo build --locked --release
# This is the 2nd stage: a very small image where we copy the Polkadot binary."
FROM docker.io/parity/base-bin:latest
LABEL description="Multistage Docker image for Polkadot: a platform for web3" \
io.parity.image.type="builder" \
io.parity.image.authors="chevdor@gmail.com, devops-team@parity.io" \
io.parity.image.vendor="Parity Technologies" \
io.parity.image.description="Polkadot: a platform for web3" \
io.parity.image.source="https://github.com/paritytech/polkadot/blob/${VCS_REF}/docker/dockerfiles/polkadot/polkadot_builder.Dockerfile" \
io.parity.image.documentation="https://github.com/paritytech/polkadot/"
COPY --from=builder /polkadot/target/release/polkadot /usr/local/bin
RUN useradd -m -u 1000 -U -s /bin/sh -d /polkadot polkadot && \
mkdir -p /data /polkadot/.local/share && \
chown -R polkadot:polkadot /data && \
ln -s /data /polkadot/.local/share/polkadot && \
# unclutter and minimize the attack surface
rm -rf /usr/bin /usr/sbin && \
# check if executable works in this container
/usr/local/bin/polkadot --version
USER polkadot
EXPOSE 30333 9933 9944 9615
VOLUME ["/data"]
ENTRYPOINT ["/usr/local/bin/polkadot"]
@@ -0,0 +1,53 @@
FROM docker.io/library/ubuntu:20.04
# metadata
ARG VCS_REF
ARG BUILD_DATE
ARG POLKADOT_VERSION
ARG POLKADOT_GPGKEY=9D4B2B6EB8F97156D19669A9FF0812D491B96798
ARG GPG_KEYSERVER="keyserver.ubuntu.com"
LABEL io.parity.image.authors="devops-team@parity.io" \
io.parity.image.vendor="Parity Technologies" \
io.parity.image.title="parity/polkadot" \
io.parity.image.description="Polkadot: a platform for web3. This is the official Parity image with an injected binary." \
io.parity.image.source="https://github.com/paritytech/polkadot/blob/${VCS_REF}/scripts/ci/dockerfiles/polkadot/polkadot_injected_debian.Dockerfile" \
io.parity.image.revision="${VCS_REF}" \
io.parity.image.created="${BUILD_DATE}" \
io.parity.image.documentation="https://github.com/paritytech/polkadot/"
# show backtraces
ENV RUST_BACKTRACE 1
# install tools and dependencies
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
libssl1.1 \
ca-certificates \
gnupg && \
useradd -m -u 1000 -U -s /bin/sh -d /polkadot polkadot && \
# add repo's gpg keys and install the published polkadot binary
gpg --keyserver ${GPG_KEYSERVER} --recv-keys ${POLKADOT_GPGKEY} && \
gpg --export ${POLKADOT_GPGKEY} > /usr/share/keyrings/parity.gpg && \
echo 'deb [signed-by=/usr/share/keyrings/parity.gpg] https://releases.parity.io/deb release main' > /etc/apt/sources.list.d/parity.list && \
apt-get update && \
apt-get install -y --no-install-recommends polkadot=${POLKADOT_VERSION#?} && \
# apt cleanup
apt-get autoremove -y && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* ; \
mkdir -p /data /polkadot/.local/share && \
chown -R polkadot:polkadot /data && \
ln -s /data /polkadot/.local/share/polkadot
USER polkadot
# check if executable works in this container
RUN /usr/bin/polkadot --version
RUN /usr/bin/polkadot-execute-worker --version
RUN /usr/bin/polkadot-prepare-worker --version
EXPOSE 30333 9933 9944
VOLUME ["/polkadot"]
ENTRYPOINT ["/usr/bin/polkadot"]
@@ -9,7 +9,7 @@ LABEL io.parity.image.authors="devops-team@parity.io" \
io.parity.image.vendor="Parity Technologies" \
io.parity.image.title="${IMAGE_NAME}" \
io.parity.image.description="Polkadot: a platform for web3" \
io.parity.image.source="https://github.com/paritytech/polkadot/blob/${VCS_REF}/scripts/ci/dockerfiles/polkadot_injected_debug.Dockerfile" \
io.parity.image.source="https://github.com/paritytech/polkadot/blob/${VCS_REF}/docker/dockerfiles/polkadot/polkadot_injected_debug.Dockerfile" \
io.parity.image.revision="${VCS_REF}" \
io.parity.image.created="${BUILD_DATE}" \
io.parity.image.documentation="https://github.com/paritytech/polkadot/"
@@ -11,7 +11,7 @@ LABEL io.parity.image.authors="devops-team@parity.io" \
io.parity.image.vendor="Parity Technologies" \
io.parity.image.title="parity/polkadot" \
io.parity.image.description="Polkadot: a platform for web3. This is the official Parity image with an injected binary." \
io.parity.image.source="https://github.com/paritytech/polkadot/blob/${VCS_REF}/scripts/ci/dockerfiles/polkadot_injected_release.Dockerfile" \
io.parity.image.source="https://github.com/paritytech/polkadot/blob/${VCS_REF}/docker/dockerfiles/polkadot/polkadot_injected_release.Dockerfile" \
io.parity.image.revision="${VCS_REF}" \
io.parity.image.created="${BUILD_DATE}" \
io.parity.image.documentation="https://github.com/paritytech/polkadot/"
@@ -1,4 +1,4 @@
# This file is sourced from https://github.com/paritytech/polkadot/blob/master/scripts/ci/dockerfiles/polkadot/polkadot_builder.Dockerfile
# This file is sourced from https://github.com/paritytech/polkadot/blob/master/docker/dockerfiles/polkadot/polkadot_builder.Dockerfile
FROM docker.io/paritytech/ci-linux:production as builder
WORKDIR /cumulus
@@ -9,7 +9,7 @@ LABEL io.parity.image.authors="devops-team@parity.io" \
io.parity.image.vendor="Parity Technologies" \
io.parity.image.title="${IMAGE_NAME}" \
io.parity.image.description="Test parachain for Zombienet" \
io.parity.image.source="https://github.com/paritytech/cumulus/blob/${VCS_REF}/docker/test-parachain_injected.Dockerfile" \
io.parity.image.source="https://github.com/paritytech/cumulus/blob/${VCS_REF}/docker/dockerfiles/test-parachain_injected.Dockerfile" \
io.parity.image.revision="${VCS_REF}" \
io.parity.image.created="${BUILD_DATE}" \
io.parity.image.documentation="https://github.com/paritytech/cumulus/"
-51
View File
@@ -1,51 +0,0 @@
FROM docker.io/library/ubuntu:20.04
# metadata
ARG VCS_REF
ARG BUILD_DATE
ARG IMAGE_NAME
LABEL io.parity.image.authors="devops-team@parity.io" \
io.parity.image.vendor="Parity Technologies" \
io.parity.image.title="${IMAGE_NAME}" \
io.parity.image.description="Cumulus, the Polkadot collator." \
io.parity.image.source="https://github.com/paritytech/polkadot/blob/${VCS_REF}/scripts/docker/Dockerfile" \
io.parity.image.revision="${VCS_REF}" \
io.parity.image.created="${BUILD_DATE}" \
io.parity.image.documentation="https://github.com/paritytech/cumulus/"
# show backtraces
ENV RUST_BACKTRACE 1
# install tools and dependencies
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y \
libssl1.1 \
ca-certificates \
curl && \
# apt cleanup
apt-get autoremove -y && \
apt-get clean && \
find /var/lib/apt/lists/ -type f -not -name lock -delete; \
# add user and link ~/.local/share/polkadot to /data
useradd -m -u 1000 -U -s /bin/sh -d /polkadot polkadot && \
mkdir -p /data /polkadot/.local/share && \
chown -R polkadot:polkadot /data && \
ln -s /data /polkadot/.local/share/polkadot && \
mkdir -p /specs
# add polkadot-parachain binary to the docker image
COPY ./target/release/polkadot-parachain /usr/local/bin
COPY ./target/release/polkadot-parachain.asc /usr/local/bin
COPY ./target/release/polkadot-parachain.sha256 /usr/local/bin
COPY ./parachains/chain-specs/*.json /specs/
USER polkadot
# check if executable works in this container
RUN /usr/local/bin/polkadot-parachain --version
EXPOSE 30333 9933 9944
VOLUME ["/polkadot"]
ENTRYPOINT ["/usr/local/bin/polkadot-parachain"]
+13
View File
@@ -0,0 +1,13 @@
#!/usr/bin/env bash
# Sample call:
# $0 /path/to/folder_with_binary
# This script replace the former dedicated Dockerfile
# and shows how to use the generic binary_injected.dockerfile
PROJECT_ROOT=`git rev-parse --show-toplevel`
export BINARY=adder-collator,undying-collator
export ARTIFACTS_FOLDER=$1
$PROJECT_ROOT/docker/scripts/build-injected.sh
+23
View File
@@ -0,0 +1,23 @@
#!/usr/bin/env bash
TMP=$(mktemp -d)
ENGINE=${ENGINE:-podman}
# TODO: Switch to /bin/bash when the image is built from parity/base-bin
# Fetch some binaries
$ENGINE run --user root --rm -i \
--pull always \
-v "$TMP:/export" \
--entrypoint /usr/bin/bash \
paritypr/colander:master -c \
'cp "$(which adder-collator)" /export'
$ENGINE run --user root --rm -i \
--pull always \
-v "$TMP:/export" \
--entrypoint /usr/bin/bash \
paritypr/colander:master -c \
'cp "$(which undying-collator)" /export'
./build-injected.sh $TMP
+100
View File
@@ -0,0 +1,100 @@
#!/usr/bin/env bash
#set -e
# This script allows building a Container Image from a Linux
# binary that is injected into a base-image.
ENGINE=${ENGINE:-podman}
if [ "$ENGINE" == "podman" ]; then
PODMAN_FLAGS="--format docker"
else
PODMAN_FLAGS=""
fi
CONTEXT=$(mktemp -d)
REGISTRY=${REGISTRY:-docker.io}
# The following line ensure we know the project root
PROJECT_ROOT=${PROJECT_ROOT:-$(git rev-parse --show-toplevel)}
DOCKERFILE=${DOCKERFILE:-docker/dockerfiles/binary_injected.Dockerfile}
VERSION_TOML=$(grep "^version " $PROJECT_ROOT/Cargo.toml | grep -oE "([0-9\.]+-?[0-9]+)")
#n The following VAR have default that can be overriden
DOCKER_OWNER=${DOCKER_OWNER:-parity}
# We may get 1..n binaries, comma separated
BINARY=${BINARY:-polkadot}
IFS=',' read -r -a BINARIES <<< "$BINARY"
VERSION=${VERSION:-$VERSION_TOML}
ARTIFACTS_FOLDER=${ARTIFACTS_FOLDER:-.}
IMAGE=${IMAGE:-${REGISTRY}/${DOCKER_OWNER}/${BINARIES[0]}}
DESCRIPTION_DEFAULT="Injected Container image built for ${BINARY}"
DESCRIPTION=${DESCRIPTION:-$DESCRIPTION_DEFAULT}
VCS_REF=${VCS_REF:-01234567}
# Build the image
echo "Using engine: $ENGINE"
echo "Using Dockerfile: $DOCKERFILE"
echo "Using context: $CONTEXT"
echo "Building ${IMAGE}:latest container image for ${BINARY} v${VERSION} from ${ARTIFACTS_FOLDER} hang on!"
echo "ARTIFACTS_FOLDER=$ARTIFACTS_FOLDER"
echo "CONTEXT=$CONTEXT"
# We need all binaries and resources available in the Container build "CONTEXT"
mkdir -p $CONTEXT/bin
for bin in "${BINARIES[@]}"
do
echo "Copying $ARTIFACTS_FOLDER/$bin to context: $CONTEXT/bin"
ls -al "$ARTIFACTS_FOLDER/$bin"
cp -r "$ARTIFACTS_FOLDER/$bin" "$CONTEXT/bin"
done
cp "$PROJECT_ROOT/docker/scripts/entrypoint.sh" "$CONTEXT"
if [[ "$BINARY" == "polkadot-parachain" ]]; then
mkdir -p "$CONTEXT/specs"
echo "Copying parachains chain-specs from $ARTIFACTS_FOLDER/specs to context: $CONTEXT/specs"
ls -al "$ARTIFACTS_FOLDER/specs"
cp -r "$ARTIFACTS_FOLDER/specs" "$CONTEXT/specs"
fi
echo "Building image: ${IMAGE}"
TAGS=${TAGS[@]:-latest}
IFS=',' read -r -a TAG_ARRAY <<< "$TAGS"
TAG_ARGS=" "
echo "The image ${IMAGE} will be tagged with ${TAG_ARRAY[*]}"
for tag in "${TAG_ARRAY[@]}"; do
TAG_ARGS+="--tag ${IMAGE}:${tag} "
done
echo "$TAG_ARGS"
# time \
$ENGINE build \
${PODMAN_FLAGS} \
--build-arg VCS_REF="${VCS_REF}" \
--build-arg BUILD_DATE=$(date -u '+%Y-%m-%dT%H:%M:%SZ') \
--build-arg IMAGE_NAME="${IMAGE}" \
--build-arg BINARY="${BINARY}" \
--build-arg ARTIFACTS_FOLDER="${ARTIFACTS_FOLDER}" \
--build-arg DESCRIPTION="${DESCRIPTION}" \
${TAG_ARGS} \
-f "${PROJECT_ROOT}/${DOCKERFILE}" \
${CONTEXT}
echo "Your Container image for ${IMAGE} is ready"
$ENGINE images
if [[ -z "${SKIP_IMAGE_VALIDATION}" ]]; then
echo "Check the image ${IMAGE}:${TAG_ARRAY[0]}"
$ENGINE run --rm -i "${IMAGE}:${TAG_ARRAY[0]}" --version
echo "Query binaries"
$ENGINE run --rm -i --entrypoint /bin/bash "${IMAGE}:${TAG_ARRAY[0]}" -c "echo BINARY: ${BINARY}"
fi
+18
View File
@@ -0,0 +1,18 @@
#!/usr/bin/env bash
# Sanity check
if [ -z "$BINARY" ]
then
echo "BINARY ENV not defined, this should never be the case. Aborting..."
exit 1
fi
# If the user built the image with multiple binaries,
# we consider the first one to be the canonical one
# To start with another binary, the user can either:
# - use the --entrypoint option
# - pass the ENV BINARY with a single binary
IFS=',' read -r -a BINARIES <<< "$BINARY"
BIN0=${BINARIES[0]}
echo "Starting binary $BIN0"
$BIN0 $@
+14
View File
@@ -0,0 +1,14 @@
#!/usr/bin/env bash
# Sample call:
# $0 /path/to/folder_with_binary
# This script replace the former dedicated Dockerfile
# and shows how to use the generic binary_injected.dockerfile
PROJECT_ROOT=`git rev-parse --show-toplevel`
export BINARY=malus,polkadot-execute-worker,polkadot-prepare-worker
export ARTIFACTS_FOLDER=$1
# export TAGS=...
$PROJECT_ROOT/docker/scripts/build-injected.sh
+19
View File
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
TMP=$(mktemp -d)
ENGINE=${ENGINE:-podman}
export TAGS=latest,beta,7777,1.0.2-rc23
# Fetch some binaries
$ENGINE run --user root --rm -i \
--pull always \
-v "$TMP:/export" \
--entrypoint /bin/bash \
paritypr/malus:7217 -c \
'cp "$(which malus)" /export'
echo "Checking binaries we got:"
ls -al $TMP
./build-injected.sh $TMP
+15
View File
@@ -0,0 +1,15 @@
#!/usr/bin/env bash
# Sample call:
# $0 /path/to/folder_with_binary
# This script replace the former dedicated Dockerfile
# and shows how to use the generic binary_injected.dockerfile
PROJECT_ROOT=`git rev-parse --show-toplevel`
export BINARY=polkadot-parachain
export ARTIFACTS_FOLDER=$1
export DOCKERFILE="docker/dockerfiles/polkadot-parachain/polkadot-parachain_injected.Dockerfile"
# export TAGS=...
$PROJECT_ROOT/docker/scripts/build-injected.sh
+19
View File
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
TMP=$(mktemp -d)
ENGINE=${ENGINE:-podman}
export TAGS=latest,beta,7777,1.0.2-rc23
# Fetch some binaries
$ENGINE run --user root --rm -i \
--pull always \
-v "$TMP:/export" \
--entrypoint /bin/bash \
parity/polkadot-parachain:7217 -c \
'cp "$(which malus)" /export'
echo "Checking binaries we got:"
ls -al $TMP
./build-injected.sh $TMP
+10
View File
@@ -0,0 +1,10 @@
#!/usr/bin/env bash
OWNER=${OWNER:-parity}
IMAGE_NAME=${IMAGE_NAME:-polkadot-parachain}
docker build --no-cache \
--build-arg IMAGE_NAME=$IMAGE_NAME \
-t $OWNER/$IMAGE_NAME \
-f ./docker/dockerfiles/polkadot-parachain/polkadot-parachain_injected.Dockerfile \
. && docker images
+13
View File
@@ -0,0 +1,13 @@
#!/usr/bin/env bash
# Sample call:
# $0 /path/to/folder_with_binary
# This script replace the former dedicated Dockerfile
# and shows how to use the generic binary_injected.dockerfile
PROJECT_ROOT=`git rev-parse --show-toplevel`
export BINARY=polkadot,polkadot-execute-worker,polkadot-prepare-worker
export ARTIFACTS_FOLDER=$1
$PROJECT_ROOT/docker/scripts/build-injected.sh
+18
View File
@@ -0,0 +1,18 @@
#!/usr/bin/env bash
TMP=$(mktemp -d)
ENGINE=${ENGINE:-podman}
# You need to build an injected image first
# Fetch some binaries
$ENGINE run --user root --rm -i \
-v "$TMP:/export" \
--entrypoint /bin/bash \
parity/polkadot -c \
'cp "$(which polkadot)" /export'
echo "Checking binaries we got:"
tree $TMP
./build-injected.sh $TMP
+37
View File
@@ -0,0 +1,37 @@
# staking-miner container image
## Build using the Builder
```
./build.sh
```
## Build the injected Image
You first need a valid Linux binary to inject. Let's assume this binary is located in `BIN_FOLDER`.
```
./build-injected.sh "$BIN_FOLDER"
```
## Test
Here is how to test the image. We can generate a valid seed but the staking-miner will quickly notice that our
account is not funded and "does not exist".
You may pass any ENV supported by the binary and must provide at least a few such as `SEED` and `URI`:
```
ENV SEED=""
ENV URI="wss://rpc.polkadot.io:443"
ENV RUST_LOG="info"
```
```
export SEED=$(subkey generate -n polkadot --output-type json | jq -r .secretSeed)
podman run --rm -it \
-e URI="wss://rpc.polkadot.io:443" \
-e RUST_LOG="info" \
-e SEED \
localhost/parity/staking-miner \
dry-run seq-phragmen
```
+13
View File
@@ -0,0 +1,13 @@
#!/usr/bin/env bash
# Sample call:
# $0 /path/to/folder_with_staking-miner_binary
# This script replace the former dedicated staking-miner "injected" Dockerfile
# and shows how to use the generic binary_injected.dockerfile
PROJECT_ROOT=`git rev-parse --show-toplevel`
export BINARY=staking-miner
export ARTIFACTS_FOLDER=$1
$PROJECT_ROOT/docker/scripts/build-injected.sh
+13
View File
@@ -0,0 +1,13 @@
#!/usr/bin/env bash
# Sample call:
# $0 /path/to/folder_with_staking-miner_binary
# This script replace the former dedicated staking-miner "injected" Dockerfile
# and shows how to use the generic binary_injected.dockerfile
PROJECT_ROOT=`git rev-parse --show-toplevel`
ENGINE=podman
echo "Building the staking-miner using the Builder image"
echo "PROJECT_ROOT=$PROJECT_ROOT"
$ENGINE build -t staking-miner -f "${PROJECT_ROOT}/docker/dockerfiles/staking-miner/staking-miner_builder.Dockerfile" "$PROJECT_ROOT"
@@ -0,0 +1,3 @@
# Staking-miner Docker image
## [GitHub](https://github.com/paritytech/polkadot/tree/master/utils/staking-miner)
@@ -0,0 +1,43 @@
FROM paritytech/ci-linux:production as builder
# metadata
ARG VCS_REF
ARG BUILD_DATE
ARG IMAGE_NAME="staking-miner"
ARG PROFILE=production
LABEL description="This is the build stage. Here we create the binary."
WORKDIR /app
COPY . /app
RUN cargo build --locked --profile $PROFILE --package staking-miner
# ===== SECOND STAGE ======
FROM docker.io/parity/base-bin:latest
LABEL description="This is the 2nd stage: a very small image where we copy the binary."
LABEL io.parity.image.authors="devops-team@parity.io" \
io.parity.image.vendor="Parity Technologies" \
io.parity.image.title="${IMAGE_NAME}" \
io.parity.image.description="${IMAGE_NAME} for substrate based chains" \
io.parity.image.source="https://github.com/paritytech/polkadot/blob/${VCS_REF}/scripts/ci/dockerfiles/${IMAGE_NAME}/${IMAGE_NAME}_builder.Dockerfile" \
io.parity.image.revision="${VCS_REF}" \
io.parity.image.created="${BUILD_DATE}" \
io.parity.image.documentation="https://github.com/paritytech/polkadot/"
ARG PROFILE=release
COPY --from=builder /app/target/$PROFILE/staking-miner /usr/local/bin
# show backtraces
ENV RUST_BACKTRACE 1
USER parity
ENV SEED=""
ENV URI="wss://rpc.polkadot.io"
ENV RUST_LOG="info"
# check if the binary works in this container
RUN /usr/local/bin/staking-miner --version
ENTRYPOINT [ "/usr/local/bin/staking-miner" ]
+18
View File
@@ -0,0 +1,18 @@
#!/usr/bin/env bash
TMP=$(mktemp -d)
ENGINE=${ENGINE:-podman}
# You need to build an injected image first
# Fetch some binaries
$ENGINE run --user root --rm -i \
-v "$TMP:/export" \
--entrypoint /bin/bash \
parity/staking-miner -c \
'cp "$(which staking-miner)" /export'
echo "Checking binaries we got:"
tree $TMP
./build-injected.sh $TMP