Skip to content

Commit 68e7783

Browse files
Docker container not getting version string (#454)
* Fix workflow that builds docker containers so the version string compiled into the binary is accurate
1 parent d8090e9 commit 68e7783

File tree

4 files changed

+32
-18
lines changed

4 files changed

+32
-18
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- name: Checkout
2424
uses: actions/checkout@v4
2525
with:
26-
fetch-depth: '0'
26+
fetch-depth: '0' # need full history to get version from git tag
2727

2828
- name: Install packaged dependencies
2929
run: .github/install_dependencies

.github/workflows/build_containers.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ jobs:
1818

1919
- name: Checkout
2020
uses: actions/checkout@v4
21+
with:
22+
fetch-depth: '0' # need full history to get version from git tag
2123

2224
- name: Container metadata
2325
id: metadata
@@ -45,6 +47,7 @@ jobs:
4547
platforms: linux/amd64, linux/386, linux/arm64, linux/arm/v6, linux/arm/v7
4648
cache-from: type=gha
4749
cache-to: type=gha,mode=max
50+
context: .
4851
push: true
4952
tags: ${{ steps.metadata.outputs.tags }}
5053
labels: ${{ steps.metadata.outputs.labels }}

CMakeLists.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,15 @@ project (RTLSDR-Airband CXX)
33

44
execute_process(COMMAND git describe --tags --abbrev --dirty --always
55
OUTPUT_VARIABLE RTL_AIRBAND_VERSION
6-
OUTPUT_STRIP_TRAILING_WHITESPACE)
6+
OUTPUT_STRIP_TRAILING_WHITESPACE
7+
ERROR_VARIABLE RTL_AIRBAND_VERSION_ERROR
8+
ERROR_STRIP_TRAILING_WHITESPACE)
9+
10+
string(COMPARE EQUAL "${RTL_AIRBAND_VERSION}" "" RTL_AIRBAND_VERSION_UNSET)
11+
12+
if(RTL_AIRBAND_VERSION_UNSET)
13+
message(FATAL_ERROR "Failed to detect RTL_AIRBAND_VERSION - \"${RTL_AIRBAND_VERSION_ERROR}\"")
14+
endif()
715

816
set (CMAKE_CXX_STANDARD 11)
917
set (CXX_STANDARD_REQUIRED ON)

Dockerfile

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
# build container
22
FROM debian:bookworm-slim AS build
33

4-
# set working dir
5-
WORKDIR /app
6-
74
# install build dependencies
85
RUN apt-get update && \
96
apt-get upgrade -y && \
@@ -26,6 +23,9 @@ RUN apt-get update && \
2623
apt-get clean && \
2724
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
2825

26+
# set working dir for building rtl-sdr support
27+
WORKDIR /rtl_sdr_build
28+
2929
# compile / install rtl-sdr-blog version of rtl-sdr for v4 support
3030
RUN git clone https://github.com/rtlsdrblog/rtl-sdr-blog && \
3131
cd rtl-sdr-blog/ && \
@@ -38,26 +38,29 @@ RUN git clone https://github.com/rtlsdrblog/rtl-sdr-blog && \
3838

3939
# TODO: build anything from source?
4040

41+
# set working dir for project build
42+
WORKDIR /rtl_airband_build
43+
4144
# copy in the rtl_airband source
42-
COPY CMakeLists.txt src /app/
45+
# WARNING: not copying in the whole repo, this may need to be updated if build files are added outside of src/
46+
COPY ./.git/ .git/
47+
COPY ./src/ src/
48+
COPY ./CMakeLists.txt .
4349

4450
# configure and build
4551
# TODO: detect platforms
4652
RUN uname -m && \
47-
echo | gcc -### -v -E - | tee /app/compiler_native_info.txt && \
53+
echo | gcc -### -v -E - | tee compiler_native_info.txt && \
4854
cmake -B build_dir -DPLATFORM=generic -DCMAKE_BUILD_TYPE=Release -DNFM=TRUE -DBUILD_UNITTESTS=TRUE && \
4955
VERBOSE=1 cmake --build build_dir -j4
5056

5157
# make sure unit tests pass
52-
RUN ./build_dir/unittests
58+
RUN ./build_dir/src/unittests
5359

5460

5561
# application container
5662
FROM debian:bookworm-slim
5763

58-
# set working dir
59-
WORKDIR /app
60-
6164
# install runtime dependencies
6265
RUN apt-get update && \
6366
apt-get upgrade -y && \
@@ -76,20 +79,20 @@ RUN apt-get update && \
7679
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
7780

7881
# install (from build container) rtl-sdr-blog version of rtl-sdr for v4 support
79-
COPY --from=build /app/librtlsdr0_*.deb /app/librtlsdr-dev_*.deb /app/rtl-sdr_*.deb ./
80-
RUN dpkg -i librtlsdr0_*.deb && \
81-
dpkg -i librtlsdr-dev_*.deb && \
82-
dpkg -i rtl-sdr_*.deb && \
83-
rm -rf *.deb && \
82+
COPY --from=build /rtl_sdr_build/librtlsdr0_*.deb /rtl_sdr_build/librtlsdr-dev_*.deb /rtl_sdr_build/rtl-sdr_*.deb /tmp/
83+
RUN dpkg -i /tmp/librtlsdr0_*.deb && \
84+
dpkg -i /tmp/librtlsdr-dev_*.deb && \
85+
dpkg -i /tmp/rtl-sdr_*.deb && \
86+
rm -rf /tmp/*.deb && \
8487
echo '' | tee --append /etc/modprobe.d/rtl_sdr.conf && \
8588
echo 'blacklist dvb_usb_rtl28xxun' | tee --append /etc/modprobe.d/rtl_sdr.conf && \
8689
echo 'blacklist rtl2832' | tee --append /etc/modprobe.d/rtl_sdr.conf && \
8790
echo 'blacklist rtl2830' | tee --append /etc/modprobe.d/rtl_sdr.conf
8891

8992
# Copy rtl_airband from the build container
9093
COPY LICENSE /opt/rtl_airband/
91-
COPY --from=build /app/build_dir/unittests /opt/rtl_airband/
92-
COPY --from=build /app/build_dir/rtl_airband /opt/rtl_airband/
94+
COPY --from=build /rtl_airband_build/build_dir/src/unittests /opt/rtl_airband/
95+
COPY --from=build /rtl_airband_build/build_dir/src/rtl_airband /opt/rtl_airband/
9396
RUN chmod a+x /opt/rtl_airband/unittests /opt/rtl_airband/rtl_airband
9497

9598
# make sure unit tests pass

0 commit comments

Comments
 (0)