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..d66c275 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,56 @@ +# ======================== +# Build Stage +# ======================== +FROM rust:1.82.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"] diff --git a/README.md b/README.md index a0b6d14..0b338fb 100644 --- a/README.md +++ b/README.md @@ -158,3 +158,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?** +You can find building instruction [here](./server/README.md). 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