Skip to content

Commit

Permalink
make Dockerfile more efficient
Browse files Browse the repository at this point in the history
  • Loading branch information
kx1t committed Oct 23, 2023
1 parent 81a57b5 commit f3cd18f
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 12 deletions.
45 changes: 33 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,35 @@
FROM ghcr.io/sdr-enthusiasts/docker-baseimage:base

ARG radarurl="ftp://public.tubby.org/radar-0.99.tar.gz"
ARG radarurlcreds="ftp:"

RUN set -x && \
FROM ghcr.io/sdr-enthusiasts/docker-baseimage:base as build
# define packages needed for installation and general management of the container:
RUN set -x && \
TEMP_PACKAGES=() && \
KEPT_PACKAGES=() && \
#
TEMP_PACKAGES+=(pkg-config) && \
TEMP_PACKAGES+=(build-essential) && \
# Install all the apt packages:
apt-get update -q && \
apt-get install -q -o APT::Autoremove::RecommendsImportant=0 -o APT::Autoremove::SuggestsImportant=0 -o Dpkg::Options::="--force-confold" -y --no-install-recommends --no-install-suggests ${TEMP_PACKAGES[@]} ${KEPT_PACKAGES[@]} && \
#
# install stuff
mkdir -p /src && \
pushd /src && \
curl -sSL -u $radarurlcreds $radarurl -o radar.tgz && \
tar zxf radar.tgz && \
mv -f radar-* radar && \
cd radar && \
make && \
make install && \
popd


FROM ghcr.io/sdr-enthusiasts/docker-baseimage:base

COPY --from=build /usr/sbin/radar /usr/sbin/radar

RUN set -x && \
# define packages needed for installation and general management of the container:
KEPT_PACKAGES=() && \
KEPT_PACKAGES+=(tcpdump) && \
KEPT_PACKAGES+=(logrotate) && \
#
Expand All @@ -30,16 +50,17 @@ RUN set -x && \
useradd -U -M -s /usr/sbin/nologin radar && \
#
# Clean up
echo Uninstalling $TEMP_PACKAGES && \
apt-get remove -y -q ${TEMP_PACKAGES[@]} && \
echo Autoremoving/cleaning APT && \
apt-get autoremove -q -o APT::Autoremove::RecommendsImportant=0 -o APT::Autoremove::SuggestsImportant=0 -y && \
apt-get clean -y -q && \
rm -rf \
/src/* \
/tmp/* \
/var/lib/apt/lists/* \
/.dockerenv \
/git && \
/src/* \
/tmp/* \
/var/lib/apt/lists/* \
/.dockerenv \
/git && \
#
# add version to the container
version="$(/usr/sbin/radar -v | sed 's/^.*Version \(.*\)$/\1/g;q')" && \
echo "${version// /_} ($(uname -m))" > /.CONTAINER_VERSION
#
Expand Down
57 changes: 57 additions & 0 deletions Dockerfile.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
FROM ghcr.io/sdr-enthusiasts/docker-baseimage:base

ARG radarurl="ftp://public.tubby.org/radar-0.99.tar.gz"
ARG radarurlcreds="ftp:"

RUN set -x && \
# define packages needed for installation and general management of the container:
TEMP_PACKAGES=() && \
KEPT_PACKAGES=() && \
#
TEMP_PACKAGES+=(pkg-config) && \
TEMP_PACKAGES+=(build-essential) && \
KEPT_PACKAGES+=(tcpdump) && \
KEPT_PACKAGES+=(logrotate) && \
#
# Install all the apt packages:
apt-get update -q && \
apt-get install -q -o APT::Autoremove::RecommendsImportant=0 -o APT::Autoremove::SuggestsImportant=0 -o Dpkg::Options::="--force-confold" -y --no-install-recommends --no-install-suggests ${TEMP_PACKAGES[@]} ${KEPT_PACKAGES[@]} && \
#
# install stuff
mkdir -p /src && \
pushd /src && \
curl -sSL -u $radarurlcreds $radarurl -o radar.tgz && \
tar zxf radar.tgz && \
mv -f radar-* radar && \
cd radar && \
make && \
make install && \
popd && \
useradd -U -M -s /usr/sbin/nologin radar && \
#
# Clean up
echo Uninstalling $TEMP_PACKAGES && \
apt-get remove -y -q ${TEMP_PACKAGES[@]} && \
apt-get autoremove -q -o APT::Autoremove::RecommendsImportant=0 -o APT::Autoremove::SuggestsImportant=0 -y && \
apt-get clean -y -q && \
rm -rf \
/src/* \
/tmp/* \
/var/lib/apt/lists/* \
/.dockerenv \
/git && \
version="$(/usr/sbin/radar -v | sed 's/^.*Version \(.*\)$/\1/g;q')" && \
echo "${version// /_} ($(uname -m))" > /.CONTAINER_VERSION
#
COPY rootfs/ /
#
RUN set -x && \
#
# Do some other stuff
echo "alias dir=\"ls -alsv\"" >> /root/.bashrc && \
echo "alias nano=\"nano -l\"" >> /root/.bashrc

HEALTHCHECK --interval=300s --timeout=30s --start-period=300s --start-interval=30s --retries=1 CMD /scripts/healthcheck.sh
#
# No need for SHELL and ENTRYPOINT as those are inherited from the base image
#

0 comments on commit f3cd18f

Please sign in to comment.