From 70cb5c1b3af412eff17a1f9076e17445abcef8a0 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 29 Jun 2025 21:27:12 +1200 Subject: [PATCH] test: Update 5 files --- dehydrate/Dockerfile.dropshell-build | 65 -------------------------- dehydrate/build.sh | 41 ++++++++-------- dehydrate/clean.sh | 20 +++----- dehydrate/publish.sh | 16 +------ dehydrate/test/build_dehydrate_test.sh | 2 +- 5 files changed, 28 insertions(+), 116 deletions(-) delete mode 100644 dehydrate/Dockerfile.dropshell-build diff --git a/dehydrate/Dockerfile.dropshell-build b/dehydrate/Dockerfile.dropshell-build deleted file mode 100644 index 7187e87..0000000 --- a/dehydrate/Dockerfile.dropshell-build +++ /dev/null @@ -1,65 +0,0 @@ -ARG IMAGE_TAG -FROM gitea.jde.nz/public/dropshell-build-base:latest AS builder - -ARG PROJECT -ARG CMAKE_BUILD_TYPE=Debug - -# Set working directory -WORKDIR /app - -SHELL ["/bin/bash", "-c"] - -# Create cache directories -RUN mkdir -p /ccache - -# Set up ccache -ENV CCACHE_DIR=/ccache -ENV CCACHE_COMPILERCHECK=content -ENV CCACHE_MAXSIZE=2G - -# Copy build files -COPY CMakeLists.txt ./ -COPY src/version.hpp.in src/ - -# Copy source files -COPY src/ src/ -COPY contrib/ contrib/ - -# Configure project -RUN --mount=type=cache,target=/ccache \ - --mount=type=cache,target=/build \ - mkdir -p /build && \ - cmake -G Ninja -S /app -B /build \ - -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} \ - -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ - -DCMAKE_C_COMPILER_LAUNCHER=ccache \ - -DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=mold -static -g" \ - -DCMAKE_CXX_FLAGS="-g -fno-omit-frame-pointer" \ - -DCMAKE_C_FLAGS="-g -fno-omit-frame-pointer" \ - -DPROJECT_NAME="${PROJECT}" \ - -DCMAKE_STRIP=OFF \ - ${CMAKE_TOOLCHAIN_FILE:+-DCMAKE_TOOLCHAIN_FILE=$CMAKE_TOOLCHAIN_FILE} - -# Build project -RUN --mount=type=cache,target=/ccache \ - --mount=type=cache,target=/build \ - cmake --build /build - -# Copy the built executable to a regular directory for the final stage -RUN --mount=type=cache,target=/build \ - mkdir -p /output && \ - 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 - -ARG PROJECT - -# Copy the actual binary from the regular directory -COPY --from=builder /output/${PROJECT} /${PROJECT} \ No newline at end of file diff --git a/dehydrate/build.sh b/dehydrate/build.sh index 93b5a21..575db41 100755 --- a/dehydrate/build.sh +++ b/dehydrate/build.sh @@ -1,29 +1,26 @@ #!/bin/bash - -set -euo pipefail +# build.sh using docker run approach SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" PROJECT="dehydrate" -export CMAKE_BUILD_TYPE="Debug" - -rm -rf "${SCRIPT_DIR}/output" +# Create persistent build directory +mkdir -p "${SCRIPT_DIR}/build" mkdir -p "${SCRIPT_DIR}/output" -# make sure we have the latest base image. -docker pull gitea.jde.nz/public/dropshell-build-base:latest - -# Build with or without cache based on NO_CACHE environment variable -CACHE_FLAG="" -if [ "${NO_CACHE:-false}" = "true" ]; then - CACHE_FLAG="--no-cache" -fi - -docker build \ - ${CACHE_FLAG} \ - -t "${PROJECT}-build" \ - -f "${SCRIPT_DIR}/Dockerfile.dropshell-build" \ - --build-arg PROJECT="${PROJECT}" \ - --build-arg CMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE}" \ - --output "${SCRIPT_DIR}/output" \ - "${SCRIPT_DIR}" \ No newline at end of file +# Run build in container with mounted directories +docker run --rm \ + --user "$(id -u):$(id -g)" \ + -v "${SCRIPT_DIR}:/src:ro" \ + -v "${SCRIPT_DIR}/build:/build" \ + -v "${SCRIPT_DIR}/output:/output" \ + -e CMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE:-Debug}" \ + gitea.jde.nz/public/dropshell-build-base:latest \ + bash -c " + cd /build && \ + cmake -G Ninja -S /src -B . \ + -DCMAKE_BUILD_TYPE=\${CMAKE_BUILD_TYPE} \ + -DPROJECT_NAME=${PROJECT} && \ + cmake --build . && \ + cp ${PROJECT} /output/ + " \ No newline at end of file diff --git a/dehydrate/clean.sh b/dehydrate/clean.sh index 1366acd..cd967ac 100755 --- a/dehydrate/clean.sh +++ b/dehydrate/clean.sh @@ -7,18 +7,12 @@ PROJECT="dehydrate" echo "Cleaning ${PROJECT}..." -# Remove output directory -if [ -d "${SCRIPT_DIR}/output" ]; then - echo "Removing output directory..." - rm -rf "${SCRIPT_DIR}/output" -fi - -# Remove Docker images related to this project -echo "Removing Docker images..." -docker images --filter "reference=${PROJECT}-build*" -q | xargs -r docker rmi -f - -# Remove Docker build cache -echo "Pruning Docker build cache..." -docker builder prune -f +# Remove output and build directories +for dir in "output" "build"; do + if [ -d "${SCRIPT_DIR}/${dir}" ]; then + echo "Removing ${dir} directory..." + rm -rf "${SCRIPT_DIR:?}/${dir}" + fi +done echo "✓ ${PROJECT} cleaned successfully" \ No newline at end of file diff --git a/dehydrate/publish.sh b/dehydrate/publish.sh index 0ef79bc..deab3db 100755 --- a/dehydrate/publish.sh +++ b/dehydrate/publish.sh @@ -35,21 +35,7 @@ heading "Building ${PROJECT}" # build release version export CMAKE_BUILD_TYPE="Release" - -# Build with or without cache based on NO_CACHE environment variable -CACHE_FLAG="" -if [ "${NO_CACHE:-false}" = "true" ]; then - CACHE_FLAG="--no-cache" -fi - -docker build \ - ${CACHE_FLAG} \ - -t "${PROJECT}-build" \ - -f "${SCRIPT_DIR}/Dockerfile.dropshell-build" \ - --build-arg PROJECT="${PROJECT}" \ - --build-arg CMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE}" \ - --output "${OUTPUT}" \ - "${SCRIPT_DIR}" +"${SCRIPT_DIR}/build.sh" [ -f "${OUTPUT}/${PROJECT}" ] || die "Build failed." diff --git a/dehydrate/test/build_dehydrate_test.sh b/dehydrate/test/build_dehydrate_test.sh index cc13215..cb09a2a 100755 --- a/dehydrate/test/build_dehydrate_test.sh +++ b/dehydrate/test/build_dehydrate_test.sh @@ -4,7 +4,7 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" PROJECT_DIR="$( cd "$SCRIPT_DIR/.." && pwd )" -cd "$SCRIPT_DIR" +cd "$SCRIPT_DIR" || exit 1 # Clean up old test data and any existing binaries # Force removal with chmod to handle permission issues