Skip to content

Commit

Permalink
optimize Dockerfile for size and build speed; add Container Version (#68
Browse files Browse the repository at this point in the history
)

* Dockerfile optimization

* change base image to minimize space

* add missing file

* rename files
  • Loading branch information
kx1t authored Jun 18, 2024
1 parent 4bcb20b commit bf6b3c9
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 24 deletions.
42 changes: 18 additions & 24 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,45 +1,39 @@
FROM ghcr.io/sdr-enthusiasts/docker-baseimage:mlatclient as downloader

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

ENV PRIVATE_MLAT="false" \
MLAT_INPUT_TYPE="dump1090"

COPY --from=downloader /mlatclient.tgz /src/mlatclient.tgz
ARG VERSION_REPO="sdr-enthusiasts/docker-radarvirtuel" \
VERSION_BRANCH="##BRANCH##"

# hadolint ignore=DL3008,SC2086,SC2039,SC2068,DL3003,DL3015,SC3054
RUN set -x && \
SHELL ["/bin/bash", "-x", "-o", "pipefail", "-c"]
RUN --mount=type=bind,from=downloader,source=/,target=/downloader/ \
# define packages needed for installation and general management of the container:
TEMP_PACKAGES=() && \
KEPT_PACKAGES=() && \
KEPT_PACKAGES+=(procps aptitude) && \
KEPT_PACKAGES+=(procps) && \
KEPT_PACKAGES+=(psmisc) && \
# Git and net-tools are needed to install and run @Mikenye's HealthCheck framework
# TEMP_PACKAGES+=(git) && \
# These are needed to compile and install the mlat_client:
# TEMP_PACKAGES+=(build-essential) && \
# TEMP_PACKAGES+=(debhelper) && \
# TEMP_PACKAGES+=(python3-dev) && \
# TEMP_PACKAGES+=(python3-distutils-extra) && \
# Needed to run the mlat_client:
KEPT_PACKAGES+=(python3-minimal) && \
KEPT_PACKAGES+=(python3-pkg-resources) && \
#
# Install all these packages:
apt-get update -q -y && \
apt-get install -o APT::Autoremove::RecommendsImportant=0 -o APT::Autoremove::SuggestsImportant=0 -o Dpkg::Options::="--force-confold" -y --no-install-recommends --no-install-suggests \
${KEPT_PACKAGES[@]} \
${TEMP_PACKAGES[@]} && \
#
# Compile and Install the mlat_client
# mkdir -p /git && \
# pushd /git && \
# git clone --depth 1 $URL_MLAT_CLIENT_REPO && \
# cd mlat-client && \
# ./setup.py install && \
# ln -s /usr/local/bin/mlat-client /usr/bin/mlat-client && \
# popd && \
# rm -rf /git && \
#
# New - install mlatclient that was copied in from downloader image
tar zxf /src/mlatclient.tgz -C / && \
# Install mlatclient that was copied in from downloader image
tar zxf /downloader/mlatclient.tgz -C / && \
# test mlat-client
/usr/bin/mlat-client --help > /dev/null && \
# remove pycache introduced by testing mlat-client
find /usr | grep -E "/__pycache__$" | xargs rm -rf || true && \
# Add Container Version
[[ "${VERSION_BRANCH:0:1}" == "#" ]] && VERSION_BRANCH="main" || true && \
echo "$(TZ=UTC date +%Y%m%d-%H%M%S)_$(curl -ssL https://api.github.com/repos/$VERSION_REPO/commits/$VERSION_BRANCH | awk '{if ($1=="\"sha\":") {print substr($2,2,7); exit}}')_$VERSION_BRANCH" > /.CONTAINER_VERSION && \
#
# Clean up
# apt-get remove -q -y ${TEMP_PACKAGES[@]} && \
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
oneshot
2 changes: 2 additions & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/01-print-container-version/up
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
exec /etc/s6-overlay/scripts/01-print-container-version
Empty file.
23 changes: 23 additions & 0 deletions rootfs/etc/s6-overlay/scripts/01-print-container-version
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/command/with-contenv bash
# shellcheck shell=bash disable=SC1091,SC2015,SC2154

source /scripts/common

# Print container version
#---------------------------------------------------------------------------------------------
# Copyright (C) 2023-2024, Ramon F. Kolb (kx1t) and contributors
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with this program.
# If not, see <https://www.gnu.org/licenses/>.
#---------------------------------------------------------------------------------------------

[[ -f /.CONTAINER_VERSION ]] && "${s6wrap[@]}" echo "Container Version: $(</.CONTAINER_VERSION), build date $(stat -c '%y' /.CONTAINER_VERSION |sed 's|\(.*\)\.[0-9]* \(.*\)|\1 \2|g')" || true

0 comments on commit bf6b3c9

Please sign in to comment.