diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 42ead75..4561bd2 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -12,6 +12,11 @@ on: type: boolean description: "Use base image testpr" default: false + build_latest_as_test: + required: false + type: boolean + description: "Build latest as test" + default: false # Build and deploy the image on pushes to main branch push: @@ -23,9 +28,6 @@ on: - "Dockerfile.build_binary" - "rootfs/**" - # Build and deploy the image nightly (to ensure we pick up any security updates) - # schedule: - # - cron: "0 14 * * *" env: REGISTRY: ghcr.io IMAGE_NAME: ${{ github.repository }} @@ -47,8 +49,164 @@ jobs: run: | echo "Workflow dispatch reason: $INPUTS_REASON" echo "Use test image: $INPUTS_USE_TEST_IMAGE" + binary_build_armv7: + name: Build Binary - armv7 + runs-on: ubuntu-latest + # needs: test_rust_functionality + + steps: + - name: Checkout + uses: actions/checkout@v4.1.1 + with: + fetch-depth: 0 + repository: sdr-enthusiasts/acars-bridge + + - name: Run Docker on tmpfs + uses: JonasAlfredsson/docker-on-tmpfs@v1 + with: + tmpfs_size: 5 + swap_size: 4 + swap_location: "/mnt/swapfile" + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build armv7 + uses: docker/build-push-action@v5 + with: + context: . + push: false + file: Dockerfile.build_binary + tags: acars-bridge:armv7 + platforms: linux/arm/v7 + outputs: type=local,dest=./image_armv7/ + + - name: Upload artifact armv7 binary + uses: actions/upload-artifact@v4.0.0 + with: + name: acars-bridge.armv7 + path: ./image_armv7/acars-bridge + + binary_build_arm64: + name: Build Binary - arm64 + runs-on: ubuntu-latest + # needs: test_rust_functionality + + steps: + - name: Checkout + uses: actions/checkout@v4.1.1 + with: + fetch-depth: 0 + repository: sdr-enthusiasts/acars-bridge + + - name: Run Docker on tmpfs + uses: JonasAlfredsson/docker-on-tmpfs@v1 + with: + tmpfs_size: 5 + swap_size: 4 + swap_location: "/mnt/swapfile" + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build arm64 + uses: docker/build-push-action@v5 + with: + context: . + push: false + file: Dockerfile.build_binary + tags: acars-bridge:arm64 + platforms: linux/arm64 + outputs: type=local,dest=./image_arm64/ + + - name: Upload artifact arm64 binary + uses: actions/upload-artifact@v4.0.0 + with: + name: acars-bridge.arm64 + path: ./image_arm64/acars-bridge + + binary_build_amd64: + name: Build Binary - amd64 + runs-on: ubuntu-latest + # needs: test_rust_functionality + + steps: + - name: Checkout + uses: actions/checkout@v4.1.1 + with: + fetch-depth: 0 + repository: sdr-enthusiasts/acars-bridge + + - name: Run Docker on tmpfs + uses: JonasAlfredsson/docker-on-tmpfs@v1 + with: + tmpfs_size: 5 + swap_size: 4 + swap_location: "/mnt/swapfile" + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build amd64 + uses: docker/build-push-action@v5 + with: + context: . + push: false + file: Dockerfile.build_binary + tags: acars-bridge:amd64 + platforms: linux/amd64 + outputs: type=local,dest=./image_amd64/ + + - name: Upload artifact amd64 binary + uses: actions/upload-artifact@v4.0.0 + with: + name: acars-bridge.amd64 + path: ./image_amd64/acars-bridge + + consolidate_binaries: + name: Consolidate & Cache Binaries + runs-on: ubuntu-latest + needs: [binary_build_amd64, binary_build_arm64, binary_build_armv7] + steps: + - run: mkdir -p ./bin + + - uses: actions/download-artifact@v4.0.0 + with: + name: acars-bridge.amd64 + path: ./bin/acars-bridge.amd64 + + - uses: actions/download-artifact@v4.0.0 + with: + name: acars-bridge.armv7 + path: ./bin/acars-bridge.armv7 + + - uses: actions/download-artifact@v4.0.0 + with: + name: acars-bridge.arm64 + path: ./bin/acars-bridge.arm64 + + - run: ls -la ./bin/* + + - name: Cache Binaries + uses: actions/cache@v3 + with: + path: ./bin/ + key: ${{ github.run_id }} build_and_push: name: Image Build & Push + needs: [consolidate_binaries] + if: | + github.event.inputs.build_latest_as_test == 'false' || + github.event.inputs.build_latest_as_test == '' uses: sdr-enthusiasts/common-github-workflows/.github/workflows/build_and_push_image.yml@main with: push_enabled: true @@ -66,5 +224,37 @@ jobs: build_platform_specific: ${{ github.event.inputs.use_test_image == 'false' || github.event.inputs.use_test_image == '' }} build_nohealthcheck: ${{ github.event.inputs.use_test_image == 'false' || github.event.inputs.use_test_image == '' }} build_baseimage_url: :acars-decoder/:acars-decoder-test-pr + cache_enabled: true + cache_path: ./bin/ + cache_key: ${{ github.run_id }} + secrets: + ghcr_token: ${{ secrets.GITHUB_TOKEN }} + + deploy_test: + name: Deploy as test + needs: [consolidate_binaries] + if: | + github.event.inputs.build_latest_as_test == 'true' && + (github.event.inputs.use_test_image == 'false' || github.event.inputs.use_test_image == '') + uses: sdr-enthusiasts/common-github-workflows/.github/workflows/build_and_push_image.yml@main + with: + push_enabled: true + push_destinations: ghcr.io + ghcr_repo_owner: ${{ github.repository_owner }} + ghcr_repo: ${{ github.repository }} + build_with_tmpfs: true + get_version_method: git_commit_hash_short + # set build_latest to true if github.event.inputs.use_test_image is false + build_latest: true + docker_latest_tag: test + build_baseimage_test: false + # only build the entire stack if we are not using the test image + build_version_specific: false + build_platform_specific: false + build_nohealthcheck: false + build_baseimage_url: :acars-decoder/:acars-decoder-test-pr + cache_enabled: true + cache_path: ./bin/ + cache_key: ${{ github.run_id }} secrets: ghcr_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/test-pr.yml b/.github/workflows/test-pr.yml new file mode 100644 index 0000000..fce0557 --- /dev/null +++ b/.github/workflows/test-pr.yml @@ -0,0 +1,196 @@ +name: Deploy + +on: + # Build and deploy the image on pushes to main branch + push: + branches: + - main + paths: + - "rust/**" + - "Dockerfile" + - "Dockerfile.build_binary" + - "rootfs/**" + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + binary_build_armv7: + name: Build Binary - armv7 + runs-on: ubuntu-latest + # needs: test_rust_functionality + + steps: + - name: Checkout + uses: actions/checkout@v4.1.1 + with: + fetch-depth: 0 + repository: sdr-enthusiasts/acars-bridge + + - name: Run Docker on tmpfs + uses: JonasAlfredsson/docker-on-tmpfs@v1 + with: + tmpfs_size: 5 + swap_size: 4 + swap_location: "/mnt/swapfile" + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build armv7 + uses: docker/build-push-action@v5 + with: + context: . + push: false + file: Dockerfile.build_binary + tags: acars-bridge:armv7 + platforms: linux/arm/v7 + outputs: type=local,dest=./image_armv7/ + + - name: Upload artifact armv7 binary + uses: actions/upload-artifact@v4.0.0 + with: + name: acars-bridge.armv7 + path: ./image_armv7/acars-bridge + + binary_build_arm64: + name: Build Binary - arm64 + runs-on: ubuntu-latest + # needs: test_rust_functionality + + steps: + - name: Checkout + uses: actions/checkout@v4.1.1 + with: + fetch-depth: 0 + repository: sdr-enthusiasts/acars-bridge + + - name: Run Docker on tmpfs + uses: JonasAlfredsson/docker-on-tmpfs@v1 + with: + tmpfs_size: 5 + swap_size: 4 + swap_location: "/mnt/swapfile" + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build arm64 + uses: docker/build-push-action@v5 + with: + context: . + push: false + file: Dockerfile.build_binary + tags: acars-bridge:arm64 + platforms: linux/arm64 + outputs: type=local,dest=./image_arm64/ + + - name: Upload artifact arm64 binary + uses: actions/upload-artifact@v4.0.0 + with: + name: acars-bridge.arm64 + path: ./image_arm64/acars-bridge + + binary_build_amd64: + name: Build Binary - amd64 + runs-on: ubuntu-latest + # needs: test_rust_functionality + + steps: + - name: Checkout + uses: actions/checkout@v4.1.1 + with: + fetch-depth: 0 + repository: sdr-enthusiasts/acars-bridge + + - name: Run Docker on tmpfs + uses: JonasAlfredsson/docker-on-tmpfs@v1 + with: + tmpfs_size: 5 + swap_size: 4 + swap_location: "/mnt/swapfile" + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build amd64 + uses: docker/build-push-action@v5 + with: + context: . + push: false + file: Dockerfile.build_binary + tags: acars-bridge:amd64 + platforms: linux/amd64 + outputs: type=local,dest=./image_amd64/ + + - name: Upload artifact amd64 binary + uses: actions/upload-artifact@v4.0.0 + with: + name: acars-bridge.amd64 + path: ./image_amd64/acars-bridge + + consolidate_binaries: + name: Consolidate & Cache Binaries + runs-on: ubuntu-latest + needs: [binary_build_amd64, binary_build_arm64, binary_build_armv7] + steps: + - run: mkdir -p ./bin + + - uses: actions/download-artifact@v4.0.0 + with: + name: acars-bridge.amd64 + path: ./bin/acars-bridge.amd64 + + - uses: actions/download-artifact@v4.0.0 + with: + name: acars-bridge.armv7 + path: ./bin/acars-bridge.armv7 + + - uses: actions/download-artifact@v4.0.0 + with: + name: acars-bridge.arm64 + path: ./bin/acars-bridge.arm64 + + - run: ls -la ./bin/* + + - name: Cache Binaries + uses: actions/cache@v3 + with: + path: ./bin/ + key: ${{ github.run_id }} + + deploy_test: + name: Deploy as test + needs: [consolidate_binaries] + uses: sdr-enthusiasts/common-github-workflows/.github/workflows/build_and_push_image.yml@main + with: + push_enabled: false + push_destinations: ghcr.io + ghcr_repo_owner: ${{ github.repository_owner }} + ghcr_repo: ${{ github.repository }} + build_with_tmpfs: true + get_version_method: git_commit_hash_short + # set build_latest to true if github.event.inputs.use_test_image is false + build_latest: true + docker_latest_tag: test + build_baseimage_test: false + # only build the entire stack if we are not using the test image + build_version_specific: false + build_platform_specific: false + build_nohealthcheck: false + build_baseimage_url: :acars-decoder/:acars-decoder-test-pr + cache_enabled: true + cache_path: ./bin/ + cache_key: ${{ github.run_id }} + secrets: + ghcr_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/Dockerfile b/Dockerfile index bdd63d5..991ecb9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,10 +7,17 @@ ENV DEVICE_INDEX="" \ PPM="0"\ GAIN="400" \ SERIAL="" \ - SERVER="acarshub" \ - SERVER_PORT="5555" \ + OUTPUT_SERVER="acars_router" \ + OUTPUT_SERVER_PORT="5555" \ + OUTPUT_SERVER_MODE="udp" \ MODE="J" +SHELL ["/bin/bash", "-o", "pipefail", "-c"] +COPY ./rootfs / +COPY ./bin/acars-bridge.armv7/acars-bridge /opt/acars-bridge.armv7 +COPY ./bin/acars-bridge.arm64/acars-bridge /opt/acars-bridge.arm64 +COPY ./bin/acars-bridge.amd64/acars-bridge /opt/acars-bridge.amd64 + # hadolint ignore=DL3008,SC2086,SC2039,SC3054 RUN set -x && \ TEMP_PACKAGES=() && \ @@ -29,6 +36,17 @@ RUN set -x && \ "${KEPT_PACKAGES[@]}" \ "${TEMP_PACKAGES[@]}"\ && \ + # ensure binaries are executable + chmod -v a+x \ + /opt/acars-bridge.armv7 \ + /opt/acars-bridge.arm64 \ + /opt/acars-bridge.amd64 \ + && \ + # remove foreign architecture binaries + /rename_current_arch_binary.sh && \ + rm -fv \ + /opt/acars-bridge.* \ + && \ # vdlm2dec # git clone https://github.com/TLeconte/vdlm2dec.git /src/vdlm2dec && \ git clone https://github.com/wiedehopf/vdlm2dec.git /src/vdlm2dec && \ @@ -46,9 +64,6 @@ RUN set -x && \ apt-get autoremove -y && \ rm -rf /src/* /tmp/* /var/lib/apt/lists/* - -COPY rootfs/ / - # ENTRYPOINT [ "/init" ] # Add healthcheck diff --git a/Dockerfile.local b/Dockerfile.local new file mode 100644 index 0000000..342dda5 --- /dev/null +++ b/Dockerfile.local @@ -0,0 +1,74 @@ +#build acars-bridge +FROM rust:1.75.0 as builder +WORKDIR /tmp/acars-bridge +# hadolint ignore=DL3008,DL3003,SC1091 +RUN set -x && \ + apt-get update && \ + apt-get install -y --no-install-recommends libzmq3-dev + +RUN set -x && \ + git clone https://github.com/sdr-enthusiasts/acars-bridge.git . && \ + cargo build --release && \ + # clean up the apt-cache + apt-get clean && \ + rm -rf /var/lib/apt/lists/* && \ + cp /tmp/acars-bridge/target/release/acars-bridge . && \ + cargo clean + +FROM ghcr.io/sdr-enthusiasts/docker-baseimage:acars-decoder + +ENV DEVICE_INDEX="" \ + QUIET_LOGS="TRUE" \ + FREQUENCIES="" \ + FEED_ID="" \ + PPM="0"\ + GAIN="400" \ + SERIAL="" \ + OUTPUT_SERVER="acars_router" \ + OUTPUT_SERVER_PORT="5555" \ + OUTPUT_SERVER_MODE="udp" \ + MODE="J" + +# hadolint ignore=DL3008,SC2086,SC2039,SC3054 +RUN set -x && \ + TEMP_PACKAGES=() && \ + KEPT_PACKAGES=() && \ + # Required for building multiple packages. + TEMP_PACKAGES+=(build-essential) && \ + TEMP_PACKAGES+=(pkg-config) && \ + TEMP_PACKAGES+=(cmake) && \ + TEMP_PACKAGES+=(git) && \ + TEMP_PACKAGES+=(automake) && \ + TEMP_PACKAGES+=(autoconf) && \ + TEMP_PACKAGES+=(wget) && \ + # install packages + apt-get update && \ + apt-get install -y --no-install-recommends \ + "${KEPT_PACKAGES[@]}" \ + "${TEMP_PACKAGES[@]}"\ + && \ + # vdlm2dec + # git clone https://github.com/TLeconte/vdlm2dec.git /src/vdlm2dec && \ + git clone https://github.com/wiedehopf/vdlm2dec.git /src/vdlm2dec && \ + pushd /src/vdlm2dec && \ + # fix for floating point amd64 nonsense + sed -i 's/add_compile_options(-Ofast -march=native )/add_compile_options(-O2 )/g' CMakeLists.txt && \ + mkdir build && \ + pushd build && \ + cmake ../ -Drtl=ON -DCMAKE_BUILD_TYPE=Debug && \ + make && \ + make install && \ + popd && popd && \ + # Clean up + apt-get remove -y "${TEMP_PACKAGES[@]}" && \ + apt-get autoremove -y && \ + rm -rf /src/* /tmp/* /var/lib/apt/lists/* + + +COPY rootfs/ / +COPY --from=builder /tmp/acars-bridge/acars-bridge /opt/acars-bridge + +# ENTRYPOINT [ "/init" ] + +# Add healthcheck +HEALTHCHECK --start-period=3600s --interval=600s CMD /scripts/healthcheck.sh diff --git a/LICENSE b/LICENSE index 0c1ffcc..c506185 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2022 Fred Clausen +Copyright (C) 2022-2024 Fred Clausen Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index f55b30d..3b2426e 100644 --- a/README.md +++ b/README.md @@ -18,10 +18,6 @@ Please see: [Buster-Docker-Fixes](https://github.com/fredclausen/Buster-Docker-F A computer host on a suitable architecture and one USB RTL-SDR dongle connected to an antenna. -## ACARS Hub integration - -The default `SERVER` and `SERVER_PORT` values are suitable for automatically working with ACARS Hub, provided ACARS Hub is **on the same pi as the decoder**. If ACARS Hub is not on the same Pi, please provide the correct host name in the `SERVER` variable. Very likely you will not have to change the `SERVER_PORT`, but if you did change the port mapping on your ACARS Hub (and you will know if you did) please set the server port correctly as well. - ## Up and running ```yaml @@ -33,8 +29,8 @@ services: tty: true container_name: vdlm2dec restart: always - devices: - - /dev/bus/usb:/dev/bus/usb + device_cgroup_rules: + - "c 189:* rwm" ports: environment: - TZ="America/Denver" @@ -44,19 +40,37 @@ services: tmpfs: - /run:exec,size=64M - /var/log + volumes: + - /dev:/dev:ro ``` ## Configuration options -| Variable | Description | Required | Default | -| ------------- | ------------------------------------------------------------------------------------------------------------------------- | -------- | ------- | -| `TZ` | Your timezone | No | UTC | -| `SERIAL` | The serial number of your RTL-SDR dongle | Yes | Blank | -| `FEED_ID` | Used by the decoder to insert a unique ID in to the output message | Yes | Blank | -| `FREQUENCIES` | Colon-separated list of frequencies, but to a maximum of 8, for the decoder to list to | Yes | Blank | -| `PPM` | Parts per million correction of the decoder | No | 0 | -| `GAIN` | The gain applied to the RTL-SDR dongle. If you want to set the gain manually it is set in tenth of db (ie -g 90 for +9db) | No | `400` | -| `SERVER` | The server where messages will be forwarded to. | No | Blank | -| `SERVER_PORT` | The port where the server will receive messages on. | No | `5550` | -| `MODE` | The output mode. `P` for planeplotter, `J` for JSON and `A` for acarsdec. | No | `J` | -| `QUIET_LOGS` | Mute log output to the bare minimum. Set to `false` to disable. | No | `TRUE` | +| Variable | Description | Required | Default | +| ------------------------ | ------------------------------------------------------------------------------------------------------------------------- | -------- | -------------- | +| `TZ` | Your timezone | No | UTC | +| `SERIAL` | The serial number of your RTL-SDR dongle | Yes | Blank | +| `FEED_ID` | Used by the decoder to insert a unique ID in to the output message | Yes | Blank | +| `FREQUENCIES` | Colon-separated list of frequencies, but to a maximum of 8, for the decoder to list to | Yes | Blank | +| `PPM` | Parts per million correction of the decoder | No | 0 | +| `GAIN` | The gain applied to the RTL-SDR dongle. If you want to set the gain manually it is set in tenth of db (ie -g 90 for +9db) | No | `400` | +| `OUTPUT_SERVER` | The server where messages will be forwarded to. | No | `acars_router` | +| `OUTPUT_SERVER_PORT` | The port where the server will receive messages on. | No | `5555` | +| `OUTPUT_SERVER_MODE` | The output mode. `udp`, `tcp` and `zmq` are valid | No | `udp` | +| `MODE` | The output mode. `P` for planeplotter, `J` for JSON and `A` for acarsdec. | No | `J` | +| `QUIET_LOGS` | Mute log output to the bare minimum. Set to `false` to disable. | No | `TRUE` | +| `VDLM2DEC_COMMAND_EXTRA` | Additional arguments to pass to the decoder. | No | Blank | + +## Output modes + +TL;DR: No change to your setup is necessary for continued functionality, but you should update your configuration to use the new variables and at least use TCP. + +A recent change in the container has meant we are migrating from `SERVER`/`SERVER_PORT` to `OUTPUT_SERVER`/`OUTPUT_SERVER_PORT` as a better name for what the variable is representing. The old variables will continue to work for the time being, but please update your configuration to use the new variables. Simply replace `SERVER` with `OUTPUT_SERVER` and `SERVER_PORT` with `OUTPUT_SERVER_PORT`. If you do not have `SERVER`/`SERVER_PORT` set, you do not need to do anything and it will work as it did before. + +Generally speaking for a proper migration, whatever your `SERVER` was before should be set in your compose as `OUTPUT_SERVER` and whatever your `SERVER_PORT` was before should be set as `OUTPUT_SERVER_PORT`. If `SERVER` was not set, you do not have to add in `OUTPUT_SERVER`. If you did not have `SERVER_PORT` set in your compose, you do not have to add in `OUTPUT_SERVER_PORT` unless you want to use `zmq`. + +Additionally, the `OUTPUT_SERVER_MODE` variable has been added to allow for the output mode to be set. The default is `udp` and the container will function as it did before. `tcp` and `zmq` are also valid options and recommended over `udp` for reliability. + +To use `tcp` with `acars_router` with the default ports it would have mapped, simply set `OUTPUT_SERVER_MODE=tcp` and leave the `OUTPUT_SERVER_PORT` as `5555` or unset. + +If you wish to use `zmq` with `acars_router` with the default ports it would have mapped, simply set `OUTPUT_SERVER_MODE=zmq` and set `OUTPUT_SERVER_PORT` as `35555`. diff --git a/rootfs/etc/s6-overlay/s6-rc.d/vdlm_feeder/dependencies.d/01-vdlm2dec b/rootfs/etc/s6-overlay/s6-rc.d/acars_bridge/dependencies.d/01-vdlm2dec similarity index 100% rename from rootfs/etc/s6-overlay/s6-rc.d/vdlm_feeder/dependencies.d/01-vdlm2dec rename to rootfs/etc/s6-overlay/s6-rc.d/acars_bridge/dependencies.d/01-vdlm2dec diff --git a/rootfs/etc/s6-overlay/s6-rc.d/acars_bridge/run b/rootfs/etc/s6-overlay/s6-rc.d/acars_bridge/run new file mode 100755 index 0000000..a600547 --- /dev/null +++ b/rootfs/etc/s6-overlay/s6-rc.d/acars_bridge/run @@ -0,0 +1,2 @@ +#!/bin/sh +exec /etc/s6-overlay/scripts/acars_bridge diff --git a/rootfs/etc/s6-overlay/s6-rc.d/vdlm_feeder/type b/rootfs/etc/s6-overlay/s6-rc.d/acars_bridge/type similarity index 100% rename from rootfs/etc/s6-overlay/s6-rc.d/vdlm_feeder/type rename to rootfs/etc/s6-overlay/s6-rc.d/acars_bridge/type diff --git a/rootfs/etc/s6-overlay/s6-rc.d/vdlm_feeder/dependencies.d/02-gdbcheck b/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/02-gdbcheck similarity index 100% rename from rootfs/etc/s6-overlay/s6-rc.d/vdlm_feeder/dependencies.d/02-gdbcheck rename to rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/02-gdbcheck diff --git a/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/vdlm_feeder b/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/acars_bridge similarity index 100% rename from rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/vdlm_feeder rename to rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/acars_bridge diff --git a/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/vdlm_server b/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/vdlm_server deleted file mode 100644 index e69de29..0000000 diff --git a/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/vdlm_stats b/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/vdlm_stats deleted file mode 100644 index e69de29..0000000 diff --git a/rootfs/etc/s6-overlay/s6-rc.d/vdlm2dec/.blank b/rootfs/etc/s6-overlay/s6-rc.d/vdlm2dec/.blank deleted file mode 100644 index e69de29..0000000 diff --git a/rootfs/etc/s6-overlay/s6-rc.d/vdlm_feeder/run b/rootfs/etc/s6-overlay/s6-rc.d/vdlm_feeder/run deleted file mode 100755 index be5edc3..0000000 --- a/rootfs/etc/s6-overlay/s6-rc.d/vdlm_feeder/run +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -exec /etc/s6-overlay/scripts/vdlm_feeder diff --git a/rootfs/etc/s6-overlay/s6-rc.d/vdlm_server/dependencies.d/01-vdlm2dec b/rootfs/etc/s6-overlay/s6-rc.d/vdlm_server/dependencies.d/01-vdlm2dec deleted file mode 100644 index e69de29..0000000 diff --git a/rootfs/etc/s6-overlay/s6-rc.d/vdlm_server/dependencies.d/02-gdbcheck b/rootfs/etc/s6-overlay/s6-rc.d/vdlm_server/dependencies.d/02-gdbcheck deleted file mode 100644 index e69de29..0000000 diff --git a/rootfs/etc/s6-overlay/s6-rc.d/vdlm_server/run b/rootfs/etc/s6-overlay/s6-rc.d/vdlm_server/run deleted file mode 100755 index 6a712f8..0000000 --- a/rootfs/etc/s6-overlay/s6-rc.d/vdlm_server/run +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -exec /etc/s6-overlay/scripts/vdlm_server diff --git a/rootfs/etc/s6-overlay/s6-rc.d/vdlm_server/type b/rootfs/etc/s6-overlay/s6-rc.d/vdlm_server/type deleted file mode 100644 index 5883cff..0000000 --- a/rootfs/etc/s6-overlay/s6-rc.d/vdlm_server/type +++ /dev/null @@ -1 +0,0 @@ -longrun diff --git a/rootfs/etc/s6-overlay/s6-rc.d/vdlm_stats/dependencies.d/01-vdlm2dec b/rootfs/etc/s6-overlay/s6-rc.d/vdlm_stats/dependencies.d/01-vdlm2dec deleted file mode 100644 index e69de29..0000000 diff --git a/rootfs/etc/s6-overlay/s6-rc.d/vdlm_stats/dependencies.d/02-gdbcheck b/rootfs/etc/s6-overlay/s6-rc.d/vdlm_stats/dependencies.d/02-gdbcheck deleted file mode 100644 index e69de29..0000000 diff --git a/rootfs/etc/s6-overlay/s6-rc.d/vdlm_stats/run b/rootfs/etc/s6-overlay/s6-rc.d/vdlm_stats/run deleted file mode 100755 index 91aa3bf..0000000 --- a/rootfs/etc/s6-overlay/s6-rc.d/vdlm_stats/run +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -exec /etc/s6-overlay/scripts/vdlm_stats diff --git a/rootfs/etc/s6-overlay/s6-rc.d/vdlm_stats/type b/rootfs/etc/s6-overlay/s6-rc.d/vdlm_stats/type deleted file mode 100644 index 5883cff..0000000 --- a/rootfs/etc/s6-overlay/s6-rc.d/vdlm_stats/type +++ /dev/null @@ -1 +0,0 @@ -longrun diff --git a/rootfs/etc/s6-overlay/scripts/01-vdlm2dec b/rootfs/etc/s6-overlay/scripts/01-vdlm2dec index db4e76c..4260fcb 100755 --- a/rootfs/etc/s6-overlay/scripts/01-vdlm2dec +++ b/rootfs/etc/s6-overlay/scripts/01-vdlm2dec @@ -51,11 +51,6 @@ if [[ "${MODE}" != @(J|j|P|p|A|a) ]]; then exit 1 fi -if [[ -n "${SERVER}" && -z "${SERVER_PORT}" ]]; then - "${s6wrap[@]}" echo "SERVER is set but SERVER_PORT is not set, exiting" - exit 1 -fi - # DEVICE_ID or SERIAL needs to be set if [[ -z "${SERIAL}" ]]; then diff --git a/rootfs/etc/s6-overlay/scripts/acars_bridge b/rootfs/etc/s6-overlay/scripts/acars_bridge new file mode 100755 index 0000000..a7ca9d9 --- /dev/null +++ b/rootfs/etc/s6-overlay/scripts/acars_bridge @@ -0,0 +1,45 @@ +#!/command/with-contenv bash +# shellcheck shell=bash + +SCRIPT_NAME="$(basename "$0")" +SCRIPT_NAME="${SCRIPT_NAME%.*}" + +# shellcheck disable=SC2034 +s6wrap=(s6wrap --quiet --timestamps --prepend="$SCRIPT_NAME" --args) +# lets see if legacy SERVER / SERVER_PORT are set + +if [[ -n "$SERVER" ]]; then + "${s6wrap[@]}" echo "[WARN] SERVER is deprecated, please use OUTPUT_SERVER" + OUTPUT_SERVER="$SERVER" +fi + +if [[ -n "$SERVER_PORT" ]]; then + "${s6wrap[@]}" echo "[WARN] SERVER_PORT is deprecated, please use OUTPUT_SERVER_PORT" + OUTPUT_SERVER_PORT="$SERVER_PORT" +fi + +# detect legacy udp +if [[ "$OUTPUT_SERVER_MODE" == "udp" ]]; then + "${s6wrap[@]}" echo "[WARN] Using UDP mode to connect to $OUTPUT_SERVER:$OUTPUT_SERVER_PORT. Suggest switching to TCP or ZMQ Mode. Please see documentation for more information." +fi + +SOURCE_PORT=5555 +ACARS_BRIDGE_BIN="/opt/acars-bridge" +ACARS_BRIDGE_CMD=(--source-port "$SOURCE_PORT") +ACARS_BRIDGE_CMD+=(--source-protocol "udp") +ACARS_BRIDGE_CMD+=(--source-host "0.0.0.0") + +if [[ -n "$OUTPUT_SERVER" ]]; then + ACARS_BRIDGE_CMD+=(--destination-host "$OUTPUT_SERVER") +fi + +if [[ -n "$OUTPUT_SERVER_PORT" ]]; then + ACARS_BRIDGE_CMD+=(--destination-port "$OUTPUT_SERVER_PORT") +fi + +if [[ -n "$OUTPUT_SERVER_MODE" ]]; then + ACARS_BRIDGE_CMD+=(--destination-protocol "$OUTPUT_SERVER_MODE") +fi + +"${s6wrap[@]}" echo "[INFO] Starting acars-bridge with command: $ACARS_BRIDGE_BIN ${ACARS_BRIDGE_CMD[*]}" +"${s6wrap[@]}" "$ACARS_BRIDGE_BIN" "${ACARS_BRIDGE_CMD[@]}" diff --git a/rootfs/etc/s6-overlay/scripts/vdlm2dec b/rootfs/etc/s6-overlay/scripts/vdlm2dec index 9983872..3335d4e 100755 --- a/rootfs/etc/s6-overlay/scripts/vdlm2dec +++ b/rootfs/etc/s6-overlay/scripts/vdlm2dec @@ -6,14 +6,6 @@ SCRIPT_NAME="${SCRIPT_NAME%.*}" # shellcheck disable=SC2034 s6wrap=(s6wrap --quiet --timestamps --prepend="$SCRIPT_NAME" --args) -# Require that vdlm_server is running -if ! netstat -an | grep -P '^\s*tcp\s+\d+\s+\d+\s+0\.0\.0\.0:15555\s+(?>\d{1,3}\.{0,1}){4}:\*\s+LISTEN\s*$' > /dev/null; then - sleep 1 - if [[ ! ${QUIET_LOGS,,} =~ true ]]; then - "${s6wrap[@]}" echo "vdlm_server not running, exiting" - fi - exit -fi VDLM_BIN="/usr/local/bin/vdlm2dec" # shellcheck disable=SC2001 @@ -35,22 +27,25 @@ if [ -n "${QUIET_LOGS}" ]; then VDLM_CMD+=("-v") fi -# Send output JSON to acars_server -if [ -n "${SERVER}" ]; then - if [[ "${MODE}" == @(J|j) ]]; then - VDLM_CMD+=("-j" "127.0.0.1:5555") - elif [[ "${MODE}" == @(P|p) ]]; then - VDLM_CMD+=("-n" "127.0.0.1:5555") - elif [[ "${MODE}" == @(A|a) ]]; then - VDLM_CMD+=("-N" "127.0.0.1:5555") - fi + +if [[ "${MODE}" == @(J|j) ]]; then + VDLM_CMD+=("-j" "127.0.0.1:5555") +elif [[ "${MODE}" == @(P|p) ]]; then + VDLM_CMD+=("-n" "127.0.0.1:5555") +elif [[ "${MODE}" == @(A|a) ]]; then + VDLM_CMD+=("-N" "127.0.0.1:5555") fi + # Specify device ID if [ -n "${SERIAL}" ]; then VDLM_CMD+=("-r" "$SERIAL") fi +if [[ -n "$VDLM2DEC_COMMAND_EXTRA" ]]; then + VDLM_CMD+=("$VDLM2DEC_COMMAND_EXTRA") +fi + # shellcheck disable=SC2206 VDLM_CMD+=($FREQ_STRING) diff --git a/rootfs/etc/s6-overlay/scripts/vdlm_feeder b/rootfs/etc/s6-overlay/scripts/vdlm_feeder deleted file mode 100755 index d8050c0..0000000 --- a/rootfs/etc/s6-overlay/scripts/vdlm_feeder +++ /dev/null @@ -1,26 +0,0 @@ -#!/command/with-contenv bash -# shellcheck shell=bash - -SCRIPT_NAME="$(basename "$0")" -SCRIPT_NAME="${SCRIPT_NAME%.*}" - -# shellcheck disable=SC2034 -s6wrap=(s6wrap --quiet --timestamps --prepend="$SCRIPT_NAME" --args) - -set -o pipefail - -# Require that vdlm_server is running -if ! netstat -an | grep -P '^\s*tcp\s+\d+\s+\d+\s+0\.0\.0\.0:15555\s+(?>\d{1,3}\.{0,1}){4}:\*\s+LISTEN\s*$' > /dev/null; then - sleep 1 - if [[ ! ${QUIET_LOGS,,} =~ true ]]; then - "${s6wrap[@]}" echo "vdlm_server not running, exiting" - fi - exit -fi -set -e - -SERVER_ADDR="UDP:${SERVER}:${SERVER_PORT}" -# shellcheck disable=SC2016 -socat -d TCP:127.0.0.1:15555 "$SERVER_ADDR" - -sleep 5 diff --git a/rootfs/etc/s6-overlay/scripts/vdlm_server b/rootfs/etc/s6-overlay/scripts/vdlm_server deleted file mode 100755 index 308f2e3..0000000 --- a/rootfs/etc/s6-overlay/scripts/vdlm_server +++ /dev/null @@ -1,11 +0,0 @@ -#!/command/with-contenv bash -#shellcheck shell=bash - -set -o pipefail -set -e - -# Listens for the output of vdlm2dec (UDP), and makes it available for multiple processes at TCP port 15555 -# shellcheck disable=SC2016 -socat -u udp-listen:5555,fork stdout | ncat -4 --keep-open --listen 0.0.0.0 15555 - -sleep 5 diff --git a/rootfs/etc/s6-overlay/scripts/vdlm_stats b/rootfs/etc/s6-overlay/scripts/vdlm_stats deleted file mode 100755 index e479b90..0000000 --- a/rootfs/etc/s6-overlay/scripts/vdlm_stats +++ /dev/null @@ -1,44 +0,0 @@ -#!/command/with-contenv bash -#shellcheck shell=bash - -SCRIPT_NAME="$(basename "$0")" -SCRIPT_NAME="${SCRIPT_NAME%.*}" - -# shellcheck disable=SC2034 -s6wrap=(s6wrap --quiet --timestamps --prepend="$SCRIPT_NAME" --args) - -set -o pipefail - -# Require that vdlm_server is running -if ! netstat -an | grep -P '^\s*tcp\s+\d+\s+\d+\s+0\.0\.0\.0:15555\s+(?>\d{1,3}\.{0,1}){4}:\*\s+LISTEN\s*$' > /dev/null; then - sleep 1 - if [[ ! ${QUIET_LOGS,,} =~ true ]]; then - "${s6wrap[@]}" echo "vdlm_server not running, exiting" - fi - exit -fi - -# Start our stats loop -while true; do - - # capture 5 mins of flows - timeout --foreground 300s socat -u TCP:127.0.0.1:15555 CREATE:/run/acars/vdlm2.past5min.json - - # if the port isn't reachable, this file isn't created, either container is shutting down or vdlm_server isn't reachable - # in both cases let's exit, if this should still be running it will be restarted - if ! [[ -f /run/acars/vdlm2.past5min.json ]]; then - exit - fi - - # shellcheck disable=SC2016 - "${s6wrap[@]}" echo "$(wc -l < /run/acars/vdlm2.past5min.json) VDLM messages received in last 5 mins" - - # rotate files keeping last 2 hours - for i in {24..1}; do - mv "/run/acars/vdlm2.$((i-1)).json" "/run/acars/vdlm2.$i.json" > /dev/null 2>&1 || true - done - mv "/run/acars/vdlm2.past5min.json" "/run/acars/vdlm2.0.json" > /dev/null 2>&1 || true - -done - -sleep 5 diff --git a/rootfs/rename_current_arch_binary.sh b/rootfs/rename_current_arch_binary.sh new file mode 100755 index 0000000..0d666ef --- /dev/null +++ b/rootfs/rename_current_arch_binary.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +set -x + +ls -la /opt/ + +# determine which binary to keep +if /opt/acars-bridge.amd64 --version > /dev/null 2>&1; then + mv -v /opt/acars-bridge.amd64 /opt/acars-bridge +elif /opt/acars-bridge.arm64 --version > /dev/null 2>&1; then + mv -v /opt/acars-bridge.arm64 /opt/acars-bridge +elif /opt/acars-bridge.armv7 --version > /dev/null 2>&1; then + mv -v /opt/acars-bridge.armv7 /opt/acars-bridge +else + >&2 echo "ERROR: Unsupported architecture" + exit 1 +fi