Skip to content

Commit

Permalink
reduce container size by 80 MB (#196)
Browse files Browse the repository at this point in the history
  • Loading branch information
wiedehopf authored Jun 11, 2024
1 parent 82e0ebc commit 8366921
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 92 deletions.
46 changes: 18 additions & 28 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,34 +30,28 @@ ENV BEASTPORT=30005 \

SHELL ["/bin/bash", "-o", "pipefail", "-c"]

#COPY rootfs/tar1090-install.sh /
#COPY rootfs/etc/nginx.tar1090 /etc/nginx.tar1090
# for dev testing, rootfs copy can be moved after run, then these two lines above are needed

COPY rootfs/ /

# add telegraf binary
##telegraf##COPY --from=telegraf /usr/bin/telegraf /usr/bin/telegraf

RUN set -x && \
RUN \
--mount=type=bind,source=./,target=/app/ \
set -x && \
TEMP_PACKAGES=() && \
KEPT_PACKAGES=() && \
# Essentials (git is kept for aircraft db updates)
KEPT_PACKAGES+=(git) && \
TEMP_PACKAGES+=(git) && \
# tar1090
KEPT_PACKAGES+=(nginx-light) && \
# graphs1090
KEPT_PACKAGES+=(collectd-core) && \
KEPT_PACKAGES+=(rrdtool) && \
KEPT_PACKAGES+=(unzip) && \
KEPT_PACKAGES+=(bash-builtins) && \
KEPT_PACKAGES+=(libpython3.11) && \
KEPT_PACKAGES+=(libncurses6) && \
# healthchecks
KEPT_PACKAGES+=(jq) && \
# install packages
apt-get update && \
apt-get install -y --no-install-recommends \
apt-get install -y --no-install-suggests --no-install-recommends \
${KEPT_PACKAGES[@]} \
${TEMP_PACKAGES[@]} \
&& \
Expand All @@ -69,21 +63,17 @@ RUN set -x && \
# nginx: remove default config
rm /etc/nginx/sites-enabled/default && \
# tar1090: install using project copy of original script
bash /tar1090-install.sh /run/readsb webroot "${TAR1090_INSTALL_DIR}" && \
bash /app/rootfs/tar1090-install.sh /run/readsb webroot "${TAR1090_INSTALL_DIR}" && \
# change some /run/tar1090-webroot to /run/readsb to make work with existing docker scripting
sed -i -e 's#/run/tar1090-webroot/#/run/readsb/#' /usr/local/share/tar1090/nginx-tar1090-webroot.conf && \
# tar1090-db: document version
pushd "${TAR1090_UPDATE_DIR}/git-db" || exit 1 && \
bash -ec 'echo "tar1090-db $(git log | head -1 | tr -s " " "_")" >> /VERSIONS' && \
popd && \
echo "tar1090-db $(cat ${TAR1090_UPDATE_DIR}/git-db/version)" >> VERSIONS && \
# tar1090: document version
pushd "${TAR1090_UPDATE_DIR}/git" || exit 1 && \
bash -ec 'echo "tar1090 $(git log | head -1 | tr -s " " "_")" >> /VERSIONS' && \
popd && \
echo "tar1090 $(cat ${TAR1090_UPDATE_DIR}/git/version)" >> VERSIONS && \
# tar1090: remove tar1090-update files as they're not needed unless tar1090-update is active
rm -rf "${TAR1090_UPDATE_DIR}" && \
# tar1090: add nginx config
cp -Rv /etc/nginx.tar1090/* /etc/nginx/ && \
cp -Rv /app/rootfs/etc/nginx.tar1090/* /etc/nginx/ && \
# aircraft-db, file in TAR1090_UPDATE_DIR will be preferred when starting readsb if tar1090-update enabled
curl -o "${TAR1090_INSTALL_DIR}/aircraft.csv.gz" "https://raw.githubusercontent.com/wiedehopf/tar1090-db/csv/aircraft.csv.gz" && \
# clone graphs1090 repo
Expand Down Expand Up @@ -159,22 +149,22 @@ RUN set -x && \
##telegraf##mkdir -p /etc/telegraf/telegraf.d && \
# document telegraf version
##telegraf##bash -ec "telegraf --version >> /VERSIONS" && \
# Clean-up.
apt-get remove -y ${TEMP_PACKAGES[@]} && \
apt-get autoremove -y && \
apt-get clean -q -y && \
rm -rf /src/* /tmp/* /var/lib/apt/lists/* /var/cache/* && \
# document versions
bash -ec 'grep -v tar1090-db /VERSIONS | grep tar1090 | cut -d " " -f 2 > /CONTAINER_VERSION' && \
cat /VERSIONS && \
# Add Container Version
branch="##BRANCH##" && \
[[ "${branch:0:1}" == "#" ]] && branch="main" || true && \
git clone --depth=1 -b $branch https://github.com/sdr-enthusiasts/docker-tar1090.git /tmp/clone && \
pushd /tmp/clone && \
bash -ec 'echo "$(TZ=UTC date +%Y%m%d-%H%M%S)_$(git rev-parse --short HEAD)_$(git branch --show-current)" > /.CONTAINER_VERSION' && \
popd && \
rm -rf /tmp/*
# Clean-up.
apt-get remove -y ${TEMP_PACKAGES[@]} && \
apt-get autoremove -q -o APT::Autoremove::RecommendsImportant=0 -o APT::Autoremove::SuggestsImportant=0 -y && \
apt-get clean -q -y && \
rm -rf /src/* /tmp/* /var/lib/apt/lists/* /var/cache/* && \
# document versions
cat /VERSIONS

COPY rootfs/ /

EXPOSE 80/tcp

Expand Down
11 changes: 4 additions & 7 deletions rootfs/etc/s6-overlay/startup.d/02-tar1090-update
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ OVERRIDE_GIT_SOURCE="/var/tar1090_git_source"

if [[ -d "${OVERRIDE_GIT_SOURCE}/html" ]]; then
echo "USING LOCALLY MODIFIED TAR1090 from ${OVERRIDE_GIT_SOURCE}"
TAR1090_VERSION="LOCALLY MODIFIED"
TAR1090_VERSION="$(cat "${OVERRIDE_GIT_SOURCE}/version") LOCALLY MODIFIED"
bash /tar1090-install.sh /run/readsb webroot "${TAR1090_INSTALL_DIR}" "${OVERRIDE_GIT_SOURCE}"
else
TAR1090_VERSION=$(cat "${TAR1090_UPDATE_DIR}/git/version")
bash /tar1090-install.sh /run/readsb webroot "${TAR1090_INSTALL_DIR}"
fi

Expand All @@ -30,10 +31,6 @@ if [[ "$TAR1090_ENABLE_AC_DB" == "true" ]]; then
fi

# Print tar1090 version
pushd "${TAR1090_UPDATE_DIR}/git" >/dev/null || exit 1
if [[ -z "$TAR1090_VERSION" ]]; then
TAR1090_VERSION=$(git rev-parse --short HEAD)
fi
echo "tar1090 version: ${TAR1090_VERSION}"
TAR1090_DB_VERSION=$(cat "${TAR1090_UPDATE_DIR}/git-db/version")
echo "tar1090 version: ${TAR1090_VERSION} tar1090-db version: ${TAR1090_DB_VERSION}"
export TAR1090_VERSION
popd >/dev/null || exit 1
15 changes: 14 additions & 1 deletion rootfs/etc/s6-overlay/startup.d/11-timelapse1090
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ if [[ -d "${GITPATH_TIMELAPSE1090}" ]]; then
exit 0
fi

set -e

function getGIT() {
# getGIT $REPO $BRANCH $TARGET (directory)
if [[ -z "$1" ]] || [[ -z "$2" ]] || [[ -z "$3" ]]; then echo "getGIT wrong usage, check your script or tell the author!" 1>&2; return 1; fi
REPO="$1"; BRANCH="$2"; TARGET="$3"; pushd /tmp >/dev/null
rm -rf "$TARGET"; tmp=$(mktemp)
if wget --no-verbose -O "$tmp" "$REPO/archive/refs/heads/$BRANCH.tar.gz" && mkdir -p "$tmp.folder" && tar xf "$tmp" -C "$tmp.folder" >/dev/null; then
if mv -fT "$tmp.folder/$(ls "$tmp.folder")" "$TARGET"; then rm -rf "$tmp" "$tmp.folder"; popd > /dev/null; return 0; fi
fi
rm -rf "$tmp" "$tmp.folder"; popd > /dev/null; return 1;
}

# timelapse1090
git clone --single-branch --depth 1 "https://github.com/wiedehopf/timelapse1090.git" "${GITPATH_TIMELAPSE1090}"
getGIT https://github.com/wiedehopf/timelapse1090 master "${GITPATH_TIMELAPSE1090}"
mkdir -p /var/timelapse1090
64 changes: 8 additions & 56 deletions rootfs/tar1090-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,47 +30,6 @@ if [[ -z "$gpath" ]]; then gpath="$ipath"; fi
mkdir -p "$ipath"
mkdir -p "$gpath"

if useSystemd && ! id -u tar1090 &>/dev/null
then
adduser --system --home "$ipath" --no-create-home --quiet tar1090 || adduser --system --home-dir "$ipath" --no-create-home tar1090
fi

# terminate with /
command_package="git git/jq jq/"
packages=()

while read -r -d '/' CMD PKG
do
if ! command -v "$CMD" &>/dev/null
then
#echo "command $CMD not found, will try to install package $PKG"
packages+=("$PKG")
fi
done < <(echo "$command_package")

if [[ -n "${packages[*]}" ]]; then
if ! command -v "apt-get" &>/dev/null; then
echo "Please install the following packages and rerun the install:"
echo "${packages[*]}"
exit 1
fi
echo "Installing required packages: ${packages[*]}"
if ! apt-get install -y --no-install-suggests --no-install-recommends "${packages[@]}"; then
apt-get update || true
apt-get install -y --no-install-suggests --no-install-recommends "${packages[@]}" || true
fi
hash -r || true
while read -r -d '/' CMD PKG
do
if ! command -v "$CMD" &>/dev/null
then
echo "command $CMD not found, seems we failed to install package $PKG"
echo "FATAL: Exiting!"
exit 1
fi
done < <(echo "$command_package")
fi

if [ -d /etc/lighttpd/conf.d/ ] && ! [ -d /etc/lighttpd/conf-enabled/ ] && ! [ -d /etc/lighttpd/conf-available ] && command -v lighttpd &>/dev/null
then
ln -s /etc/lighttpd/conf.d /etc/lighttpd/conf-enabled
Expand Down Expand Up @@ -102,25 +61,17 @@ function copyNoClobber() {
function getGIT() {
# getGIT $REPO $BRANCH $TARGET (directory)
if [[ -z "$1" ]] || [[ -z "$2" ]] || [[ -z "$3" ]]; then echo "getGIT wrong usage, check your script or tell the author!" 1>&2; return 1; fi
REPO="$1"; BRANCH="$2"; TARGET="$3"; pushd . >/dev/null
if cd "$TARGET" &>/dev/null && git fetch --depth 1 origin "$BRANCH" 2>/dev/null && git reset --hard FETCH_HEAD; then popd >/dev/null && return 0; fi
if ! cd /tmp || ! rm -rf "$TARGET"; then popd > /dev/null; return 1; fi
if git clone --depth 1 --single-branch --branch "$BRANCH" "$REPO" "$TARGET"; then popd > /dev/null; return 0; fi
rm -rf "$TARGET"; tmp=/tmp/getGIT-tmp-tar1090
if wget -O "$tmp" "$REPO/archive/refs/heads/$BRANCH.zip" && unzip "$tmp" -d "$tmp.folder" >/dev/null; then
REPO="$1"; BRANCH="$2"; TARGET="$3"; pushd /tmp >/dev/null
rm -rf "$TARGET"; tmp=$(mktemp)
if wget --no-verbose -O "$tmp" "$REPO/archive/refs/heads/$BRANCH.tar.gz" && mkdir -p "$tmp.folder" && tar xf "$tmp" -C "$tmp.folder" >/dev/null; then
if mv -fT "$tmp.folder/$(ls "$tmp.folder")" "$TARGET"; then rm -rf "$tmp" "$tmp.folder"; popd > /dev/null; return 0; fi
fi
rm -rf "$tmp" "$tmp.folder"; popd > /dev/null; return 1;
}
function revision() {
git rev-parse --short HEAD 2>/dev/null || echo "$RANDOM-$RANDOM"
}

if ! { [[ "$1" == "test" ]] && cd "$gpath/git-db"; }; then
DB_VERSION_NEW=$(curl --silent --show-error "https://raw.githubusercontent.com/wiedehopf/tar1090-db/master/version")
if [[ "$(cat "$gpath/git-db/version" 2>/dev/null)" != "$DB_VERSION_NEW" ]]; then
getGIT "$db_repo" "master" "$gpath/git-db" || true
fi
DB_VERSION_NEW=$(curl --silent --show-error "https://raw.githubusercontent.com/wiedehopf/tar1090-db/master/version")
if [[ "$(cat "$gpath/git-db/version" 2>/dev/null)" != "$DB_VERSION_NEW" ]]; then
getGIT "$db_repo" "master" "$gpath/git-db" || true
fi

if ! cd "$gpath/git-db"
Expand All @@ -129,7 +80,7 @@ then
exit 1
fi

DB_VERSION=$(revision)
DB_VERSION=$(cat "$gpath/git-db/version")

cd "$dir"

Expand Down Expand Up @@ -296,6 +247,7 @@ do
cp -r -T "$gpath/git-db/db" "$TMP/db-$DB_VERSION"
sed -i -e "s/let databaseFolder = .*;/let databaseFolder = \"db-$DB_VERSION\";/" "$TMP/index.html"
echo "{ \"tar1090Version\": \"$TAR_VERSION\", \"databaseVersion\": \"$DB_VERSION\" }" > "$TMP/version.json"
echo "$TAR_VERSION" > "$TMP/version"

# keep some stuff around
mv "$html_path/config.js" "$TMP/config.js" 2>/dev/null || true
Expand Down

0 comments on commit 8366921

Please sign in to comment.