From 9c9dadba95820c0354f74d437fc60e1642cf104f Mon Sep 17 00:00:00 2001 From: SHAcollision Date: Mon, 23 Sep 2024 15:39:31 +0200 Subject: [PATCH 1/6] feat(server): add dockerfile --- .dockerignore | 3 +++ Dockerfile | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..0a5df56 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +/target +/docs +/.github \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..537c546 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,56 @@ +# ======================== +# Build Stage +# ======================== +FROM rust:1.81.0-alpine3.20 AS builder + +# Install build dependencies, including static OpenSSL libraries +RUN apk add --no-cache \ + musl-dev \ + openssl-dev \ + openssl-libs-static \ + pkgconfig \ + build-base \ + curl + +# Set environment variables for static linking with OpenSSL +ENV OPENSSL_STATIC=yes +ENV OPENSSL_LIB_DIR=/usr/lib +ENV OPENSSL_INCLUDE_DIR=/usr/include + +# Add the MUSL target for static linking +RUN rustup target add x86_64-unknown-linux-musl + +# Set the working directory +WORKDIR /usr/src/app + +# Copy over Cargo.toml and Cargo.lock for dependency caching +COPY Cargo.toml Cargo.lock ./ + +# Copy over all the source code +COPY . . + +# Build the project in release mode for the MUSL target +RUN cargo build --release --target x86_64-unknown-linux-musl + +# Strip the binary to reduce size +RUN strip target/x86_64-unknown-linux-musl/release/pkarr-server + +# ======================== +# Runtime Stage +# ======================== +FROM alpine:3.20 + +# Install runtime dependencies (only ca-certificates) +RUN apk add --no-cache ca-certificates + +# Copy the compiled binary from the builder stage +COPY --from=builder /usr/src/app/target/x86_64-unknown-linux-musl/release/pkarr-server /usr/local/bin/pkarr-server + +# Set the working directory +WORKDIR /usr/local/bin + +# Expose the port the pkarr server listens on (should match that of config.toml) +EXPOSE 6881 + +# Set the default command to run the homeserver binary +CMD ["pkarr-server", "--config=./config.toml"] From 9bbbc92d1b1cb12c71d172b77683921e9d3cd9d6 Mon Sep 17 00:00:00 2001 From: Miguel Medeiros Date: Mon, 4 Nov 2024 12:52:41 -0300 Subject: [PATCH 2/6] feat: add Dockerfile and update README for Docker setup --- Dockerfile | 29 +++++++++++++++++++++++++++++ README.md | 18 ++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..61fb2db --- /dev/null +++ b/Dockerfile @@ -0,0 +1,29 @@ +# Start with an official Rust image +FROM rust:latest as builder + +# Create a new directory for the project +WORKDIR /usr/src/pkarr-server + +# Copy the project files into the container +COPY . . + +# Build the project in release mode +RUN cargo build --release + +# Use an image with a compatible glibc version +FROM ubuntu:latest + +# Install necessary libraries +RUN apt-get update && apt-get install -y libssl-dev + +# Copy the binary from the builder stage +COPY --from=builder /usr/src/pkarr-server/target/release/pkarr-server /usr/local/bin/pkarr-server + +# Copy the example configuration file as config.toml if config.toml is not present +COPY --from=builder /usr/src/pkarr-server/server/src/config.example.toml /etc/pkarr/config.toml + +# Expose the necessary port (change according to your server settings) +EXPOSE 6881 + +# Run the server with the appropriate flags +CMD ["pkarr-server", "--config=/etc/pkarr/config.toml", "-t=pkarr=debug,tower_http=debug"] \ No newline at end of file diff --git a/README.md b/README.md index a0b6d14..0676798 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,21 @@ Try the [web app demo](https://app.pkarr.org). Or if you prefer Rust [Examples](./pkarr/examples) +## Docker Setup +To build and run the Pkarr server using Docker, follow these steps: + +1. **Build the Docker image**: +```bash +docker build -t pkarr-server . +``` + +2. Run the Docker container: +```bash +docker run -p 6881:6881 --name pkarr-server-container pkarr-server +``` + +This will make the Pkarr server accessible at http://localhost:6881. + ## TOC - [Architecture](#Architecture) - [Expectations](#Expectations) @@ -158,3 +173,6 @@ Open social networks often attempt to solve discovery natively within their netw - Their infrastructure would need to become a gossip overlay network, which may not be desirable. - Achieving consistency and load balancing would require further optimization, effectively reinventing a DHT. - If an overlay network is developed that surpasses the performance of a 10-million-node DHT with a 15-year track record, Pkarr should still be capable of utilizing your network as a backend, either as an alternative or alongside existing solutions. + +3. **How can I run the Pkarr server using Docker?** + To run the server with Docker, build the image and start the container using the instructions in the [Docker Setup](#docker-setup) section. From 0700fc3766acca74a26846f2c9cb8adaa873a9bb Mon Sep 17 00:00:00 2001 From: SHAcollision Date: Mon, 4 Nov 2024 17:43:38 +0100 Subject: [PATCH 3/6] Update readme docker --- README.md | 47 +++++++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 0676798..0794507 100644 --- a/README.md +++ b/README.md @@ -19,21 +19,6 @@ Try the [web app demo](https://app.pkarr.org). Or if you prefer Rust [Examples](./pkarr/examples) -## Docker Setup -To build and run the Pkarr server using Docker, follow these steps: - -1. **Build the Docker image**: -```bash -docker build -t pkarr-server . -``` - -2. Run the Docker container: -```bash -docker run -p 6881:6881 --name pkarr-server-container pkarr-server -``` - -This will make the Pkarr server accessible at http://localhost:6881. - ## TOC - [Architecture](#Architecture) - [Expectations](#Expectations) @@ -175,4 +160,34 @@ Open social networks often attempt to solve discovery natively within their netw - If an overlay network is developed that surpasses the performance of a 10-million-node DHT with a 15-year track record, Pkarr should still be capable of utilizing your network as a backend, either as an alternative or alongside existing solutions. 3. **How can I run the Pkarr server using Docker?** - To run the server with Docker, build the image and start the container using the instructions in the [Docker Setup](#docker-setup) section. +To build and run the Pkarr server using Docker, you can use a small `docker-compose.yml` such as: + +``` +services: + pkarr: + container_name: pkarr + build: + context: ./pkarr + volumes: + - ./config.toml:/config.toml + - .pkarr_cache:/cache + command: pkarr-server --config=/config.toml +``` +In the example above `.pkarr_cache` relative directory will be used to permanently store pkarr cached keys. + +An example `./config.toml` here (we are mounting it on the container) +``` +relay_port = 6881 +dht_port = 6881 +cache_path = "/cache" +cache_size = 1_000_000 +resolvers = [] +minimum_ttl = 300 +maximum_ttl = 86400 +[rate_limiter] +behind_proxy = false +per_second = 2 +burst_size = 10 +``` + +This will make the Pkarr server accessible at http://localhost:6881. \ No newline at end of file From b6adcab3ffd4f603bc0b4b758fda1b697b0befe4 Mon Sep 17 00:00:00 2001 From: SHAcollision Date: Mon, 4 Nov 2024 17:46:57 +0100 Subject: [PATCH 4/6] Fix example docker-compose --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 0794507..95df049 100644 --- a/README.md +++ b/README.md @@ -166,8 +166,7 @@ To build and run the Pkarr server using Docker, you can use a small `docker-comp services: pkarr: container_name: pkarr - build: - context: ./pkarr + build: . volumes: - ./config.toml:/config.toml - .pkarr_cache:/cache From 2d7a2a97411b9c9c0c4a7da8f50353ef48ca4493 Mon Sep 17 00:00:00 2001 From: SHAcollision Date: Tue, 5 Nov 2024 16:00:03 +0100 Subject: [PATCH 5/6] Move Docker documentation --- server/README.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/server/README.md b/server/README.md index 03498da..bc51165 100644 --- a/server/README.md +++ b/server/README.md @@ -28,3 +28,35 @@ You can customize logging levels ```bash ../target/release/pkarr-server --config=./config.toml -t=pkarr=debug,tower_http=debug ``` + +## Using Docker +To build and run the Pkarr server using Docker, this repository has a `Dockerfile` in the top level. You could use a small `docker-compose.yml` such as: + +``` +services: + pkarr: + container_name: pkarr + build: . + volumes: + - ./config.toml:/config.toml + - .pkarr_cache:/cache + command: pkarr-server --config=/config.toml +``` +Alternatively, lunch docker correctly attaching the `config.toml` as a volume in the right location. In the example above `.pkarr_cache` relative directory is used to permanently store pkarr cached keys. + +An example `./config.toml` here (we are mounting it on the container) +``` +relay_port = 6881 +dht_port = 6881 +cache_path = "/cache" +cache_size = 1_000_000 +resolvers = [] +minimum_ttl = 300 +maximum_ttl = 86400 +[rate_limiter] +behind_proxy = false +per_second = 2 +burst_size = 10 +``` + +This will make the Pkarr server accessible at http://localhost:6881. \ No newline at end of file From 6060460e2961d83f605a10d9c158e96a4d396200 Mon Sep 17 00:00:00 2001 From: Nuh Date: Tue, 5 Nov 2024 18:09:54 +0300 Subject: [PATCH 6/6] Update README.md remove docker instructions from root README.md --- README.md | 33 ++------------------------------- 1 file changed, 2 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 95df049..0b338fb 100644 --- a/README.md +++ b/README.md @@ -159,34 +159,5 @@ Open social networks often attempt to solve discovery natively within their netw - Achieving consistency and load balancing would require further optimization, effectively reinventing a DHT. - If an overlay network is developed that surpasses the performance of a 10-million-node DHT with a 15-year track record, Pkarr should still be capable of utilizing your network as a backend, either as an alternative or alongside existing solutions. -3. **How can I run the Pkarr server using Docker?** -To build and run the Pkarr server using Docker, you can use a small `docker-compose.yml` such as: - -``` -services: - pkarr: - container_name: pkarr - build: . - volumes: - - ./config.toml:/config.toml - - .pkarr_cache:/cache - command: pkarr-server --config=/config.toml -``` -In the example above `.pkarr_cache` relative directory will be used to permanently store pkarr cached keys. - -An example `./config.toml` here (we are mounting it on the container) -``` -relay_port = 6881 -dht_port = 6881 -cache_path = "/cache" -cache_size = 1_000_000 -resolvers = [] -minimum_ttl = 300 -maximum_ttl = 86400 -[rate_limiter] -behind_proxy = false -per_second = 2 -burst_size = 10 -``` - -This will make the Pkarr server accessible at http://localhost:6881. \ No newline at end of file +3. **How can I run the Pkarr server?** +You can find building instruction [here](./server/README.md).