From e753a1fdc187a497b06bff0dd04420a426786c99 Mon Sep 17 00:00:00 2001 From: tchapacan Date: Mon, 1 Apr 2024 17:54:24 +0200 Subject: [PATCH] remove unecessary println && add publish workflow --- .github/workflows/publish.yml | 57 +++++++++++++++++++++++++++++++++ Dockerfile | 29 +++++++++++++++++ src/livebox_client_rs/client.rs | 3 -- 3 files changed, 86 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/publish.yml create mode 100644 Dockerfile diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..5a3c7a6 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,57 @@ +name: "Release docker image" +run-name: "Release docker image: ${{ github.event.release.name }} ⛑️" + +on: + push: +# release: +# types: [published] + +jobs: + docker: + name: Docker + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Docker meta + id: meta + uses: docker/metadata-action@v4 + with: + images: ${{ github.repository }} + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + with: + platforms: linux/amd64,linux/arm64 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + id: buildx + + - name: Inspect builder + run: | + echo "Name: ${{ steps.buildx.outputs.name }}" + echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}" + echo "Status: ${{ steps.buildx.outputs.status }}" + echo "Flags: ${{ steps.buildx.outputs.flags }}" + echo "Platforms: ${{ steps.buildx.outputs.platforms }}" + +# - name: Login to DockerHub +# uses: docker/login-action@v2 +# if: github.event_name != 'pull_request' +# with: +# username: ${{ secrets.DOCKERHUB_USERNAME }} +# password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and push + uses: docker/build-push-action@v4 + id: docker_build + with: + builder: ${{ steps.buildx.outputs.name }} + context: . + file: ./Dockerfile + platforms: linux/amd64,linux/arm64 + push: false + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ef10577 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,29 @@ +# Workaround for QEmu bug when building for 32bit platforms on a 64bit host +FROM --platform=$BUILDPLATFORM rust:bookworm as vendor +ARG BUILDPLATFORM +ARG TARGETPLATFORM +RUN echo "Running on: $BUILDPLATFORM / Building for $TARGETPLATFORM" +WORKDIR /app + +COPY ./Cargo.toml . +COPY ./Cargo.lock . +COPY ./src src +RUN mkdir .cargo && cargo vendor > .cargo/config.toml + +FROM rust:bookworm as builder +WORKDIR /app + +COPY --from=vendor /app/.cargo .cargo +COPY --from=vendor /app/vendor vendor +COPY ./Cargo.toml . +COPY ./Cargo.lock . +COPY ./src src +RUN cargo build --release + +FROM debian:bookworm-slim +WORKDIR /app +ENV RUST_BACKTRACE=full +COPY --from=builder /app/target/release/livebox-exporter-rs livebox-exporter-rs + +EXPOSE 9100 +ENTRYPOINT ["/app/livebox-exporter-rs"] diff --git a/src/livebox_client_rs/client.rs b/src/livebox_client_rs/client.rs index 770d3d8..64add1a 100644 --- a/src/livebox_client_rs/client.rs +++ b/src/livebox_client_rs/client.rs @@ -137,7 +137,6 @@ impl Client { .authenticated_post_request("DeviceInfo", "get", serde_json::json!({})) .await; let json: Value = serde_json::from_slice(&body_bytes).expect("Could not parse JSON."); - println!("Body was: '{}'.", std::str::from_utf8(&body_bytes).unwrap()); assert!( parts.status.is_success(), "Router answered with something else than a success code." @@ -153,7 +152,6 @@ impl Client { .authenticated_post_request("NMC", "getWANStatus", serde_json::json!({})) .await; let json: Value = serde_json::from_slice(&body_bytes).expect("Could not parse JSON."); - println!("Body was: '{}'.", std::str::from_utf8(&body_bytes).unwrap()); assert!( parts.status.is_success(), "Router answered with something else than a success code." @@ -185,7 +183,6 @@ impl Client { .authenticated_post_request("HomeLan", "getResults", post_data) .await; let json: Value = serde_json::from_slice(&body_bytes).expect("Could not parse JSON."); - println!("Body was: '{}'.", std::str::from_utf8(&body_bytes).unwrap()); let mut metrics: Vec = Vec::new(); if let Some(status) = json["status"].as_object() { for (key, value) in status.iter() {