diff --git a/bin/Dockerfile b/bin/Dockerfile deleted file mode 100644 index 1bf3f67b560d1cb3aca0e4f272521e78d269a0f2..0000000000000000000000000000000000000000 --- a/bin/Dockerfile +++ /dev/null @@ -1,26 +0,0 @@ -# Dockerfile for the SDF Generator environment - -# Start from a specific openEuler release. -ARG RELEASE_TAG=24.03-lts -FROM hub.oepkgs.net/openeuler/openeuler:${RELEASE_TAG} - -# Install all the dependencies for the splitter tool. -RUN dnf install -y \ - python3-dnf \ - git \ - python3-pip \ - cpio \ - binutils \ - file && \ - dnf clean all - -# Copy the splitter source code into the image. -COPY . /splitter - -# Install the splitter tool itself and its dependencies. -RUN cd /splitter && \ - pip3 install -i https://repo.huaweicloud.com/repository/pypi/simple . - -WORKDIR /splitter - -CMD ["/bin/bash"] \ No newline at end of file diff --git a/bin/gen-sdf-docker.sh b/bin/gen-sdf-docker.sh deleted file mode 100755 index e986cb29434314aec8e9c9d8915d2d939023b4ec..0000000000000000000000000000000000000000 --- a/bin/gen-sdf-docker.sh +++ /dev/null @@ -1,117 +0,0 @@ -#!/usr/bin/env bash -set -eu - -# base directory -SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -cd "${SCRIPT_DIR}/.." || exit 1 -BASE_DIR=$(pwd) - -ensure_docker_ready() { - # Check if Docker command exists - if ! command -v docker &> /dev/null; then - echo ">>> Docker not found. Installing ..." - # Check for root privileges. Exit if not root. - if [[ $EUID -ne 0 ]]; then - echo "This script must be run as root to install Docker." - exit 1 - fi - dnf install -y docker - systemctl restart docker - echo ">>> Docker installed." - fi -} - -# Help Function -usage() { - echo "Usage: $0 -p -r -o " - echo " -p, --package Required. The name of the RPM package to generate an SDF for (e.g., 'brotli')." - echo " -r, --release Required. The openEuler release (e.g., '24.03-LTS')." - echo " -o, --output Required. The directory to save the generated SDF file." - echo " -h, --help Show this help message." - exit 1 -} - -# Defaults -ARCH=$(uname -m) -RELEASE="" -PACKAGE_NAME="" -OUTPUT_DIR="" - -# Argument Parsing with getopts -while getopts ":p:r:o:h" opt; do - case ${opt} in - p ) - PACKAGE_NAME=$OPTARG - ;; - r ) - RELEASE=$OPTARG - ;; - o ) - OUTPUT_DIR=$OPTARG - ;; - h ) - usage - ;; - \? ) - echo "Invalid Option: -$OPTARG" 1>&2 - usage - ;; - : ) - echo "Invalid Option: -$OPTARG requires an argument" 1>&2 - usage - ;; - esac -done - -# Input Validation -if [[ -z "$PACKAGE_NAME" || -z "$RELEASE" || -z "$OUTPUT_DIR" ]]; then - echo "Error: Missing required arguments." - usage -fi - -ensure_docker_ready - -# Absolute path for the output directory for Docker mount -mkdir -p "${OUTPUT_DIR}" -ABS_OUTPUT_DIR="$(cd "$OUTPUT_DIR" && pwd)" - -RELEASE_TAG="${RELEASE,,}" # Convert to lowercase for consistency -CUSTOM_IMAGE_NAME="sdf-generator-base:${RELEASE_TAG}" -CONTAINER_NAME="sdf-generator-${PACKAGE_NAME}-$$" - -echo ">>> Starting SDF Generation for '${PACKAGE_NAME}'" -echo " Release: ${RELEASE}" -echo " Release Tag: ${RELEASE_TAG}" -echo " Arch: ${ARCH}" -echo " Output Dir: ${ABS_OUTPUT_DIR}" -echo " Using Docker Image: ${CUSTOM_IMAGE_NAME}" - -# Docker Image Build -echo ">>> Checking for custom base image: ${CUSTOM_IMAGE_NAME}" -if [[ -z "$(docker images -q "${CUSTOM_IMAGE_NAME}")" ]]; then - echo ">>> Base image not found. Building it now..." - docker build --no-cache --build-arg RELEASE_TAG="${RELEASE_TAG}" \ - -t "${CUSTOM_IMAGE_NAME}" \ - -f "${BASE_DIR}/bin/Dockerfile" \ - "${BASE_DIR}" - echo ">>> Base image built successfully." -else - echo ">>> Base image found." -fi - -echo ">>> Output SDF will be saved to: ${ABS_OUTPUT_DIR}" - -# The command to be executed inside the container. -INSTALL_CMD="dnf install -y ${PACKAGE_NAME}" -GENERATE_CMD="splitter gen -p ${PACKAGE_NAME} -r ${RELEASE} -o /output -a ${ARCH}" -FULL_COMMAND="${INSTALL_CMD} && ${GENERATE_CMD}" - -echo ">>> Starting Docker container from custom image..." -docker run --name "${CONTAINER_NAME}" \ - -v "${ABS_OUTPUT_DIR}:/output" \ - --rm \ - "${CUSTOM_IMAGE_NAME}" \ - /bin/bash -c "${FULL_COMMAND}" - -echo ">>> SDF Generation complete. Docker container has been removed." -echo ">>> Done." \ No newline at end of file diff --git a/bin/splitter-docker.sh b/bin/splitter-docker.sh new file mode 100755 index 0000000000000000000000000000000000000000..0bd768034b73c3bb69bce41c2e16465775581055 --- /dev/null +++ b/bin/splitter-docker.sh @@ -0,0 +1,141 @@ +#!/usr/bin/env bash +set -eu + +usage() { + echo "Usage: $0 [options...]" + echo "" + echo "A wrapper to run the official openeuler/splitter Docker image." + echo "" + echo "Commands:" + echo " cut Generate slices from packages. See 'splitter cut --help' for options." + echo " gen Generate a Slice Definition File (SDF). See 'splitter gen --help' for options." + echo "" + echo "Example for 'cut':" + echo " $0 cut -r 24.03-LTS -o ./output -a x86_64 python3_standard python3_utils" + echo "" + echo "Example for 'gen':" + echo " $0 gen -r 24.03-LTS -o ./output -p brotli" + exit 1 +} + +# Input Validation +if [[ $# -lt 1 || "$1" == "-h" || "$1" == "--help" ]]; then + usage +fi + +# The first argument is the splitter command (cut or gen) +SPLITTER_COMMAND="$1" +if [[ "$SPLITTER_COMMAND" != "cut" && "$SPLITTER_COMMAND" != "gen" ]]; then + echo "Error: Invalid command '$SPLITTER_COMMAND'. Must be 'cut' or 'gen'." + usage +fi +shift + +# Parse arguments +RELEASE="" +OUTPUT_DIR="" +PACKAGE_NAME="" +ARCH="" +for ((i=1; i<=$#; i++)); do + current_arg="${!i}" + next_i=$((i+1)) + next_arg="${!next_i:-}" + case "$current_arg" in + -r|--release) RELEASE="$next_arg";; + -o|--output) OUTPUT_DIR="$next_arg";; + -p|--package) PACKAGE_NAME="$next_arg";; + -a|--arch) ARCH="$next_arg";; + esac +done + +if [[ -z "$RELEASE" ]] || [[ -z "$OUTPUT_DIR" ]]; then + echo "Error: Missing required argument(s): -r and/or -o." + usage +fi + +if [[ "$SPLITTER_COMMAND" == "gen" && -z "$PACKAGE_NAME" ]]; then + echo "Error: 'gen' command requires -p argument." + usage +fi + +if [[ "$SPLITTER_COMMAND" == "cut" && -z "$ARCH" ]]; then + echo "Error: 'cut' command requires -a argument." + usage +fi + +# Docker Image name construction +# if SPLITTER_VERSION is unset or null, set it to "1.0.2" +: "${SPLITTER_VERSION:="1.0.2"}" +release_lower=$(echo "$RELEASE" | tr '[:upper:]' '[:lower:]') +sanitized_tag=${release_lower//-lts-sp/sp} +sanitized_tag=${sanitized_tag//-lts/lts} +sanitized_tag=${sanitized_tag//./} +sanitized_tag=${sanitized_tag//-/} + +IMAGE_TAG="${SPLITTER_VERSION}-oe${sanitized_tag}" +OFFICIAL_IMAGE="hub.oepkgs.net/openeuler/splitter:${IMAGE_TAG}" + +echo ">>> Splitter version: ${SPLITTER_VERSION}" +echo ">>> Release: ${RELEASE}" +echo ">>> Image Tag: ${IMAGE_TAG}" +echo ">>> Using official Docker image: ${OFFICIAL_IMAGE}" + +# Docker Environment Check +ensure_docker_ready() { + # Check if Docker command exists + if ! command -v docker &> /dev/null; then + echo ">>> Docker not found. Installing ..." + # Check for root privileges. Exit if not root. + if [[ $EUID -ne 0 ]]; then + echo "This script must be run as root to install Docker." + exit 1 + fi + dnf install -y docker + systemctl start docker + echo ">>> Docker installed." + fi +} +ensure_docker_ready + +# convert output to absolute path +mkdir -p "$OUTPUT_DIR" +ABS_OUTPUT_DIR="$(cd "$OUTPUT_DIR" && pwd)" +echo ">>> Output directory is: ${ABS_OUTPUT_DIR}" + +# Create a new array to hold the modified arguments for the container +container_args=() +for ((i=1; i<=$#; i++)); do + current_arg="${!i}" + next_i=$((i+1)) + + if [[ "$current_arg" == "-o" || "$current_arg" == "--output" ]]; then + # When we find -o or --output, we add '-o /output' to our new list + container_args+=("-o" "/output") + # And we skip the next argument, which is the host path + i=$((i+1)) + else + # Otherwise, just add the argument as is + container_args+=("$current_arg") + fi +done + +# Use the newly built container_args array +INNER_CMD="splitter ${SPLITTER_COMMAND} ${container_args[*]}" + +# For 'gen' command, we need to install the package first +if [[ "$SPLITTER_COMMAND" == "gen" ]]; then + INNER_CMD="dnf install -y ${PACKAGE_NAME} && ${INNER_CMD}" +fi + +echo ">>> Executing in container: /bin/bash -c \"${INNER_CMD}\"" + +# Run the command in Docker +CONTAINER_NAME="splitter-run-$$" +docker run --name "$CONTAINER_NAME" \ + -v "$ABS_OUTPUT_DIR:/output" \ + --rm \ + "$OFFICIAL_IMAGE" \ + /bin/bash -c "${INNER_CMD}" + +echo ">>> Command completed successfully." +echo ">>> Done." \ No newline at end of file