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

Commit

Permalink
Introduce a generic image for binary injection
Browse files Browse the repository at this point in the history
  • Loading branch information
chevdor committed Aug 2, 2023
1 parent e66d4fd commit 6a546da
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 84 deletions.
55 changes: 26 additions & 29 deletions scripts/ci/dockerfiles/binary_injected.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,47 +1,44 @@
FROM docker.io/library/ubuntu:20.04
# It would be better using this image to inject generic binaries
# instead of requiring a dockerfile per binary.
# Unfortunately, ENTRYPOINT requires using an ENV
# and the current setup shows limitation: the passed args are ignored.

FROM docker.io/parity/base-bin

# metadata
ARG VCS_REF
ARG BUILD_DATE
ARG IMAGE_NAME
ARG BINARY
ARG BINARY=polkadot
ARG BIN_FOLDER=.
ARG DOC_URL=https://github.com/paritytech/polkadot
ARG DESCRIPTION="Polkadot: a platform for web3"

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.Dockerfile" \
io.parity.image.description="${DESCRIPTION}" \
io.parity.image.source="https://github.com/paritytech/polkadot/blob/${VCS_REF}/scripts/ci/dockerfiles/binary_injected.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 \
libssl1.1 \
ca-certificates && \
# 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
io.parity.image.documentation="${DOC_URL}"

USER root
WORKDIR /app

# add polkadot binary to docker image
COPY ./polkadot ./polkadot-*-worker /usr/local/bin/
COPY entrypoint.sh .
COPY ./$BIN_FOLDER/$BINARY /usr/local/bin/
RUN chmod a+rwx /usr/local/bin/$BINARY

USER polkadot
USER parity
ENV BINARY=${BINARY}

# check if executable works in this container
RUN /usr/local/bin/polkadot --version
RUN /usr/local/bin/$BINARY --version

EXPOSE 30333 9933 9944
VOLUME ["/polkadot"]
VOLUME ["/$BINARY"]

ENTRYPOINT ["/usr/local/bin/polkadot"]
# ENTRYPOINT
ENTRYPOINT ["/app/entrypoint.sh"]
CMD ["--help"]
46 changes: 46 additions & 0 deletions scripts/ci/dockerfiles/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/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}

# The following line ensure we know the project root
PROJECT_ROOT=`git rev-parse --show-toplevel`
DOCKERFILE=${DOCKERFILE:-$PROJECT_ROOT/scripts/ci/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
OWNER=${OWNER:-parity}
BINARY=${BINARY:-polkadot}
VERSION=${VERSION:-$VERSION_TOML}
BIN_FOLDER=${BIN_FOLDER:-.}

IMAGE=${OWNER}/${BINARY}
DESCRIPTION_DEFAULT="Injected Container image built for $BINARY"
DESCRIPTION=${DESCRIPTION:-$DESCRIPTION_DEFAULT}

# Build the image
echo "Using engine: $ENGINE"
echo "Using Dockerfile: $DOCKERFILE"
echo "Building ${IMAGE}:latest container image for ${BINARY} v${VERSION} from ${BIN_FOLDER} hang on!"

# time \
$ENGINE build \
--build-arg BUILD_DATE=$(date -u '+%Y-%m-%dT%H:%M:%SZ') \
--build-arg IMAGE_NAME=${IMAGE} \
--build-arg BINARY=${BINARY} \
--build-arg BIN_FOLDER=${BIN_FOLDER} \
--build-arg DESCRIPTION=${DESCRIPTION} \
-f $DOCKERFILE \
-t ${IMAGE}:latest \
-t ${IMAGE}:v${VERSION} \
.

# Show the list of available images for this repo
echo "Your Container image for ${IMAGE} is ready"
$ENGINE images | grep ${IMAGE}

# Check the final image
$ENGINE run --rm -it "${IMAGE}:latest" --version
11 changes: 11 additions & 0 deletions scripts/ci/dockerfiles/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/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

echo "Starting binary $BINARY"
$BINARY $@
27 changes: 0 additions & 27 deletions scripts/ci/dockerfiles/polkadot/build.sh

This file was deleted.

43 changes: 15 additions & 28 deletions scripts/ci/dockerfiles/polkadot_injected.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,48 +1,35 @@
FROM docker.io/library/ubuntu:20.04
FROM docker.io/parity/base-bin

# metadata
ARG VCS_REF
ARG BUILD_DATE
ARG IMAGE_NAME
ARG DOC_URL=https://github.com/paritytech/polkadot
ARG DESCRIPTION="Polkadot: a platform for web3"

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.description="${DESCRIPTION}" \
io.parity.image.source="https://github.com/paritytech/polkadot/blob/${VCS_REF}/scripts/ci/dockerfiles/polkadot_injected.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 \
libssl1.1 \
ca-certificates && \
# 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

# add polkadot binary to docker image
COPY ./polkadot ./polkadot-execute-worker ./polkadot-prepare-worker /usr/local/bin/

USER polkadot
io.parity.image.documentation="${DOC_URL}"

USER root

# Add the polkadot binaries to the image
COPY ./polkadot ./polkadot-*-worker /usr/local/bin/
RUN chmod a+rwx /usr/local/bin/polkadot*

USER parity

# check if executable works in this container
RUN /usr/local/bin/polkadot --version
RUN /usr/local/bin/polkadot-execute-worker --version
RUN /usr/local/bin/polkadot-prepare-worker --version

EXPOSE 30333 9933 9944
VOLUME ["/polkadot"]
EXPOSE 30333 9933 9944 9615
VOLUME ["/data"]

ENTRYPOINT ["/usr/local/bin/polkadot"]

0 comments on commit 6a546da

Please sign in to comment.