From 1bfcb35005bbbfc0bc620b4ca96d04c8b9a8aa5c Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 22 Jun 2025 18:36:53 +1200 Subject: [PATCH] test: Update 3 files --- build-base/Dockerfile.dropshell-build-base | 4 ++ build-base/build.sh | 11 ++++-- build-base/opt/install_upx.sh | 46 ++++++++++++++++++++++ tests/Dockerfile.test-build | 6 +++ 4 files changed, 63 insertions(+), 4 deletions(-) create mode 100755 build-base/opt/install_upx.sh diff --git a/build-base/Dockerfile.dropshell-build-base b/build-base/Dockerfile.dropshell-build-base index 1cb60dd..fa1d219 100644 --- a/build-base/Dockerfile.dropshell-build-base +++ b/build-base/Dockerfile.dropshell-build-base @@ -250,3 +250,7 @@ RUN curl -LO https://github.com/nlohmann/json/archive/refs/tags/v${NLOHMANN_JSON make -j$(nproc) && \ make install && \ cd / && rm -rf /tmp/json-${NLOHMANN_JSON_VERSION} /tmp/v${NLOHMANN_JSON_VERSION}.tar.gz + +# Install upx +COPY opt /opt +RUN /opt/install_upx.sh diff --git a/build-base/build.sh b/build-base/build.sh index 0b6c783..791bfb2 100755 --- a/build-base/build.sh +++ b/build-base/build.sh @@ -5,11 +5,14 @@ set -euo pipefail SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" PROJECT="dropshell-build-base" - ARCH=$(uname -m) +echo "Building ${PROJECT} for ${ARCH}..." + # Build multi-platform image and push it docker build \ - -t "dropshell-build-base:test" \ - -f "${SCRIPT_DIR}/Dockerfile.dropshell-build-base" \ - ${SCRIPT_DIR} + -t "${PROJECT}:test" \ + -f "${SCRIPT_DIR}/Dockerfile.${PROJECT}" \ + "${SCRIPT_DIR}" + +echo "Successfully built ${PROJECT}:test" diff --git a/build-base/opt/install_upx.sh b/build-base/opt/install_upx.sh new file mode 100755 index 0000000..5fd8349 --- /dev/null +++ b/build-base/opt/install_upx.sh @@ -0,0 +1,46 @@ +#!/bin/bash +set -euo pipefail + +# check we're running as root +if [ "$(id -u)" -ne 0 ]; then + echo "Please run as root" + exit 1 +fi + +# Determine architecture +ARCH=$(uname -m) +case $ARCH in + x86_64) + UPX_ARCH="amd64" + ;; + aarch64) + UPX_ARCH="arm64" + ;; + *) + echo "Unsupported architecture: $ARCH" + exit 1 + ;; +esac + +# Download and install UPX v5.0.1 +UPX_VERSION="5.0.1" +UPX_FILE="upx-${UPX_VERSION}-${UPX_ARCH}_linux.tar.xz" +UPX_URL="https://github.com/upx/upx/releases/download/v${UPX_VERSION}/${UPX_FILE}" + +echo "Downloading UPX ${UPX_VERSION} for ${UPX_ARCH}..." +curl -L -o "${UPX_FILE}" "${UPX_URL}" + +# Extract UPX +tar -xf "${UPX_FILE}" + +# Install to /usr/local/bin +cp "upx-${UPX_VERSION}-${UPX_ARCH}_linux/upx" /usr/local/bin/ +chmod +x /usr/local/bin/upx + +# Verify installation +upx --version + +# Cleanup +rm -rf "${UPX_FILE}" "upx-${UPX_VERSION}-${UPX_ARCH}_linux" + +echo "UPX ${UPX_VERSION} installed successfully!" \ No newline at end of file diff --git a/tests/Dockerfile.test-build b/tests/Dockerfile.test-build index 4cdee6f..2be1a05 100644 --- a/tests/Dockerfile.test-build +++ b/tests/Dockerfile.test-build @@ -53,6 +53,12 @@ RUN --mount=type=cache,target=/build \ find /build -type f -executable -name "*${PROJECT}*" -exec cp {} /output/${PROJECT} \; || \ find /build -type f -executable -exec cp {} /output/${PROJECT} \; +# if we're a release build, then run upx on the binary. +RUN if [ "${CMAKE_BUILD_TYPE}" = "Release" ]; then \ + upx /output/${PROJECT}; \ + fi + + # Final stage that only contains the binary FROM scratch AS project