Skip to content

Commit

Permalink
make container work without git as kept package
Browse files Browse the repository at this point in the history
this reduces image size by 80 MB
  • Loading branch information
wiedehopf committed Jun 11, 2024
1 parent 67599a6 commit 4b65d20
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 83 deletions.
30 changes: 11 additions & 19 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,20 @@ RUN \
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,13 +67,9 @@ RUN \
# 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
Expand Down Expand Up @@ -155,22 +149,20 @@ RUN \
##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/ /

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 4b65d20

Please sign in to comment.