diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 99d3a799..877d92a5 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -16,6 +16,7 @@ on: - "**.md" - "**.MD" - "**.yml" + - "**.yaml" - "LICENSE" - ".gitattributes" - ".gitignore" @@ -38,8 +39,168 @@ jobs: echo "Workflow dispatch reason: $INPUTS_REASON" echo "::notice title=${{ github.job }}: Workflow Dispatch Reason::${INPUTS_REASON}" + binary_build: + name: Build Binaries + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: "Install OS dependencies: armhf" + uses: ryankurte/action-apt@v0.3.0 + with: + arch: armhf + packages: "libzmq3-dev:armhf" + + - name: "Install OS dependencies: arm64" + uses: ryankurte/action-apt@v0.3.0 + with: + arch: arm64 + packages: "libzmq3-dev:arm64" + + # i386 currently does not work... + # - name: "Install OS dependencies: i386" + # uses: ryankurte/action-apt@v0.3.0 + # with: + # arch: i386 + # packages: "libzmq3-dev:i386" + + - name: "Install OS dependencies: arm64" + run: | + sudo apt-get update + sudo apt-get install -y --no-install-recommends \ + libzmq3-dev + + - name: "Install rust targets/toolchains for cross build" + run: | + sudo apt-get update + sudo apt-get install -y --no-install-recommends \ + g++-arm-linux-gnueabihf \ + libc6-dev-armhf-cross \ + g++-aarch64-linux-gnu \ + libc6-dev-arm64-cross + + rustup target add armv7-unknown-linux-gnueabihf + rustup toolchain install stable-armv7-unknown-linux-gnueabihf + rustup target add aarch64-unknown-linux-gnu + rustup toolchain install stable-aarch64-unknown-linux-gnu + rustup target add x86_64-unknown-linux-gnu + rustup toolchain install stable-x86_64-unknown-linux-gnu + + - name: Build armv7 + run: | + PKG_CONFIG_SYSROOT_DIR=/usr/arm-linux-gnueabihf RUSTFLAGS="-C linker=/usr/bin/arm-linux-gnueabihf-gcc" cargo build --release --target armv7-unknown-linux-gnueabihf + + - name: Build arm64 + run: | + PKG_CONFIG_SYSROOT_DIR=/usr/aarch64-linux-gnu RUSTFLAGS="-C linker=/usr/bin/aarch64-linux-gnu-gcc" cargo build --release --target aarch64-unknown-linux-gnu + + - name: Build amd64 + run: | + cargo build --release + + - name: Consolidate binaries + run: | + mkdir -p ./bin + cp -v ./target/release/acars_router ./bin/acars_router.amd64 + cp -v ./target/armv7-unknown-linux-gnueabihf/release/acars_router ./bin/acars_router.armv7 + cp -v ./target/aarch64-unknown-linux-gnu/release/acars_router ./bin/acars_router.arm64 + + - name: Upload artifact amd64 binary + uses: actions/upload-artifact@v3 + with: + name: acars_router.amd64 + path: ./bin/acars_router.amd64 + + - name: Upload artifact armv7 binary + uses: actions/upload-artifact@v3 + with: + name: acars_router.armv7 + path: ./bin/acars_router.armv7 + + - name: Upload artifact arm64 binary + uses: actions/upload-artifact@v3 + with: + name: acars_router.arm64 + path: ./bin/acars_router.arm64 + + - name: Cache Cargo Build Output + uses: actions/cache@v3 + with: + path: bin/ + key: ${{ github.run_id }} + + # # Allows troubleshooting via SSH + # - name: Setup upterm session + # uses: lhotari/action-upterm@v1 + # env: + # GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # with: + # limit-access-to-users: mikenye + + release_binaries: + name: Release Binaries + needs: [binary_build] + runs-on: ubuntu-latest + steps: + + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Cache cargo build output + id: get_cache + uses: actions/cache@v3 + with: + path: bin/ + key: ${{ github.run_id }} + + - name: Check cache + if: steps.get_cache.outputs.cache-hit != 'true' + run: | + echo "::error title=${{ github.job }}: Could not get binaries from action cache" + exit 1 + + - name: Prepare binary release tarballs + if: steps.get_cache.outputs.cache-hit == 'true' + run: | + ORIGDIR=$(pwd) + # Make release tarballs + mkdir -vp ./release + pushd ./bin + tar cJvf "$ORIGDIR/release/acars_router.amd64.tar.xz" ./acars_router.amd64 + tar cJvf "$ORIGDIR/release/acars_router.armv7.tar.xz" ./acars_router.armv7 + tar cJvf "$ORIGDIR/release/acars_router.arm64.tar.xz" ./acars_router.arm64 + popd + + - name: Get binary version from Cargo.toml + if: steps.get_cache.outputs.cache-hit == 'true' + id: release_version + run: | + # Get version from Cargo.toml + RELEASE_VERSION=$(cat Cargo.toml | grep '\[package\]' -A9999 | grep -m 1 'version = ' | tr -d " " | tr -d '"' | tr -d "'" | cut -d = -f 2) + echo "::set-output name=RELEASE_VERSION::$RELEASE_VERSION" + + - name: Create tag + uses: rickstaa/action-create-tag@v1 + with: + tag: ${{ steps.release_version.outputs.RELEASE_VERSION }} + + - name: Create binary release + if: steps.get_cache.outputs.cache-hit == 'true' + uses: ncipollo/release-action@v1 + with: + artifacts: ./release/*.tar.xz + token: ${{ secrets.GITHUB_TOKEN }} + name: ${{ steps.release_version.outputs.RELEASE_VERSION }} + tag: ${{ steps.release_version.outputs.RELEASE_VERSION }} + deploy: name: Deploy + needs: [binary_build] uses: sdr-enthusiasts/common-github-workflows/.github/workflows/build_and_push_image.yml@main with: push_enabled: true @@ -47,5 +208,10 @@ jobs: ghcr_repo_owner: ${{ github.repository_owner }} ghcr_repo: ${{ github.repository }} build_with_tmpfs: true + get_version_method: cargo_toml_file_in_repo:file=/Cargo.toml + build_nohealthcheck: false + cache_enabled: true + cache_path: bin/ + cache_key: ${{ github.run_id }} secrets: ghcr_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/on_pr.yaml b/.github/workflows/on_pr.yaml index 38ac6790..57cdb6c4 100644 --- a/.github/workflows/on_pr.yaml +++ b/.github/workflows/on_pr.yaml @@ -18,20 +18,7 @@ on: - "**.sh" jobs: - flake8-lint: - runs-on: ubuntu-latest - name: "Linting: flake8" - steps: - - name: Check out source repository - uses: actions/checkout@v3 - - name: Set up Python environment - uses: actions/setup-python@v4 - with: - python-version: "3.9" - - name: flake8 Lint - uses: py-actions/flake8@v2 - with: - ignore: "E501" + hadolint: name: "Linting: hadolint" runs-on: ubuntu-latest @@ -73,7 +60,6 @@ jobs: test_functionality: name: "Test Functionality" runs-on: ubuntu-latest - needs: flake8-lint steps: - name: Checkout uses: actions/checkout@v3 @@ -136,82 +122,115 @@ jobs: # - name: Clean up between tests # run: ./test_data/clean_up_after_test.sh vdlm2 - test_build: - name: Test Build + binary_build: + name: Build Binaries runs-on: ubuntu-latest - needs: [hadolint, flake8-lint] - strategy: - matrix: - docker-platform: - - linux/amd64 - - linux/arm64 - # - linux/arm/v6 - - linux/arm/v7 - - linux/i386 steps: - # Check out our code - name: Checkout uses: actions/checkout@v3 with: fetch-depth: 0 - # List of files to check to trigger a rebuild on this job - - name: Get specific changed files - id: changed-files-specific - uses: tj-actions/changed-files@v23.2 + - name: "Install OS dependencies: armhf" + uses: ryankurte/action-apt@v0.3.0 with: - files: | - Dockerfile - acars_router - !*.md - !*.MD - - # https://github.com/marketplace/actions/docker-on-tmpfs - # https://github.com/rust-lang/cargo/issues/8719 - # https://github.com/rust-lang/cargo/issues/9545 - - - name: Run Docker on tmpfs - if: steps.changed-files-specific.outputs.any_changed == 'true' - uses: JonasAlfredsson/docker-on-tmpfs@v1 + arch: armhf + packages: "libzmq3-dev:armhf" + + - name: "Install OS dependencies: arm64" + uses: ryankurte/action-apt@v0.3.0 with: - tmpfs_size: 5 - swap_size: 4 - swap_location: "/mnt/swapfile" - - # Set up QEMU for multi-arch builds - - name: Set up QEMU - if: steps.changed-files-specific.outputs.any_changed == 'true' - uses: docker/setup-qemu-action@v2 - - # Set up buildx for multi platform builds - - name: Set up Docker Buildx - if: steps.changed-files-specific.outputs.any_changed == 'true' - id: buildx - uses: docker/setup-buildx-action@v2 - - # Build - - name: Test Build - if: steps.changed-files-specific.outputs.any_changed == 'true' - uses: docker/build-push-action@v3 + arch: arm64 + packages: "libzmq3-dev:arm64" + + # i386 currently does not work... + # - name: "Install OS dependencies: i386" + # uses: ryankurte/action-apt@v0.3.0 + # with: + # arch: i386 + # packages: "libzmq3-dev:i386" + + - name: "Install OS dependencies: arm64" + run: | + sudo apt-get update + sudo apt-get install -y --no-install-recommends \ + libzmq3-dev + + - name: "Install rust targets/toolchains for cross build" + run: | + sudo apt-get update + sudo apt-get install -y --no-install-recommends \ + g++-arm-linux-gnueabihf \ + libc6-dev-armhf-cross \ + g++-aarch64-linux-gnu \ + libc6-dev-arm64-cross + + rustup target add armv7-unknown-linux-gnueabihf + rustup toolchain install stable-armv7-unknown-linux-gnueabihf + rustup target add aarch64-unknown-linux-gnu + rustup toolchain install stable-aarch64-unknown-linux-gnu + rustup target add x86_64-unknown-linux-gnu + rustup toolchain install stable-x86_64-unknown-linux-gnu + + - name: Build armv7 + run: | + PKG_CONFIG_SYSROOT_DIR=/usr/arm-linux-gnueabihf RUSTFLAGS="-C linker=/usr/bin/arm-linux-gnueabihf-gcc" cargo build --release --target armv7-unknown-linux-gnueabihf + + - name: Build arm64 + run: | + PKG_CONFIG_SYSROOT_DIR=/usr/aarch64-linux-gnu RUSTFLAGS="-C linker=/usr/bin/aarch64-linux-gnu-gcc" cargo build --release --target aarch64-unknown-linux-gnu + + - name: Build amd64 + run: | + cargo build --release + + - name: Consolidate binaries + run: | + mkdir -p ./bin + cp -v ./target/release/acars_router ./bin/acars_router.amd64 + cp -v ./target/armv7-unknown-linux-gnueabihf/release/acars_router ./bin/acars_router.armv7 + cp -v ./target/aarch64-unknown-linux-gnu/release/acars_router ./bin/acars_router.arm64 + + - name: Upload artifact amd64 binary + uses: actions/upload-artifact@v3 + with: + name: acars_router.amd64 + path: ./bin/acars_router.amd64 + + - name: Upload artifact armv7 binary + uses: actions/upload-artifact@v3 + with: + name: acars_router.armv7 + path: ./bin/acars_router.armv7 + + - name: Upload artifact arm64 binary + uses: actions/upload-artifact@v3 + with: + name: acars_router.arm64 + path: ./bin/acars_router.arm64 + + - name: Cache Cargo Build Output + uses: actions/cache@v3 with: - context: . - file: ./Dockerfile - no-cache: true - platforms: ${{ matrix.docker-platform }} - push: false - - # # Patch dockerfile to remove healthcheck - # - name: Patch Dockerfile to remove healthcheck - # if: steps.changed-files-specific.outputs.any_changed == 'true' - # run: sed '/^HEALTHCHECK /d' < Dockerfile > Dockerfile.nohealthcheck - - # # Build nohealthcheck - # - name: Test Build nohealthcheck - # if: steps.changed-files-specific.outputs.any_changed == 'true' - # uses: docker/build-push-action@v3 + path: bin/ + key: ${{ github.run_id }} + + # # Allows troubleshooting via SSH + # - name: Setup upterm session + # uses: lhotari/action-upterm@v1 + # env: + # GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} # with: - # context: . - # file: ./Dockerfile.nohealthcheck - # no-cache: true - # platforms: ${{ matrix.docker-platform }} - # push: false + # limit-access-to-users: mikenye + + test_docker_image_build: + name: Test Docker Image Build + needs: [hadolint, binary_build, test_functionality] + uses: sdr-enthusiasts/common-github-workflows/.github/workflows/build_and_push_image.yml@main + with: + get_version_method: cargo_toml_file_in_repo:file=/Cargo.toml + build_with_tmpfs: true + build_nohealthcheck: false + cache_enabled: true + cache_path: bin/ + cache_key: ${{ github.run_id }} diff --git a/Dockerfile b/Dockerfile index b90707e9..2ffa0bcb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,3 @@ -FROM rust:1.62-bullseye as builder -WORKDIR /tmp/acars_router -# hadolint ignore=DL3008,DL3003,SC1091 -RUN set -x && \ - apt-get update && \ - apt-get install -y --no-install-recommends libzmq3-dev -COPY . . - -RUN cargo build --release - FROM ghcr.io/sdr-enthusiasts/docker-baseimage:base ENV AR_LISTEN_UDP_ACARS=5550 \ @@ -20,18 +10,28 @@ ENV AR_LISTEN_UDP_ACARS=5550 \ AR_SERVE_ZMQ_VDLM2=45555 SHELL ["/bin/bash", "-o", "pipefail", "-c"] -COPY rootfs / -COPY --from=builder /tmp/acars_router/target/release/acars_router /opt/acars_router +COPY ./rootfs / +COPY ./bin/acars_router.armv7 /opt/acars_router.armv7 +COPY ./bin/acars_router.arm64 /opt/acars_router.arm64 +COPY ./bin/acars_router.amd64 /opt/acars_router.amd64 + # hadolint ignore=DL3008,DL3003,SC1091 RUN set -x && \ KEPT_PACKAGES=() && \ + TEMP_PACKAGES=() && \ KEPT_PACKAGES+=(libzmq5) && \ apt-get update && \ apt-get install -y --no-install-recommends \ - "${KEPT_PACKAGES[@]}" \ - "${TEMP_PACKAGES[@]}"\ - && \ - # Simple date/time versioning - date +%Y%m%d.%H%M > /IMAGE_VERSION && \ + "${KEPT_PACKAGES[@]}" \ + "${TEMP_PACKAGES[@]}"\ + && \ + # ensure binaries are executable + chmod -v a+x \ + /opt/acars_router.armv7 \ + /opt/acars_router.arm64 \ + /opt/acars_router.amd64 \ + && \ + # clean up + apt-get remove -y "${TEMP_PACKAGES[@]}" && \ apt-get autoremove -y && \ rm -rf /src/* /tmp/* /var/lib/apt/lists/* diff --git a/Dockerfile.local b/Dockerfile.local new file mode 100644 index 00000000..6b3097d9 --- /dev/null +++ b/Dockerfile.local @@ -0,0 +1,42 @@ +FROM rust:1.62-bullseye as builder +WORKDIR /tmp/acars_router +# hadolint ignore=DL3008,DL3003,SC1091 +RUN set -x && \ + apt-get update && \ + apt-get install -y --no-install-recommends libzmq3-dev +COPY . . + +RUN cargo build --release + +FROM ghcr.io/sdr-enthusiasts/docker-baseimage:base + +ENV AR_LISTEN_UDP_ACARS=5550 \ + AR_LISTEN_TCP_ACARS=5550 \ + AR_LISTEN_UDP_VDLM2=5555 \ + AR_LISTEN_TCP_VDLM2=5555 \ + AR_SERVE_TCP_ACARS=15550 \ + AR_SERVE_TCP_VDLM2=15555 \ + AR_SERVE_ZMQ_ACARS=45550 \ + AR_SERVE_ZMQ_VDLM2=45555 + +SHELL ["/bin/bash", "-o", "pipefail", "-c"] +COPY rootfs / +COPY --from=builder /tmp/acars_router/target/release/acars_router /opt/acars_router +# hadolint ignore=DL3008,DL3003,SC1091 +RUN set -x && \ + KEPT_PACKAGES=() && \ + TEMP_PACKAGES=() && \ + KEPT_PACKAGES+=(libzmq5) && \ + apt-get update && \ + apt-get install -y --no-install-recommends \ + "${KEPT_PACKAGES[@]}" \ + "${TEMP_PACKAGES[@]}"\ + && \ + # ensure binaries are executable + chmod -v a+x \ + /opt/acars_router \ + && \ + # clean up + apt-get remove -y "${TEMP_PACKAGES[@]}" && \ + apt-get autoremove -y && \ + rm -rf /src/* /tmp/* /var/lib/apt/lists/* diff --git a/rootfs/etc/services.d/acars_router/run b/rootfs/etc/services.d/acars_router/run index f5219707..863ff3d0 100755 --- a/rootfs/etc/services.d/acars_router/run +++ b/rootfs/etc/services.d/acars_router/run @@ -1,4 +1,20 @@ #!/usr/bin/with-contenv bash # shellcheck shell=bash -/opt/acars_router +if /opt/acars_router.amd64 --version > /dev/null 2>&1; then + /opt/acars_router.amd64 + +elif /opt/acars_router.arm64 --version > /dev/null 2>&1; then + /opt/acars_router.arm64 + +elif /opt/acars_router.armv7 --version > /dev/null 2>&1; then + /opt/acars_router.armv7 + +elif /opt/acars_router --version > /dev/null 2>&1; then + /opt/acars_router + +else + >&2 echo "ERROR: Unsupported architecture" + sleep 60 + exit 1 +fi