Skip to content

Commit

Permalink
Docker container not getting version string (#454)
Browse files Browse the repository at this point in the history
* Fix workflow that builds docker containers so the version string compiled into the binary is accurate
  • Loading branch information
charlie-foxtrot authored Jan 22, 2024
1 parent d8090e9 commit 68e7783
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/build_containers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 }}
Expand Down
10 changes: 9 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
35 changes: 19 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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 && \
Expand All @@ -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/ && \
Expand All @@ -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 && \
Expand All @@ -76,20 +79,20 @@ 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 && \
echo 'blacklist rtl2830' | tee --append /etc/modprobe.d/rtl_sdr.conf

# 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
Expand Down

0 comments on commit 68e7783

Please sign in to comment.