From 8f6e37cd642d684d1210520d9bcd83e8bd4e35df Mon Sep 17 00:00:00 2001 From: Marco Cadetg Date: Sat, 22 Feb 2025 11:32:37 +0100 Subject: [PATCH 1/3] feat: docker container --- .dockerignore | 12 +++++++++ .github/workflows/package.yml | 24 +++++++++++++++++ .gitignore | 3 +-- Dockerfile | 49 +++++++++++++++++++++++++++++++++++ 4 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..c42a35d8d --- /dev/null +++ b/.dockerignore @@ -0,0 +1,12 @@ +/target +.git +.gitignore +.github +*.md +Dockerfile +.dockerignore +LICENSE-APACHE +LICENSE-MIT +*.sh +.editorconfig +.gitattributes \ No newline at end of file diff --git a/.github/workflows/package.yml b/.github/workflows/package.yml index 399c44dd3..652add69a 100644 --- a/.github/workflows/package.yml +++ b/.github/workflows/package.yml @@ -322,3 +322,27 @@ jobs: name: msi-${{ matrix.arch }} path: artifacts/ if-no-files-found: error + docker: + name: Docker Build + runs-on: ubuntu-latest + needs: build + steps: + - uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push + uses: docker/build-push-action@v5 + with: + push: true + tags: | + ghcr.io/${{ github.repository }}:latest + ghcr.io/${{ github.repository }}:${{ github.sha }} \ No newline at end of file diff --git a/.gitignore b/.gitignore index 05386a8fd..fe36f504c 100644 --- a/.gitignore +++ b/.gitignore @@ -55,6 +55,5 @@ $RECYCLE.BIN/ *.lnk ### Custom... ### -Dockerfile lcov.info -*.pcap \ No newline at end of file +*.pcap diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..d99043c72 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,49 @@ +FROM rust:1.85-slim AS builder + +# Install sniffnet build dependencies +RUN apt-get update && apt-get install -y \ + libfreetype6-dev \ + libexpat1-dev \ + libpcap-dev \ + libasound2-dev \ + libfontconfig1-dev \ + libgtk-3-dev \ + pkg-config \ + && rm -rf /var/lib/apt/lists/* + +# Create a new empty shell project +WORKDIR /usr/src/sniffnet +COPY . . + +# Build for release +RUN cargo build --release + +# Runtime stage +FROM debian:bookworm-slim + +# Install runtime dependencies including Wayland +RUN apt-get update && apt-get install -y \ + libfreetype6 \ + libexpat1 \ + libpcap0.8 \ + libasound2 \ + libfontconfig1 \ + libgtk-3-0 \ + libwayland-client0 \ + libwayland-cursor0 \ + libwayland-egl1 \ + libxkbcommon0 \ + mesa-utils \ + libegl1 \ + libvulkan1 \ + && rm -rf /var/lib/apt/lists/* + +# Copy the built binary +COPY --from=builder /usr/src/sniffnet/target/release/sniffnet /usr/local/bin/sniffnet + +# Set environment variables for Wayland +ENV GDK_BACKEND=wayland +ENV WAYLAND_DISPLAY=$WAYLAND_DISPLAY +ENV XDG_RUNTIME_DIR=/tmp + +ENTRYPOINT ["sniffnet"] \ No newline at end of file From 47085a661cb51ae27ec122a70ddcb1ee1ab2eaeb Mon Sep 17 00:00:00 2001 From: Marco Cadetg Date: Sun, 23 Feb 2025 10:05:15 +0100 Subject: [PATCH 2/3] remove unnecessary libraries from docker image --- Dockerfile | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/Dockerfile b/Dockerfile index d99043c72..ad96da936 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM rust:1.85-slim AS builder -# Install sniffnet build dependencies +# Install build dependencies for both X11 and Wayland RUN apt-get update && apt-get install -y \ libfreetype6-dev \ libexpat1-dev \ @@ -11,17 +11,15 @@ RUN apt-get update && apt-get install -y \ pkg-config \ && rm -rf /var/lib/apt/lists/* -# Create a new empty shell project WORKDIR /usr/src/sniffnet COPY . . -# Build for release RUN cargo build --release # Runtime stage FROM debian:bookworm-slim -# Install runtime dependencies including Wayland +# Install runtime dependencies for both X11 and Wayland RUN apt-get update && apt-get install -y \ libfreetype6 \ libexpat1 \ @@ -29,21 +27,8 @@ RUN apt-get update && apt-get install -y \ libasound2 \ libfontconfig1 \ libgtk-3-0 \ - libwayland-client0 \ - libwayland-cursor0 \ - libwayland-egl1 \ - libxkbcommon0 \ - mesa-utils \ - libegl1 \ - libvulkan1 \ && rm -rf /var/lib/apt/lists/* -# Copy the built binary COPY --from=builder /usr/src/sniffnet/target/release/sniffnet /usr/local/bin/sniffnet -# Set environment variables for Wayland -ENV GDK_BACKEND=wayland -ENV WAYLAND_DISPLAY=$WAYLAND_DISPLAY -ENV XDG_RUNTIME_DIR=/tmp - -ENTRYPOINT ["sniffnet"] \ No newline at end of file +ENTRYPOINT ["sniffnet"] From 0be0dfdf178124b32af3593b893c9aaad594d7f4 Mon Sep 17 00:00:00 2001 From: Marco Cadetg Date: Sun, 23 Feb 2025 14:29:57 +0100 Subject: [PATCH 3/3] use qemu to build multiarch docker images --- .github/workflows/package.yml | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/.github/workflows/package.yml b/.github/workflows/package.yml index 652add69a..29bfe619d 100644 --- a/.github/workflows/package.yml +++ b/.github/workflows/package.yml @@ -327,22 +327,28 @@ jobs: runs-on: ubuntu-latest needs: build steps: - - uses: actions/checkout@v4 - + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - + - name: Login to GitHub Container Registry uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - + - name: Build and push uses: docker/build-push-action@v5 with: + context: . + platforms: linux/amd64,linux/arm64,linux/386,linux/arm/v7 push: true tags: | ghcr.io/${{ github.repository }}:latest - ghcr.io/${{ github.repository }}:${{ github.sha }} \ No newline at end of file + ghcr.io/${{ github.repository }}:${{ github.sha }}