From 68e7783ad0a556f47f74109fe090f3ebe234c57d Mon Sep 17 00:00:00 2001 From: charlie-foxtrot <13514783+charlie-foxtrot@users.noreply.github.com> Date: Mon, 22 Jan 2024 11:21:56 -0800 Subject: [PATCH] Docker container not getting version string (#454) * Fix workflow that builds docker containers so the version string compiled into the binary is accurate --- .github/workflows/build.yml | 2 +- .github/workflows/build_containers.yml | 3 +++ CMakeLists.txt | 10 +++++++- Dockerfile | 35 ++++++++++++++------------ 4 files changed, 32 insertions(+), 18 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e5163f1..2017735 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -23,7 +23,7 @@ jobs: - name: Checkout uses: actions/checkout@v4 with: - fetch-depth: '0' + fetch-depth: '0' # need full history to get version from git tag - name: Install packaged dependencies run: .github/install_dependencies diff --git a/.github/workflows/build_containers.yml b/.github/workflows/build_containers.yml index 1872673..8afd930 100644 --- a/.github/workflows/build_containers.yml +++ b/.github/workflows/build_containers.yml @@ -18,6 +18,8 @@ jobs: - name: Checkout uses: actions/checkout@v4 + with: + fetch-depth: '0' # need full history to get version from git tag - name: Container metadata id: metadata @@ -45,6 +47,7 @@ jobs: platforms: linux/amd64, linux/386, linux/arm64, linux/arm/v6, linux/arm/v7 cache-from: type=gha cache-to: type=gha,mode=max + context: . push: true tags: ${{ steps.metadata.outputs.tags }} labels: ${{ steps.metadata.outputs.labels }} diff --git a/CMakeLists.txt b/CMakeLists.txt index a4d92be..b04d1ca 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,15 @@ project (RTLSDR-Airband CXX) execute_process(COMMAND git describe --tags --abbrev --dirty --always OUTPUT_VARIABLE RTL_AIRBAND_VERSION - OUTPUT_STRIP_TRAILING_WHITESPACE) + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_VARIABLE RTL_AIRBAND_VERSION_ERROR + ERROR_STRIP_TRAILING_WHITESPACE) + +string(COMPARE EQUAL "${RTL_AIRBAND_VERSION}" "" RTL_AIRBAND_VERSION_UNSET) + +if(RTL_AIRBAND_VERSION_UNSET) + message(FATAL_ERROR "Failed to detect RTL_AIRBAND_VERSION - \"${RTL_AIRBAND_VERSION_ERROR}\"") +endif() set (CMAKE_CXX_STANDARD 11) set (CXX_STANDARD_REQUIRED ON) diff --git a/Dockerfile b/Dockerfile index bd71d6e..4ded706 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,6 @@ # build container FROM debian:bookworm-slim AS build -# set working dir -WORKDIR /app - # install build dependencies RUN apt-get update && \ apt-get upgrade -y && \ @@ -26,6 +23,9 @@ RUN apt-get update && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* +# set working dir for building rtl-sdr support +WORKDIR /rtl_sdr_build + # compile / install rtl-sdr-blog version of rtl-sdr for v4 support RUN git clone https://github.com/rtlsdrblog/rtl-sdr-blog && \ cd rtl-sdr-blog/ && \ @@ -38,26 +38,29 @@ RUN git clone https://github.com/rtlsdrblog/rtl-sdr-blog && \ # TODO: build anything from source? +# set working dir for project build +WORKDIR /rtl_airband_build + # copy in the rtl_airband source -COPY CMakeLists.txt src /app/ +# WARNING: not copying in the whole repo, this may need to be updated if build files are added outside of src/ +COPY ./.git/ .git/ +COPY ./src/ src/ +COPY ./CMakeLists.txt . # configure and build # TODO: detect platforms RUN uname -m && \ - echo | gcc -### -v -E - | tee /app/compiler_native_info.txt && \ + echo | gcc -### -v -E - | tee compiler_native_info.txt && \ cmake -B build_dir -DPLATFORM=generic -DCMAKE_BUILD_TYPE=Release -DNFM=TRUE -DBUILD_UNITTESTS=TRUE && \ VERBOSE=1 cmake --build build_dir -j4 # make sure unit tests pass -RUN ./build_dir/unittests +RUN ./build_dir/src/unittests # application container FROM debian:bookworm-slim -# set working dir -WORKDIR /app - # install runtime dependencies RUN apt-get update && \ apt-get upgrade -y && \ @@ -76,11 +79,11 @@ RUN apt-get update && \ rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* # install (from build container) rtl-sdr-blog version of rtl-sdr for v4 support -COPY --from=build /app/librtlsdr0_*.deb /app/librtlsdr-dev_*.deb /app/rtl-sdr_*.deb ./ -RUN dpkg -i librtlsdr0_*.deb && \ - dpkg -i librtlsdr-dev_*.deb && \ - dpkg -i rtl-sdr_*.deb && \ - rm -rf *.deb && \ +COPY --from=build /rtl_sdr_build/librtlsdr0_*.deb /rtl_sdr_build/librtlsdr-dev_*.deb /rtl_sdr_build/rtl-sdr_*.deb /tmp/ +RUN dpkg -i /tmp/librtlsdr0_*.deb && \ + dpkg -i /tmp/librtlsdr-dev_*.deb && \ + dpkg -i /tmp/rtl-sdr_*.deb && \ + rm -rf /tmp/*.deb && \ echo '' | tee --append /etc/modprobe.d/rtl_sdr.conf && \ echo 'blacklist dvb_usb_rtl28xxun' | tee --append /etc/modprobe.d/rtl_sdr.conf && \ echo 'blacklist rtl2832' | tee --append /etc/modprobe.d/rtl_sdr.conf && \ @@ -88,8 +91,8 @@ RUN dpkg -i librtlsdr0_*.deb && \ # Copy rtl_airband from the build container COPY LICENSE /opt/rtl_airband/ -COPY --from=build /app/build_dir/unittests /opt/rtl_airband/ -COPY --from=build /app/build_dir/rtl_airband /opt/rtl_airband/ +COPY --from=build /rtl_airband_build/build_dir/src/unittests /opt/rtl_airband/ +COPY --from=build /rtl_airband_build/build_dir/src/rtl_airband /opt/rtl_airband/ RUN chmod a+x /opt/rtl_airband/unittests /opt/rtl_airband/rtl_airband # make sure unit tests pass