Update 3 files
Some checks failed
Build-Test-Publish / build (linux/amd64) (push) Failing after 7s
Build-Test-Publish / build (linux/arm64) (push) Failing after 9s
Build-Test-Publish / test-install-from-scratch (linux/amd64) (push) Has been skipped
Build-Test-Publish / test-install-from-scratch (linux/arm64) (push) Has been skipped

This commit is contained in:
Your Name
2025-06-29 21:32:18 +12:00
parent 70cb5c1b3a
commit 719475e29f
3 changed files with 21 additions and 118 deletions

View File

@ -1,76 +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 only build files first (for better layer caching)
COPY CMakeLists.txt cmake_prebuild.sh ./
COPY src/version.hpp.in src/
# Run prebuild script early (this rarely changes)
RUN bash cmake_prebuild.sh
# Copy source files (this invalidates cache when source changes)
COPY src/ src/
# Configure project (this step is cached unless CMakeLists.txt changes)
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" \
-DPROJECT_NAME="${PROJECT}" \
-DCMAKE_STRIP=OFF \
${CMAKE_TOOLCHAIN_FILE:+-DCMAKE_TOOLCHAIN_FILE=$CMAKE_TOOLCHAIN_FILE}
# Run prebuild script
RUN --mount=type=cache,target=/ccache \
--mount=type=cache,target=/build \
cmake --build /build --target run_prebuild_script
# Build project (ccache will help here when only some files change)
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 CA certificates for SSL validation
#COPY --from=builder /etc/ssl/certs/ /etc/ssl/certs/
# Copy the actual binary from the regular directory
COPY --from=builder /output/${PROJECT} /${PROJECT}

View File

@ -1,32 +1,26 @@
#!/bin/bash #!/bin/bash
# build.sh using docker run approach
set -euo pipefail
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" 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"
PROJECT="getpkg" PROJECT="getpkg"
# make sure we have the latest base image. # Create persistent build directory
docker pull gitea.jde.nz/public/dropshell-build-base:latest mkdir -p "${SCRIPT_DIR}/build"
mkdir -p "${SCRIPT_DIR}/output"
# 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}"
# 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/
"

View File

@ -34,22 +34,7 @@ heading "Building ${PROJECT}"
# build release version # build release version
export CMAKE_BUILD_TYPE="Release" export CMAKE_BUILD_TYPE="Release"
"${SCRIPT_DIR}/build.sh"
# 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}"
[ -f "${OUTPUT}/${PROJECT}" ] || die "Build failed." [ -f "${OUTPUT}/${PROJECT}" ] || die "Build failed."
#-------------------------------------------------------------------------------- #--------------------------------------------------------------------------------