From 110de45ad1ab89cf2c215a729f7f58e6ad131121 Mon Sep 17 00:00:00 2001 From: kx1t <15090643+kx1t@users.noreply.github.com> Date: Wed, 12 Jun 2024 11:31:56 -0400 Subject: [PATCH] Add aiscatcher link to notifications, slow down `masto_expire` runs to once every 12 hours, Dockerfile optimizations (#9) * add `MASTODON_LINK_AISCATCHER` support * Updated `MASTODON_LINK_AISCATCHER`with the link that @jvde-github advised to use * run `masto_expire` less often * bug fix * bug fix * logging improvement * add AIS-Catcher link to Discord template * optimize Dockerfile for size * optimize Dockerfile * bug fix * fix --- Dockerfile | 47 +++++++++--------- README.md | 55 ++++++++++++++++------ rootfs/etc/s6-overlay/scripts/cleanup | 13 +++-- rootfs/opt/data/discord.template | 2 +- rootfs/usr/share/vesselalert/send_mastodon | 7 +-- 5 files changed, 76 insertions(+), 48 deletions(-) diff --git a/Dockerfile b/Dockerfile index a0d235d..18f4d8f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,22 @@ FROM ghcr.io/sdr-enthusiasts/docker-baseimage:base AS build -RUN set -x && \ +SHELL ["/bin/bash", "-x", "-o", "pipefail", "-c"] +RUN \ + --mount=type=bind,source=./,target=/ghrepo/ \ apt-get update -y && \ apt-get install -q -o Dpkg::Options::="--force-confnew" -y \ git gcc && \ + mkdir -p /src && \ + cd /src && \ + cp -f /ghrepo/src/distance.c . && \ + gcc -static distance.c -o distance -lm -Ofast && \ + # Add Container Version: cd / && \ - git clone --depth=1 --single-branch https://github.com/sdr-enthusiasts/docker-vesselalert.git && \ - cd /docker-vesselalert/src && \ - gcc -static distance.c -o distance -lm -Ofast + branch="##BRANCH##" && \ + [[ "${branch:0:1}" == "#" ]] && branch="main" || true && \ + git clone --depth=1 -b $branch https://github.com/sdr-enthusiasts/docker-vesselalert.git && \ + cd docker-vesselalert && \ + echo "$(TZ=UTC date +%Y%m%d-%H%M%S)_$(git rev-parse --short HEAD)_$(git branch --show-current)" > /.CONTAINER_VERSION FROM ghcr.io/sdr-enthusiasts/docker-baseimage:base @@ -16,16 +25,15 @@ ENV MASTODON_MIN_DIST=0 ENV PATH="$PATH:/usr/share/vesselalert:/tools" LABEL org.opencontainers.image.source = "https://github.com/sdr-enthusiasts/docker-vesselalert" -SHELL ["/bin/bash", "-o", "pipefail", "-c"] - -RUN set -x && \ -# +SHELL ["/bin/bash", "-x", "-o", "pipefail", "-c"] +# hadolint ignore=DL3008,SC2086,SC2039,SC2068 +RUN \ + --mount=type=bind,from=build,source=/,target=/build \ # define required packages TEMP_PACKAGES=() && \ KEPT_PACKAGES=() && \ KEPT_PACKAGES+=(bc) && \ KEPT_PACKAGES+=(jq) && \ - KEPT_PACKAGES+=(git) && \ KEPT_PACKAGES+=(nano) && \ KEPT_PACKAGES+=(curl) && \ # @@ -35,6 +43,10 @@ RUN set -x && \ "${KEPT_PACKAGES[@]}" \ "${TEMP_PACKAGES[@]}" \ && \ + # add files from the build container: + mkdir -p /usr/share/vesselalert && \ + cp -f /build/src/distance /usr/share/vesselalert/distance && \ + cp -f /build/.CONTAINER_VERSION /.CONTAINER_VERSION && \ # Do some other stuff echo "alias dir=\"ls -alsv\"" >> /root/.bashrc && \ echo "alias nano=\"nano -l\"" >> /root/.bashrc && \ @@ -43,26 +55,13 @@ RUN set -x && \ if [[ "${#TEMP_PACKAGES[@]}" -gt 0 ]]; then \ apt-get remove -y "${TEMP_PACKAGES[@]}"; \ fi && \ - apt-get autoremove -y && \ + apt-get autoremove -q -o APT::Autoremove::RecommendsImportant=0 -o APT::Autoremove::SuggestsImportant=0 -y && \ + apt-get clean -q -y && \ # # set CONTAINER_VERSION: rm -rf /src/* /tmp/* /var/lib/apt/lists/* COPY rootfs/ / -COPY --from=build /docker-vesselalert/src/distance /usr/share/vesselalert/distance - -# Add Container Version -RUN set -x && \ -pushd /tmp && \ - branch="##BRANCH##" && \ - [[ "${branch:0:1}" == "#" ]] && branch="main" || true && \ - git clone --depth=1 -b $branch https://github.com/sdr-enthusiasts/docker-vesselalert.git && \ - cd docker-vesselalert && \ - 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/* - - # Add healthcheck # HEALTHCHECK --start-period=60s --interval=600s --timeout=60s CMD /healthcheck/healthcheck.sh diff --git a/README.md b/README.md index ab9a5b7..1a7fa14 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,30 @@ [![Discord](https://img.shields.io/discord/734090820684349521)](https://discord.gg/sTf9uYF) +## Table of Contents + +- [sdr-enthusiasts/docker-vesselalert](#sdr-enthusiastsdocker-vesselalert) + - [Table of Contents](#table-of-contents) + - [Introduction](#introduction) + - [Prerequisites](#prerequisites) + - [Multi Architecture Support](#multi-architecture-support) + - [Configuring Mastodon: create an application and get an `access token`](#configuring-mastodon-create-an-application-and-get-an-access-token) + - [Up-and-Running with Docker Compose](#up-and-running-with-docker-compose) + - [Runtime Environment Variables](#runtime-environment-variables) + - [General parameters](#general-parameters) + - [Tropo Alert parameters](#tropo-alert-parameters) + - [Mastodon notifications related parameters](#mastodon-notifications-related-parameters) + - [Discord notifications related parameters](#discord-notifications-related-parameters) + - [Expert Parameters (only change/set if you know what you're doing)](#expert-parameters-only-changeset-if-you-know-what-youre-doing) + - [Adding screenshots to your notifications](#adding-screenshots-to-your-notifications) + - [Logging](#logging) + - [Modifications of Ship Status and Ship Type descriptions](#modifications-of-ship-status-and-ship-type-descriptions) + - [Acknowledgements](#acknowledgements) + - [Getting Help](#getting-help) + - [Summary of License Terms](#summary-of-license-terms) + - [VesselAlert](#vesselalert) + - [Tropo Alert Feature](#tropo-alert-feature) + ## Introduction Docker container providing social media notification for Vessels that are received with @jvde-github's excellent [AIS-Catcher](https://github.com/jvde-github/AIS-catcher) package. @@ -13,17 +37,17 @@ Currently, posts to [Mastodon](https://airwaves.social) and Discord are supporte We expect you to have the following: -* An installed and working version of the [AIS-Catcher](https://github.com/jvde-github/AIS-catcher) package with the Web Functionality installed and accessible to this container. This means that you need to be using [v0.42](https://github.com/jvde-github/AIS-catcher/releases/tag/v0.42) or later, and that you must configure the Web Server as per the [documentation](https://github.com/jvde-github/AIS-catcher/blob/main/README.md). We advise to put the Web Server on a fixed and known port number as you will have to configure a link to this for VesselAlert to work. Note -- the version of AIS-Catcher in the official ShipXplorer distribution is too old. You must install a newer version (or switch to the [containerized version](https://github.com/sdr-enthusiasts/docker-shipxplorer), which includes an up-to-date version of AIS-Catcher). -* Docker must be installed on your system. If you don't know how to do that, please read [here](https://github.com/sdr-enthusiasts/docker-install). -* Some basic knowledge on how to use Linux and how to configure docker containers with `docker-compose`. +- An installed and working version of the [AIS-Catcher](https://github.com/jvde-github/AIS-catcher) package with the Web Functionality installed and accessible to this container. This means that you need to be using [v0.42](https://github.com/jvde-github/AIS-catcher/releases/tag/v0.42) or later, and that you must configure the Web Server as per the [documentation](https://github.com/jvde-github/AIS-catcher/blob/main/README.md). We advise to put the Web Server on a fixed and known port number as you will have to configure a link to this for VesselAlert to work. Note -- the version of AIS-Catcher in the official ShipXplorer distribution is too old. You must install a newer version (or switch to the [containerized version](https://github.com/sdr-enthusiasts/docker-shipxplorer), which includes an up-to-date version of AIS-Catcher). +- Docker must be installed on your system. If you don't know how to do that, please read [here](https://github.com/sdr-enthusiasts/docker-install). +- Some basic knowledge on how to use Linux and how to configure docker containers with `docker-compose`. ## Multi Architecture Support Currently, this image should pull and run on the following architectures: -* `arm32v7`, `armv7l`, `armhf`: ARMv7 32-bit (Odroid HC1/HC2/XU4, RPi 2/3/4 32-bit) -* `arm64`, `aarch64`: ARMv8 64-bit (RPi 4 64-bit OSes) -* `amd64`, `x86_64`: X86 64-bit Linux (Linux PC) +- `arm32v7`, `armv7l`, `armhf`: ARMv7 32-bit (Odroid HC1/HC2/XU4, RPi 2/3/4 32-bit) +- `arm64`, `aarch64`: ARMv8 64-bit (RPi 4 64-bit OSes) +- `amd64`, `x86_64`: X86 64-bit Linux (Linux PC) Other architectures (Windows, Mac, armel) are not currently supported, but feel free to see if the container builds and runs for these. @@ -74,6 +98,7 @@ For predictions on Tropo conditions for your area, please visit the [DX Info Cen | `MASTODON_NOTIFY_EVERY` | Minimum amount of time (in seconds) between two notifications for the same vessel. | `86400` (1 day) | no | | `MASTODON_POST_VISIBILITY` | `visibility` setting for the Mastodon notification. Valid values are `public`, `unlisted`, and `private`. | `unlisted` | no | | `MASTODON_CUSTOM_FIELD` | Custom field attached to the end of the Mastodon notification. Please keep it short and clear-text only. | empty | no | +| `MASTODON_LINK_AISCATCHER` | If set to `on`, the Mastodon notification will include a link to the vessel on aiscatcher.org. (Set to `off`/`false`/`no`/`0` to disable) | on | no | | `MASTODON_LINK_SHIPXPLORER` | If set to `on`, the Mastodon notification will include a link to the vessel on ShipXplorer | empty | no | | `MASTODON_LINK_MARINETRAFFIC` | If set to `on`, the Mastodon notification will include a link to the vessel on MarineTraffic | empty | no | | `MASTODON_LINK_VESSELFINDER` | If set to `on`, the Mastodon notification will include a link to the vessel on VesselFinder | empty | no | @@ -111,14 +136,14 @@ Please note that you must use the screenshot container's `aiscatcher` tag and br ## Logging -* All processes are logged to the container's stdout, and can be viewed with `docker logs [-f] container`. +- All processes are logged to the container's stdout, and can be viewed with `docker logs [-f] container`. ## Modifications of Ship Status and Ship Type descriptions In your `opt/ais/data` directory (if you followed the volume mappings as recommended), there are two files: -* `shipstatus.db` contains the descriptions of the Ship Status for each status ID number -* `shiptype.db` contains the descriptions of the Ship Type for each type number +- `shipstatus.db` contains the descriptions of the Ship Status for each status ID number +- `shiptype.db` contains the descriptions of the Ship Type for each type number You can change those with a text editor. Lines that start with "#" are ignored, and you can hashtag words in the description. @@ -126,12 +151,12 @@ You can change those with a text editor. Lines that start with "#" are ignored, Without the help, advice, testing, and kicking the tires of these people, things wouldn't have happened: -* [@jvde-github](https://github.com/jvde-github) for his advice and help. He's also the author of [AIS-Catcher](https://github.com/jvde-github/AIS-catcher), which is a prerequisite for this container to work -* [@kevinelliott](https://github.com/kevinelliott) for his help during the design phase of the project, and to bounce ideas of -* [@dziban303](https://github.com/dziban303) for his help testing the early releases and providing feedback -* [@JohnEx](https://github.com/Johnex) for his ideas, research, testing, and feedback -* [@Tedder](https://github.com/tedder) who created the [original screenshot container](https://github.com/tedder/browser-screenshot-service) when we needed it for Planefence -* The engineers at AirNav who helped me understand things through their ShipXplorer project, and who provided the initial trigger for me to create this container +- [@jvde-github](https://github.com/jvde-github) for his advice and help. He's also the author of [AIS-Catcher](https://github.com/jvde-github/AIS-catcher), which is a prerequisite for this container to work +- [@kevinelliott](https://github.com/kevinelliott) for his help during the design phase of the project, and to bounce ideas of +- [@dziban303](https://github.com/dziban303) for his help testing the early releases and providing feedback +- [@JohnEx](https://github.com/Johnex) for his ideas, research, testing, and feedback +- [@Tedder](https://github.com/tedder) who created the [original screenshot container](https://github.com/tedder/browser-screenshot-service) when we needed it for Planefence +- The engineers at AirNav who helped me understand things through their ShipXplorer project, and who provided the initial trigger for me to create this container ## Getting Help diff --git a/rootfs/etc/s6-overlay/scripts/cleanup b/rootfs/etc/s6-overlay/scripts/cleanup index b7e61ac..edbdff5 100755 --- a/rootfs/etc/s6-overlay/scripts/cleanup +++ b/rootfs/etc/s6-overlay/scripts/cleanup @@ -24,9 +24,9 @@ s6wrap=(s6wrap --quiet --timestamps --prepend="$(basename "$0")" --args) renice -n 20 -p $$ >/dev/null 2>/dev/null -CLEANUP_EVERY=1800 # every 30 minutes +CLEANUP_EVERY=1800 # 30 minutes in seconds PHOTOS_RETENTION=20160 # 2 weeks in minutes -SCREENSHOT_RETENTION=60 # 1 hour +SCREENSHOT_RETENTION=60 # 1 hour in minutes #LOCKFILE_RETENTION=15 # 15 minutes MMSI_RETENTION=1209600 # 2 weeks in seconds COUNTRY_BKUP_RETENTION=20160 # 2 weeks in minutes @@ -34,12 +34,15 @@ DISCTMPL_BKUP_RETENTION=20160 # 2 weeks in minutes SHIPSTATUS_BKUP_RETENTION=20160 # 2 weeks in minutes SHIPTYPE_BKUP_RETENTION=20160 # 2 weeks in minutes VESSELDB_BKUP_RETENTION=20160 # 2 weeks in minutes +MASTODON_CLEANUP_EVERY=43200 # 12 hours in seconds VESSELDBFILE="${VESSELDBFILE:-/data/vessel.db}" VESSELDBLOCK="${VESSELDBLOCK:-/run/vesseldb.lock}" DBLOCK_MAXWAIT=600 # don't wait more than 600 secs for the dblock to be removed +[[ ! -f /run/.last_mastodon_cleanup ]] && date +%s > /run/.last_mastodon_cleanup || true + "${s6wrap[@]}" echo "[INFO] Starting Cleanup" [[ -f $VESSELDBLOCK ]] && "${s6wrap[@]}" echo "[INFO] Waiting for vessel.db to become unlocked..." @@ -107,11 +110,11 @@ rm -f "$VESSELDBLOCK" # clean up Mastodon toots: -if [[ -n "$MASTODON_ACCESS_TOKEN" ]]; then +if [[ -n "$MASTODON_ACCESS_TOKEN" ]] && (( $(date +%s) - $( MASTODON_CLEANUP_EVERY )); then /usr/share/vesselalert/masto_expire delete || true fi - -"${s6wrap[@]}" echo "[INFO] Cleanup finished. Next cleanup run at $(date -d @$(( $(date +%s) + CLEANUP_EVERY )) ). " +"${s6wrap[@]}" echo -n "[INFO] Cleanup finished. Next cleanup run at $(date -d @$(( $(date +%s) + CLEANUP_EVERY )) )" +[[ -n "$MASTODON_ACCESS_TOKEN" ]] && echo ". Next Mastodon cleanup run at $(date -d @"$(( $(