Files
pezkuwi-subxt/polkadot/scripts/ci/dockerfiles/build-injected.sh
T
Chevdor 693a29da1a Publish RC container images (#7556)
* WIP

* Add missing checkout

* Add debuggin

* Fix VAR name

* Bug fix

* Rework jobs

* Revert "Rework jobs"

This reverts commit 2bfa79fd3ae633c17403b838f9a5025f0f7fc3f3.

* Add cache

* Add temp default for testing

* Add missing checkout

* Fix patch

* Comment out the GPG check for now

* Rename polkadot_injected_release into a more appropriate polkadot_injected_debian

* Refactoring / renaming

* Introduce a generic image for binary injection

* Flag files to be deleted and changes to be done

* WIP

* Fix multi binaries images

* Add test build scripts

* Remove old file, add polkadot build-injected script

* Fix doc

* Fix tagging

* Add build of the injected container

* Fix for docker

* Remove the need for TTY

* Handling container publishing

* Fix owner and registry

* Fix vars

* Fix repo

* Fix var naming

* Fix case when there is no tag

* Fix case with no tag

* Handle error

* Fix spacings

* Fix tags

* Remove unnecessary grep that may fail

* Add final check

* Clean up and introduce GPG check

* Add doc

* Add doc

* Update doc/docker.md

Co-authored-by: Mira Ressel <mira@parity.io>

* type

Co-authored-by: Mira Ressel <mira@parity.io>

* Fix used VAR

* Improve doc

* ci: Update .build-push-image jobs to use the new build-injected.sh

* ci: fix path to build-injected.sh script

* Rename the release artifacts folder to prevent confusion due to a similar folder in the gitlab CI

* ci: check out polkadot repo in .build-push-image

This seems far cleaner than copying the entire scripts/ folder into our
job artifacts.

* feat(build-injected.sh): make PROJECT_ROOT configurable

This lets us avoid a dependency on git in our CI image.

* ci: build injected images with buildah

* ci: pass full image names to zombienet

* Add missing ignore

---------

Co-authored-by: Mira Ressel <mira@parity.io>
2023-08-11 15:28:39 +02:00

93 lines
2.6 KiB
Bash
Executable File

#!/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:-$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
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}
BIN_FOLDER=${BIN_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 ${BIN_FOLDER} hang on!"
echo "BIN_FOLDER=$BIN_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 $BIN_FOLDER/$bin to context: $CONTEXT/bin"
cp "$BIN_FOLDER/$bin" "$CONTEXT/bin"
done
cp "$PROJECT_ROOT/scripts/ci/dockerfiles/entrypoint.sh" "$CONTEXT"
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 BIN_FOLDER="${BIN_FOLDER}" \
--build-arg DESCRIPTION="${DESCRIPTION}" \
${TAG_ARGS} \
-f "${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