From 34841af92822ec412bbd890bf3e8a4184515e461 Mon Sep 17 00:00:00 2001 From: Fred Clausen <43556888+fredclausen@users.noreply.github.com> Date: Thu, 12 Oct 2023 10:34:26 -0600 Subject: [PATCH] linting / precommit --- .dictionary.txt | 1 + .github/workflows/cancel_dupes.yml | 8 +-- .github/workflows/pre-commit-updates.yaml | 23 ++++++ .pre-commit-config.yaml | 65 +++++++++++++++++ .vscode/scp.json | 16 ++--- Dockerfile | 1 + README.md | 86 ++++++++++++++--------- docker-compose.yml | 4 +- rootfs/etc/s6-overlay/scripts/mlat-client | 2 +- rootfs/home/healthcheck/healthcheck.sh | 4 ++ 10 files changed, 163 insertions(+), 47 deletions(-) create mode 100644 .dictionary.txt create mode 100644 .github/workflows/pre-commit-updates.yaml create mode 100644 .pre-commit-config.yaml diff --git a/.dictionary.txt b/.dictionary.txt new file mode 100644 index 0000000..9ac17d5 --- /dev/null +++ b/.dictionary.txt @@ -0,0 +1 @@ +crate diff --git a/.github/workflows/cancel_dupes.yml b/.github/workflows/cancel_dupes.yml index df5522b..c039ca9 100644 --- a/.github/workflows/cancel_dupes.yml +++ b/.github/workflows/cancel_dupes.yml @@ -2,10 +2,10 @@ name: Cancelling Duplicates on: workflow_run: workflows: - - 'Deploy to GHCR' - - 'Check Linting' - - 'Tests' - types: ['requested'] + - "Deploy to GHCR" + - "Check Linting" + - "Tests" + types: ["requested"] jobs: cancel-duplicate-workflow-runs: diff --git a/.github/workflows/pre-commit-updates.yaml b/.github/workflows/pre-commit-updates.yaml new file mode 100644 index 0000000..f075972 --- /dev/null +++ b/.github/workflows/pre-commit-updates.yaml @@ -0,0 +1,23 @@ +name: Update pre-commit hooks + +on: + workflow_dispatch: + schedule: + - cron: 0 0 * * * + +jobs: + update: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4.1.0 + with: + fetch-depth: 0 + - uses: vrslev/pre-commit-autoupdate@v1.0.0 + - uses: peter-evans/create-pull-request@v5 + with: + branch: pre-commit-autoupdate + title: "chore(deps): Update pre-commit hooks" + commit-message: "chore(deps): Update pre-commit hooks" + body: Update pre-commit hooks + labels: dependencies + delete-branch: True diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..34ef282 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,65 @@ +repos: + # lint yaml, line and whitespace + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.4.0 + hooks: + - id: check-yaml + - id: end-of-file-fixer + - id: trailing-whitespace + - id: requirements-txt-fixer + - id: mixed-line-ending + - id: check-executables-have-shebangs + - id: check-shebang-scripts-are-executable + + # lint the dockerfiles + - repo: https://github.com/hadolint/hadolint + rev: v2.12.1-beta + hooks: + - id: hadolint + + # prettier + - repo: https://github.com/pre-commit/mirrors-prettier + rev: "v3.0.3" # Use the sha / tag you want to point at + hooks: + - id: prettier + types_or: [file, bash, sh, javascript, jsx, ts, tsx] + additional_dependencies: + - prettier@2.5.1 + exclude: ^(Dockerfile*) + + - repo: https://github.com/codespell-project/codespell.git + rev: "v2.2.5" # Use the sha / tag you want to point at + hooks: + - id: codespell + types: [text] + args: [--ignore-words=.dictionary.txt] + exclude: ^(Dockerfile*) + + - repo: https://github.com/shellcheck-py/shellcheck-py + rev: v0.9.0.6 + hooks: + - id: shellcheck + + - repo: https://github.com/sirosen/check-jsonschema + rev: 0.27.0 + hooks: + - id: check-github-actions + - id: check-github-workflows + + - repo: https://github.com/doublify/pre-commit-rust + rev: v1.0 + hooks: + - id: fmt + - id: cargo-check + + # lint python formatting + - repo: https://github.com/psf/black + rev: 23.9.1 + hooks: + - id: black + + - repo: https://github.com/pycqa/flake8 + rev: "6.1.0" # pick a git hash / tag to point to + hooks: + - id: flake8 + args: ["--extend-ignore=W503,W504,E501"] diff --git a/.vscode/scp.json b/.vscode/scp.json index e42d0f4..3ea5e8e 100644 --- a/.vscode/scp.json +++ b/.vscode/scp.json @@ -1,9 +1,9 @@ { - "host": "pete", - "port": 22, - "user": "docker", - "ignore":[".git",".vscode"], - "remotePath": "~", - "identity_file": "~/.ssh/id_rsa", - "uploadOnSave": true -} \ No newline at end of file + "host": "pete", + "port": 22, + "user": "docker", + "ignore": [".git", ".vscode"], + "remotePath": "~", + "identity_file": "~/.ssh/id_rsa", + "uploadOnSave": true +} diff --git a/Dockerfile b/Dockerfile index 1f7bd34..e78c760 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,6 +4,7 @@ ENV URL_MLAT_CLIENT_REPO="https://github.com/wiedehopf/mlat-client.git" \ PRIVATE_MLAT="false" \ MLAT_INPUT_TYPE="dump1090" +# hadolint ignore=DL3008,SC2086,SC2039,SC2068,DL3003,DL3015,SC3054 RUN set -x && \ # define packages needed for installation and general management of the container: TEMP_PACKAGES=() && \ diff --git a/README.md b/README.md index 579bace..b8fc0b2 100644 --- a/README.md +++ b/README.md @@ -5,16 +5,18 @@ This application is a feeder service that takes RAW/AVR ADSB data from a service like `dump1090[-fa]`, `readsb`, and `tar1090`, and feeds this data to `adsbnetwork`'s RadarVirtuel data aggregator. It works similar to other data connectors from the @Mikenye family of ADSB tools. RadarVirtuel can be reached at: + - http://www.radarvirtuel.com/ Before you install this container, you need a **feeder key**. To request one, email support@adsbnetwork.com with the following information: + - Your name - The Lat/Lon and nearest airport of your station - Your Raspberry Pi model (or other hardware if not Raspberry Pi) - Mention that you will feed using a Docker container. - ## Quick Start Guide + These instructions are for people who are deploying on Raspberry Pi (3B+ or 4) with Raspberry OS or Ubuntu, and who already have a running `Docker` and `Docker-compose` setup with `readsb`, `dump1090-fa`, or a similar ADSB decoder running. That decoder can run inside a container or directly on the host. You should also have received a Feeder Key as per the section above. @@ -25,63 +27,75 @@ With these 4 simple steps, you should be up and running in 5 minutes or less. If 2. In `docker-compose.yml`, please check the `${HOSTNAME}` variable: - if you are using dockerized `readsb` or `tar1090` in the same docker-compose stack, then you can put in the name of the target container. Example: `SOURCE_HOST=readsb:30002` - if you are using `dump1090[-fa]`, `readsb`, or `tar1090` WITHOUT docker or in a different docker stack: - - if it's on the local machine -- use the default value of `${HOSTNAME}:30002` - - if it's on a different machine -- use the hostname or IP address of the target machine, for example `SOURCE_HOST=192.168.1.10:30002` - - (Note - NEVER put "127.0.0.1" as the IP address - this won't work!) -3. Make sure that you add the following parameters to your `.env` file, in the same directory as `docker-compose.yml`. You may already have some of these params in that file, in which case it's not necessary to duplicate them. You should have received your feeder key value from support@adsbnetwork.com. + - if it's on the local machine -- use the default value of `${HOSTNAME}:30002` + - if it's on a different machine -- use the hostname or IP address of the target machine, for example `SOURCE_HOST=192.168.1.10:30002` + - (Note - NEVER put "127.0.0.1" as the IP address - this won't work!) +3. Make sure that you add the following parameters to your `.env` file, in the same directory as `docker-compose.yml`. You may already have some of these params in that file, in which case it's not necessary to duplicate them. You should have received your feeder key value from support@adsbnetwork.com. + ``` RV_FEEDER_KEY=xxxx:123456789ABCDEF FEEDER_LAT=12.345678 FEEDER_LONG=6.7890123 FEEDER_ALT_M=12.3 ``` + 4. Restart your container stack with `docker-compose up -d` and you're in business. Monitor `docker logs -f radarvirtuel` to check for any errors. ## Detailed Instructions + ## Prerequisites + 1. The use of this connector service assumes that you already have a working ADS-B station setup + - Ensure you enabled RAW (=AVR) and BEAST data output on the application that actively processes your ADS-B data. - Your ADS-B station can be on the same machine as this application, or on a different machine. - Similarly, it doesn't matter if you are using a Containerized or non-Containerized setup. 2. The use of this connector also assumes that you have installed `Docker` and `Docker-compose` on the machine you want to run `RadarVirtuel` on. + - For a good overview on Docker, installation, etc., please read Mike Nye's excellent [gitbook](https://mikenye.gitbook.io/ads-b/). - If you need to install `Docker` and/or `Docker-compose` on your machine, [go here](https://github.com/sdr-enthusiasts/docker-install) for a handy script that will take care of it for you 3. Last, you will need to get a `FEEDER_KEY` to identify your station to RadarVirtuel. See the "What is it?" section above for instructions on how to get this key. ## Installation + For a stand-alone installation on a machine with an existing ADS-B receiver, you can simply do this: + ``` sudo mkdir -p /opt/adsb && sudo chmod a+rwx /opt/adsb && cd /opt/adsb wget https://raw.githubusercontent.com/kx1t/docker-radarvirtuel/main/docker-compose.yml ``` + Then, edit the `docker-compose.yml` file and the `.env` file in the same directory using the instructions above. To add `RadarVirtuel` to an existing Docker Stack, simply copy and paste the relevant sections into your existing `docker-compose.yml` and `.env` files. ## Environment Parameters for `docker-radarvirtuel` -| Parameter | Definition | Value | -|-------------|-------------------------------|---------------------------| -| `FEEDER_KEY` | This key is provided by RadarVirtuel and is your PRIVATE KEY. Do no share this with anyone else. | `[icao]:[private_key]` | -| `SOURCE_HOST` | host and port number of your ADSB receiver. When running stand-alone on your local machine, this should be `${HOSTNAME}`. The value after the `:` is the port number to the RAW or AVR service on the target machine, most probably `30002`. | `${HOSTNAME}:30002` | -| `RV_SERVER` | The hostname and the port of the RadarVirtuel server. You should NOT change this unless specifically instructed. | `mg2.adsbnetwork.com:50050` | -| `VERBOSE` | Write verbose messages to the log | `OFF` (default) / `ON` | -| `MLAT_SERVER` | RV MLAT server address and port - do not change unless instructed to | mlat.adsbnetwork.com:50000 | -| `MLAT_HOST` | This is the same hostname as for SOURCE_HOST, but now using port 30005 | `${HOSTNAME}:30005` | -| `MLAT_INPUT_TYPE` | Optional param to define MLAT Input Type - do not change unless instructed to | `auto` (default) / `dump1090` / `beast` / `radarcape_12mhz` / `radarcape_gps` / `radarcape` / `sbs` / `avrmlat` | -| `MLAT_RESULTS` | Optional param to define how to make the MLAT results available. Value is used with the `--results` option of `mlat-client`. For valid options, do `docker exec -t radarvirtuel mlat-client --help` | `beast,listen,30105` (default) | -| `LAT` | This is your station latitude (used with MLAT) | | -| `LON` | This is your station longitude (used with MLAT) | | -| `ALT` | This is your antenna altitude above the ellipsoid (MSL). Use "ft" for feet or "m" for meters | | +| Parameter | Definition | Value | +| ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- | +| `FEEDER_KEY` | This key is provided by RadarVirtuel and is your PRIVATE KEY. Do no share this with anyone else. | `[icao]:[private_key]` | +| `SOURCE_HOST` | host and port number of your ADSB receiver. When running stand-alone on your local machine, this should be `${HOSTNAME}`. The value after the `:` is the port number to the RAW or AVR service on the target machine, most probably `30002`. | `${HOSTNAME}:30002` | +| `RV_SERVER` | The hostname and the port of the RadarVirtuel server. You should NOT change this unless specifically instructed. | `mg2.adsbnetwork.com:50050` | +| `VERBOSE` | Write verbose messages to the log | `OFF` (default) / `ON` | +| `MLAT_SERVER` | RV MLAT server address and port - do not change unless instructed to | mlat.adsbnetwork.com:50000 | +| `MLAT_HOST` | This is the same hostname as for SOURCE_HOST, but now using port 30005 | `${HOSTNAME}:30005` | +| `MLAT_INPUT_TYPE` | Optional param to define MLAT Input Type - do not change unless instructed to | `auto` (default) / `dump1090` / `beast` / `radarcape_12mhz` / `radarcape_gps` / `radarcape` / `sbs` / `avrmlat` | +| `MLAT_RESULTS` | Optional param to define how to make the MLAT results available. Value is used with the `--results` option of `mlat-client`. For valid options, do `docker exec -t radarvirtuel mlat-client --help` | `beast,listen,30105` (default) | +| `LAT` | This is your station latitude (used with MLAT) | | +| `LON` | This is your station longitude (used with MLAT) | | +| `ALT` | This is your antenna altitude above the ellipsoid (MSL). Use "ft" for feet or "m" for meters | | ## MLAT Configuration + By default, MLAT is switched ON in the container. Please make sure to configure a valid `MLAT_HOST`, `LAT`, `LON`, and `ALT` in your `docker-compose.yml` setup. If you want to switch off MLAT, simply set `MLAT_HOST` to empty. You will see a message in the logs encouraging to configure MLAT, followed by a message saying that MLAT is disabled. ## Timezone configuration + - The default timezone setting for the container mimics the host machine's timezone. Sometimes, it is desired to run the container in UTC instead. - To run the container in UTC, comment out the following lines (using `#`) in `docker-compose.yml`: + ``` # volumes: # - "/etc/localtime:/etc/localtime:ro" @@ -91,45 +105,53 @@ By default, MLAT is switched ON in the container. Please make sure to configure ## Starting, stopping, upgrading, and monitoring the container To start the container for the first time: + - `pushd /opt/adsb && docker-compose up -d && popd` To restart the container: + - `docker restart radarvirtuel` To stop the container: -- `pushd /opt/adsb && docker-compose down && popd` <-- this stops all containers in the stack -- `docker stop radarvirtuel` <-- this stops only RadarVirtuel + +- `pushd /opt/adsb && docker-compose down && popd` <-- this stops all containers in the stack +- `docker stop radarvirtuel` <-- this stops only RadarVirtuel To download and deploy a new version of the container, if one exists: + - `pushd /opt/adsb && docker-compose pull && docker-compose up -d && popd` To monitor the logs of the RadarVirtuel container: -- `docker logs radarvirtuel` <-- shows all logs for RadarVirtuel in the buffer (warning - can be very long!) -- `docker logs -f radarvirtuel` <-- shows the last few logs and waits for any new log entries, abort with CTRL-C + +- `docker logs radarvirtuel` <-- shows all logs for RadarVirtuel in the buffer (warning - can be very long!) +- `docker logs -f radarvirtuel` <-- shows the last few logs and waits for any new log entries, abort with CTRL-C ## Troubleshooting + - If things don't appear to work as they should, set `VERBOSE=ON` in your `docker-compose.yml` and restart the container. Then monitor `docker logs -f radarvirtuel` to see what is going on - If it complains about your `SOURCE_HOST`: - - Make sure your data source can be reached from inside the container. `SOURCE_HOST` should be set to: - - if it's a container within the same stack: the container name, for example `SOURCE_HOST=readsb:30002` - - if it's a separate container or a stand-alone installation on the same machine, `SOURCE_HOST` must be set to `SOURCE_HOST=${HOSTNAME}:30002` - - If it's a separate container on a different machine, you should use the full hostname or IP address of that machine. For example `SOURCE_HOST=192.168.1.10:30002`. - - Make sure that your `readsb` or `dump1090[-fa]` installation is providing RAW (AVR) data: - - Stand-alone `dump1090` variants must use the `--net-ro-port 30002` command line parameter - - Containerized `readsb` or `readsb-protobuf` should pass the following variable in the `environment:` section of `docker-compose.yml`: `READSB_NET_RAW_OUTPUT_PORT=30002` + - Make sure your data source can be reached from inside the container. `SOURCE_HOST` should be set to: + - if it's a container within the same stack: the container name, for example `SOURCE_HOST=readsb:30002` + - if it's a separate container or a stand-alone installation on the same machine, `SOURCE_HOST` must be set to `SOURCE_HOST=${HOSTNAME}:30002` + - If it's a separate container on a different machine, you should use the full hostname or IP address of that machine. For example `SOURCE_HOST=192.168.1.10:30002`. + - Make sure that your `readsb` or `dump1090[-fa]` installation is providing RAW (AVR) data: + - Stand-alone `dump1090` variants must use the `--net-ro-port 30002` command line parameter + - Containerized `readsb` or `readsb-protobuf` should pass the following variable in the `environment:` section of `docker-compose.yml`: `READSB_NET_RAW_OUTPUT_PORT=30002` - If the logs complain about not being able to reach the RadarVirtuel server: - - Make sure your machine is connected to the internet. Try this command to check connectivity: + - Make sure your machine is connected to the internet. Try this command to check connectivity: `netcat -u -z -v mg2.adsbnetwork.com 50050` - If it complains about errors in your `docker-compose.yml` file - - SPACING IS IMPORTANT. Spacing is important. There, I said it. Check that each line has the correct indentation - - Sometimes, there are problems with newline characters when you import from a Windows machine. In that case, you can easily convert your file to Unix format. There are multiple ways to do this, one of them is: + - SPACING IS IMPORTANT. Spacing is important. There, I said it. Check that each line has the correct indentation + - Sometimes, there are problems with newline characters when you import from a Windows machine. In that case, you can easily convert your file to Unix format. There are multiple ways to do this, one of them is: `cat docker-compose.yml | tr -dc '[:print:]\n' >/tmp/tmp.tmp && sudo mv -f /tmp/tmp.tmp docker-compose.yml` ## Further help + - For help with credentials and service outages, please email support@adsbnetwork.com - For help with the Docker Container and related issues, please contact kx1t on this Discord channel: https://discord.gg/m42azbZydy # OWNERSHIP AND LICENSE + RADARVIRTUEL is owned by, and copyright by AdsbNetwork and by Laurent Duval. All rights reserved. Note that parts of the code and scripts included with this package are NOT covered by an Open Source license, and may only be distributed and used with express permission from AdsbNetwork. Contact support@adsbnetwork.com for more information. diff --git a/docker-compose.yml b/docker-compose.yml index 0ba759b..bd1c112 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,4 @@ -version: '3.8' +version: "3.8" # # If you are using the readsb container to pull your feed from, you may have add the following environment @@ -6,7 +6,7 @@ version: '3.8' # - READSB_NET_BEAST_OUTPUT_PORT=30005 # - READSB_NET_RAW_OUTPUT_PORT=30002 # -# Also, it assumes that you have added the following parameters to your `.env` file., or made available in this docker-compose.yml file: +# Also, it assumes that you have added the following parameters to your `.env` file., or made available in this docker-compose.yml file: # # RV_FEEDER_KEY=xxxx:123456789ABCDEF # FEEDER_LAT=12.345678 diff --git a/rootfs/etc/s6-overlay/scripts/mlat-client b/rootfs/etc/s6-overlay/scripts/mlat-client index 4b232d3..16ecf54 100755 --- a/rootfs/etc/s6-overlay/scripts/mlat-client +++ b/rootfs/etc/s6-overlay/scripts/mlat-client @@ -49,5 +49,5 @@ if chk_enabled "${VERBOSE}"; then s6wrap --quiet --prepend="${APPNAME}" --timestamps --args echo "Starting MLAT with: ${MLAT_CMD} ${MLAT_PARAM[@]}" exec s6wrap --quiet --prepend="${APPNAME}" --timestamps --args "${MLAT_CMD}" "${MLAT_PARAM[@]}" else - exec s6wrap --quiet --ignore=stdout --prepend="${APPNAME}" --timestamps --args "${MLAT_CMD}" "${MLAT_PARAM[@]}" + exec s6wrap --quiet --ignore=stdout --prepend="${APPNAME}" --timestamps --args "${MLAT_CMD}" "${MLAT_PARAM[@]}" fi diff --git a/rootfs/home/healthcheck/healthcheck.sh b/rootfs/home/healthcheck/healthcheck.sh index 9bb2fd7..9aa54b7 100755 --- a/rootfs/home/healthcheck/healthcheck.sh +++ b/rootfs/home/healthcheck/healthcheck.sh @@ -1,6 +1,8 @@ #!/command/with-contenv bash +#shellcheck shell=bash # Import healthchecks-framework +# shellcheck disable=SC1091 source /opt/healthchecks-framework/healthchecks.sh # HEALTHLIMIT is the number of error lines that can be in run/imalive/errors before things go UNHEALTHY @@ -9,11 +11,13 @@ HEALTHLIMIT=20 APPNAME="$(hostname)/healthcheck" touch /run/imalive/errors +#shellcheck disable=SC2002 if [[ "$(cat /run/imalive/errors | wc -l)" -ge "$HEALTHLIMIT" ]] then echo "[$APPNAME][$(date)] Abnormal death count for RadarVirtuel is $(cat /run/imalive/errors | wc -l): UNHEALTHY (>= $HEALTHLIMIT)" exit 1 else + #shellcheck disable=SC2002 [[ "$VERBOSE" == "ON" ]] && echo "[$APPNAME][$(date)] Abnormal death count for RadarVirtuel is $(cat /run/imalive/errors | wc -l): HEALTHY (< $HEALTHLIMIT)" fi exit 0