From 1ac00e83f8a68eecde2dd518a967d16613a87f5e Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 14 Jun 2025 22:07:46 +1200 Subject: [PATCH] 'Generic Commit' --- .gitea/workflows/dropshell-build.yaml | 17 +++--- CLAUDE.md | 7 --- build-base/Dockerfile.dropshell-build-base | 1 - build-base/build.sh | 28 ++++----- build-base/publish.sh | 23 ++++++++ build.sh | 57 ------------------ publish.sh | 46 --------------- .../Dockerfile.test-build | 3 +- tests/build.sh | 58 +++++++++++++++++++ tests/clear-cache.sh | 19 ++++++ tests/ipdemo/CMakeLists.txt | 37 +++++++++++- test.sh => tests/test.sh | 12 ++-- 12 files changed, 164 insertions(+), 144 deletions(-) create mode 100755 build-base/publish.sh delete mode 100755 build.sh delete mode 100755 publish.sh rename Dockerfile.dropshell-build => tests/Dockerfile.test-build (95%) create mode 100755 tests/build.sh create mode 100755 tests/clear-cache.sh rename test.sh => tests/test.sh (67%) diff --git a/.gitea/workflows/dropshell-build.yaml b/.gitea/workflows/dropshell-build.yaml index ea51a93..0155662 100644 --- a/.gitea/workflows/dropshell-build.yaml +++ b/.gitea/workflows/dropshell-build.yaml @@ -19,15 +19,18 @@ jobs: registry: gitea.jde.nz username: DoesntMatter password: ${{ secrets.DOCKER_PUSH_TOKEN }} - - name: Build Base + - name: Build Base - Multiple Architectures run: | cd build-base && ./build.sh - - name: Build + - name: Build Test Applications run: | - ./build.sh - - name: Test + cd tests && ./build.sh + - name: Run Tests run: | - ./test.sh - - name: Publish + cd tests && ./test.sh + - name: Publish as Latest run: | - SOS_WRITE_TOKEN=${{ secrets.SOS_WRITE_TOKEN }} DOCKER_PUSH_TOKEN=${{ secrets.DOCKER_PUSH_TOKEN }} ./publish.sh + cd build-base && \ + SOS_WRITE_TOKEN=${{ secrets.SOS_WRITE_TOKEN }} \ + DOCKER_PUSH_TOKEN=${{ secrets.DOCKER_PUSH_TOKEN }} \ + ./publish.sh diff --git a/CLAUDE.md b/CLAUDE.md index 5e38672..ba7e4be 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -21,13 +21,6 @@ cd build-base ``` This creates the `gitea.jde.nz/public/dropshell-build-base:latest` Docker image for your current architecture and loads it into Docker. -For multiarch build (without loading): -```bash -cd build-base -BUILD_MODE=multiarch ./build.sh -``` -This builds for linux/amd64 and linux/arm64 but keeps the image in the buildx cache only. - ### Building a Project ```bash ./build.sh diff --git a/build-base/Dockerfile.dropshell-build-base b/build-base/Dockerfile.dropshell-build-base index 37337e6..1cb60dd 100644 --- a/build-base/Dockerfile.dropshell-build-base +++ b/build-base/Dockerfile.dropshell-build-base @@ -200,7 +200,6 @@ RUN curl -LO https://github.com/gabime/spdlog/archive/refs/tags/v${SPDLOG_VERSIO #ARG DROGON_VERSION=1.9.5 WORKDIR /tmp RUN git clone --recurse-submodules https://github.com/drogonframework/drogon.git /tmp/drogon && \ -#RUN git clone --branch v${DROGON_VERSION} --depth 1 https://github.com/drogonframework/drogon.git /tmp/drogon && \ mkdir -p /tmp/drogon/build && \ cd /tmp/drogon/build && \ cmake .. \ diff --git a/build-base/build.sh b/build-base/build.sh index 6876c24..2ba2c90 100755 --- a/build-base/build.sh +++ b/build-base/build.sh @@ -5,22 +5,14 @@ set -euo pipefail SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" # Create buildx builder if it doesn't exist -docker buildx create --name multiarch --use 2>/dev/null || docker buildx use multiarch +docker buildx create --name multiarch --use \ + --driver-opt env.BUILDKIT_MAX_PARALLELISM=4 \ + 2>/dev/null || docker buildx use multiarch -# Detect if we're building for testing or publishing -if [ "${BUILD_MODE:-test}" = "multiarch" ]; then - # Build multi-platform image (for publishing) - docker buildx build \ - --platform linux/amd64,linux/arm64 \ - -t "gitea.jde.nz/public/dropshell-build-base:latest" \ - -f "${SCRIPT_DIR}/Dockerfile.dropshell-build-base" \ - ${SCRIPT_DIR} -else - # Build single-platform image for current architecture and load it - docker buildx build \ - --load \ - -t "gitea.jde.nz/public/dropshell-build-base:latest" \ - -f "${SCRIPT_DIR}/Dockerfile.dropshell-build-base" \ - ${SCRIPT_DIR} -fi - \ No newline at end of file +# Build multi-platform image and push it +docker buildx build \ + --platform linux/amd64,linux/arm64 \ + --push \ + -t "gitea.jde.nz/public/dropshell-build-base:test" \ + -f "${SCRIPT_DIR}/Dockerfile.dropshell-build-base" \ + ${SCRIPT_DIR} diff --git a/build-base/publish.sh b/build-base/publish.sh new file mode 100755 index 0000000..c94e84f --- /dev/null +++ b/build-base/publish.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +set -euo pipefail + +# check standard variables present. +[[ -n $SOS_WRITE_TOKEN ]] || die "SOS_WRITE_TOKEN not specified" +[[ -n $DOCKER_PUSH_TOKEN ]] || die "DOCKER_PUSH_TOKEN not specified" + + +echo "Publishing dropshell-build-base:test as :latest..." + +# Pull the multiarch manifest from :test tag +docker buildx imagetools create \ + --tag gitea.jde.nz/public/dropshell-build-base:latest \ + gitea.jde.nz/public/dropshell-build-base:test + +echo "Successfully tagged dropshell-build-base:test as :latest" + +# Show the manifest to confirm it's multiarch +echo "" +echo "Verifying multiarch manifest:" +docker buildx imagetools inspect gitea.jde.nz/public/dropshell-build-base:latest + diff --git a/build.sh b/build.sh deleted file mode 100755 index d25d591..0000000 --- a/build.sh +++ /dev/null @@ -1,57 +0,0 @@ -#!/bin/bash - -set -euo pipefail - -SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" - - -export CMAKE_BUILD_TYPE="Debug" - -rm -rf "${SCRIPT_DIR}/output" -mkdir -p "${SCRIPT_DIR}/output" - -# If PROJECT is set, build only that project -if [ -n "${PROJECT:-}" ]; then - docker build \ - -t "gitea.jde.nz/public/${PROJECT}-build:latest" \ - -f "${SCRIPT_DIR}/Dockerfile.dropshell-build" \ - --build-arg PROJECT="${PROJECT}" \ - --build-arg CMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE}" \ - --output "${SCRIPT_DIR}/output" \ - "${SCRIPT_DIR}/tests/${PROJECT}" -else - # Build all projects - PROJECT="ipdemo" - docker build \ - -t "gitea.jde.nz/public/${PROJECT}-build:latest" \ - -f "${SCRIPT_DIR}/Dockerfile.dropshell-build" \ - --build-arg PROJECT="${PROJECT}" \ - --build-arg CMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE}" \ - --output "${SCRIPT_DIR}/output" \ - "${SCRIPT_DIR}/tests/${PROJECT}" - - - - # Test aarch64 build of ipdemo - echo "Building ipdemo for aarch64..." - PROJECT="ipdemo" - docker buildx build \ - --platform linux/arm64 \ - -t "gitea.jde.nz/public/ipdemo-build:aarch64" \ - -f "${SCRIPT_DIR}/Dockerfile.dropshell-build" \ - --build-arg PROJECT="${PROJECT}" \ - --build-arg CMAKE_BUILD_TYPE="Debug" \ - --output "${SCRIPT_DIR}/output/aarch64" \ - "${SCRIPT_DIR}/tests/${PROJECT}" - - - PROJECT="test_libs" - docker build \ - -t "gitea.jde.nz/public/${PROJECT}-build:latest" \ - -f "${SCRIPT_DIR}/Dockerfile.dropshell-build" \ - --build-arg PROJECT="${PROJECT}" \ - --build-arg CMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE}" \ - --output "${SCRIPT_DIR}/output" \ - "${SCRIPT_DIR}/tests/${PROJECT}" -fi - diff --git a/publish.sh b/publish.sh deleted file mode 100755 index 417d0a2..0000000 --- a/publish.sh +++ /dev/null @@ -1,46 +0,0 @@ -#!/bin/bash - -set -euo pipefail - -die() { - echo "Fatal error:" - echo "$1" - exit 1 -} - -# check the variables are present -[[ -n $SOS_WRITE_TOKEN ]] || die "SOS_WRITE_TOKEN not specified" -[[ -n $DOCKER_PUSH_TOKEN ]] || die "DOCKER_PUSH_TOKEN not specified" - - -# Publish gitea.jde.nz/public/dropshell-build-base:latest - -# login to registry handled by gitea workflow, otherwise asssume handled manually. -#docker login -u "anything" -p "${DOCKER_PUSH_TOKEN}" gitea.jde.nz - -# Build and push the multi-platform image -docker buildx build \ - --platform linux/amd64,linux/arm64 \ - -t "gitea.jde.nz/public/dropshell-build-base:latest" \ - -f "build-base/Dockerfile.dropshell-build-base" \ - --push \ - build-base/ - - - -#SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" - - - -# # download the sos binary -# SOS="${SCRIPT_DIR}/temp/sos" -# mkdir -p "${SCRIPT_DIR}/temp" -# trap 'rm -rf "${SCRIPT_DIR}/temp"' EXIT - -# curl -L -o "${SOS}" https://getbin.xyz/sos -# chmod +x "${SOS}" - -# # upload the dropshell-build script -# "${SOS}" upload "getbin.xyz" "${SCRIPT_DIR}/Dockerfile.dropshell-build" "Dockerfile.dropshell-build:latest" - -echo "Done" \ No newline at end of file diff --git a/Dockerfile.dropshell-build b/tests/Dockerfile.test-build similarity index 95% rename from Dockerfile.dropshell-build rename to tests/Dockerfile.test-build index c0d6bfa..130ba5d 100644 --- a/Dockerfile.dropshell-build +++ b/tests/Dockerfile.test-build @@ -1,4 +1,5 @@ -FROM gitea.jde.nz/public/dropshell-build-base:latest AS builder +ARG IMAGE_TAG +FROM gitea.jde.nz/public/dropshell-build-base:test AS builder ARG PROJECT ARG CMAKE_BUILD_TYPE=Debug diff --git a/tests/build.sh b/tests/build.sh new file mode 100755 index 0000000..930c006 --- /dev/null +++ b/tests/build.sh @@ -0,0 +1,58 @@ +#!/bin/bash + +set -euo pipefail + +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" + +#make canonical +ROOT_DIR="$(cd "${SCRIPT_DIR}/../" &> /dev/null && pwd)" + + +export CMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE:-Debug}" + +# Function to build a project +build_project() { + local project="$1" + local platform="${2:-}" + + local build_cmd + local tag + local output_dir + + + if [ -n "${platform}" ]; then + build_cmd=(docker buildx build "--platform" "${platform}") + local tag_suffix="${platform##*/}" # Extract arch from platform (e.g., linux/arm64 -> arm64) + tag="gitea.jde.nz/public/${project}-build-${tag_suffix}:test" + output_dir="${SCRIPT_DIR}/output/${tag_suffix}" + else + build_cmd=(docker build) + tag="gitea.jde.nz/public/${project}-build:test" + output_dir="${SCRIPT_DIR}/output/native" + fi + + mkdir -p "${output_dir}" + + "${build_cmd[@]}" \ + -t "${tag}" \ + -f "${SCRIPT_DIR}/Dockerfile.test-build" \ + --build-arg PROJECT="${project}" \ + --build-arg CMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE}" \ + --output "${output_dir}" \ + "${SCRIPT_DIR}/${project}" +} + +# Clean and prepare output directory +rm -rf "${SCRIPT_DIR}/output" +mkdir -p "${SCRIPT_DIR}/output" + +# Build all projects +echo "Building ipdemo..." +build_project "ipdemo" + +echo "Building ipdemo for aarch64..." +build_project "ipdemo" "linux/arm64" + +echo "Building test_libs..." +build_project "test_libs" + diff --git a/tests/clear-cache.sh b/tests/clear-cache.sh new file mode 100755 index 0000000..bdbbcf4 --- /dev/null +++ b/tests/clear-cache.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +set -euo pipefail + +echo "Clearing Docker build cache..." + +# Clear the build cache +docker builder prune -af + +# Optional: Also clear dangling images and containers +echo "Cleaning up dangling images and stopped containers..." +docker system prune -f + +echo "Build cache cleared successfully!" + +# Show disk usage after cleanup +echo "" +echo "Docker disk usage after cleanup:" +docker system df \ No newline at end of file diff --git a/tests/ipdemo/CMakeLists.txt b/tests/ipdemo/CMakeLists.txt index f14be99..f0d8966 100644 --- a/tests/ipdemo/CMakeLists.txt +++ b/tests/ipdemo/CMakeLists.txt @@ -29,7 +29,42 @@ target_include_directories(${PROJECT_NAME} PRIVATE # Find packages set(CMAKE_PREFIX_PATH /usr/local) -find_package(OpenSSL REQUIRED) + +# Find OpenSSL libraries in multiple possible locations +find_library(OPENSSL_SSL_LIB + NAMES ssl libssl libssl.a + PATHS /usr/local/lib /usr/local/lib64 /usr/lib /usr/lib64 + NO_DEFAULT_PATH +) + +find_library(OPENSSL_CRYPTO_LIB + NAMES crypto libcrypto libcrypto.a + PATHS /usr/local/lib /usr/local/lib64 /usr/lib /usr/lib64 + NO_DEFAULT_PATH +) + +if(NOT OPENSSL_SSL_LIB OR NOT OPENSSL_CRYPTO_LIB) + message(FATAL_ERROR "Could not find OpenSSL libraries. SSL: ${OPENSSL_SSL_LIB}, Crypto: ${OPENSSL_CRYPTO_LIB}") +endif() + +# Manually create OpenSSL targets for cross-compilation +if(NOT TARGET OpenSSL::Crypto) + add_library(OpenSSL::Crypto STATIC IMPORTED) + set_target_properties(OpenSSL::Crypto PROPERTIES + IMPORTED_LOCATION ${OPENSSL_CRYPTO_LIB} + INTERFACE_INCLUDE_DIRECTORIES /usr/local/include + ) +endif() + +if(NOT TARGET OpenSSL::SSL) + add_library(OpenSSL::SSL STATIC IMPORTED) + set_target_properties(OpenSSL::SSL PROPERTIES + IMPORTED_LOCATION ${OPENSSL_SSL_LIB} + INTERFACE_INCLUDE_DIRECTORIES /usr/local/include + INTERFACE_LINK_LIBRARIES OpenSSL::Crypto + ) +endif() + find_package(Drogon CONFIG REQUIRED) find_package(nlohmann_json REQUIRED) diff --git a/test.sh b/tests/test.sh similarity index 67% rename from test.sh rename to tests/test.sh index 60ceff4..61148f9 100755 --- a/test.sh +++ b/tests/test.sh @@ -8,9 +8,9 @@ echo "" echo "testing test_libs..." # Run test_libs -if [ -f "${SCRIPT_DIR}/output/test_libs" ]; then +if [ -f "${SCRIPT_DIR}/output/native/test_libs" ]; then echo "Running test_libs..." - "${SCRIPT_DIR}/output/test_libs" + "${SCRIPT_DIR}/output/native/test_libs" echo "test_libs completed successfully!" else echo "test_libs binary not found" @@ -21,9 +21,9 @@ echo "" echo "Testing ipdemo..." # Check if ipdemo exists -if [ -f "${SCRIPT_DIR}/output/ipdemo" ]; then +if [ -f "${SCRIPT_DIR}/output/native/ipdemo" ]; then echo "Running ipdemo..." - "${SCRIPT_DIR}/output/ipdemo" || echo "ipdemo test completed!" + "${SCRIPT_DIR}/output/native/ipdemo" || echo "ipdemo test completed!" else echo "ipdemo binary not found - run ./build.sh first" fi @@ -32,10 +32,10 @@ echo "" echo "Testing cross-architecture builds..." # Verify the binary was built and check its architecture -if [ -f "${SCRIPT_DIR}/output/aarch64/ipdemo" ]; then +if [ -f "${SCRIPT_DIR}/output/arm64/ipdemo" ]; then echo "aarch64 ipdemo binary built successfully!" echo "Architecture info:" - file "${SCRIPT_DIR}/output/aarch64/ipdemo" || true + file "${SCRIPT_DIR}/output/arm64/ipdemo" || true else echo "aarch64 ipdemo binary not found" fi \ No newline at end of file