Skip to content

Commit

Permalink
Add aiscatcher link to notifications, slow down masto_expire runs t…
Browse files Browse the repository at this point in the history
…o 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
  • Loading branch information
kx1t authored Jun 12, 2024
1 parent aaa3b1d commit 110de45
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 48 deletions.
47 changes: 23 additions & 24 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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) && \
#
Expand All @@ -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 && \
Expand All @@ -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
55 changes: 40 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.

Expand Down Expand Up @@ -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 |
Expand Down Expand Up @@ -111,27 +136,27 @@ 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.

## Acknowledgements

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

Expand Down
13 changes: 8 additions & 5 deletions rootfs/etc/s6-overlay/scripts/cleanup
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,25 @@ 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
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..."

Expand Down Expand Up @@ -107,11 +110,11 @@ rm -f "$VESSELDBLOCK"

# clean up Mastodon toots:

if [[ -n "$MASTODON_ACCESS_TOKEN" ]]; then
if [[ -n "$MASTODON_ACCESS_TOKEN" ]] && (( $(date +%s) - $(</run/.last_mastodon_cleanup) > 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 @"$(( $(</run/.last_mastodon_cleanup) + MASTODON_CLEANUP_EVERY ))")" || echo ""

sleep "${CLEANUP_EVERY}"
2 changes: 1 addition & 1 deletion rootfs/opt/data/discord.template
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
},
{
"name": "External Links",
"value": "##SM--[Station Map](##STNMAP##) | --SM##[ShipXplorer](https://www.shipxplorer.com/data/vessels/IMO-MMSI-##MMSI##) | [MarineTraffic](https://www.marinetraffic.com/en/ais/details/ships/##MMSI##) | [VesselFinder](https://www.vesselfinder.com/vessels/details/##MMSI##) | [ShipSpotting photo gallery](https://www.shipspotting.com/photos/gallery?mmsi=##MMSI##)",
"value": "##SM--[Station Map](##STNMAP##) | --SM##[AIS-Catcher](https://aiscatcher.org/ship/details/##MMSI##) | [ShipXplorer](https://www.shipxplorer.com/data/vessels/IMO-MMSI-##MMSI##) | [MarineTraffic](https://www.marinetraffic.com/en/ais/details/ships/##MMSI##) | [VesselFinder](https://www.vesselfinder.com/vessels/details/##MMSI##) | [ShipSpotting photo gallery](https://www.shipspotting.com/photos/gallery?mmsi=##MMSI##)",
"inline": false
}
],
Expand Down
7 changes: 4 additions & 3 deletions rootfs/usr/share/vesselalert/send_mastodon
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ fi
# Build the message - create notification string

links=""
[[ -n "$MASTODON_LINK_SHIPXPLORER" ]] && links+="https://www.shipxplorer.com/data/vessels/IMO-MMSI-${VESSELS[$1:mmsi]}\n" || true
[[ -n "$MASTODON_LINK_MARINETRAFFIC" ]] && links+="https://www.marinetraffic.com/en/ais/details/ships/${VESSELS[$1:mmsi]}\n" || true
[[ -n "$MASTODON_LINK_VESSELFINDER" ]] && links+="https://www.vesselfinder.com/vessels/details/${VESSELS[$1:mmsi]}\n" || true
chk_enabled "${MASTODON_LINK_AISCATCHER:-on}" && links+="https://aiscatcher.org/ship/details/${VESSELS[$1:mmsi]}\n" || true
chk_enabled "$MASTODON_LINK_SHIPXPLORER" && links+="https://www.shipxplorer.com/data/vessels/IMO-MMSI-${VESSELS[$1:mmsi]}\n" || true
chk_enabled "$MASTODON_LINK_MARINETRAFFIC" && links+="https://www.marinetraffic.com/en/ais/details/ships/${VESSELS[$1:mmsi]}\n" || true
chk_enabled "$MASTODON_LINK_VESSELFINDER" && links+="https://www.vesselfinder.com/vessels/details/${VESSELS[$1:mmsi]}\n" || true

unset mast_str

Expand Down

0 comments on commit 110de45

Please sign in to comment.