-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feat/dockerfile' into feat/dockerfile-new
- Loading branch information
Showing
2 changed files
with
50 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/target | ||
/docs | ||
/.github |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,56 @@ | ||
# 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 | ||
# ======================== | ||
# 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 | ||
RUN cargo build --release | ||
# 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 | ||
|
||
# Use an image with a compatible glibc version | ||
FROM ubuntu:latest | ||
# ======================== | ||
# Runtime Stage | ||
# ======================== | ||
FROM alpine:3.20 | ||
|
||
# Install necessary libraries | ||
RUN apt-get update && apt-get install -y libssl-dev | ||
# Install runtime dependencies (only ca-certificates) | ||
RUN apk add --no-cache ca-certificates | ||
|
||
# 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 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 | ||
|
||
# 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 | ||
# Set the working directory | ||
WORKDIR /usr/local/bin | ||
|
||
# Expose the necessary port (change according to your server settings) | ||
# Expose the port the pkarr server listens on (should match that of config.toml) | ||
EXPOSE 6881 | ||
|
||
# Run the server with the appropriate flags | ||
CMD ["pkarr-server", "--config=/etc/pkarr/config.toml", "-t=pkarr=debug,tower_http=debug"] | ||
# Set the default command to run the homeserver binary | ||
CMD ["pkarr-server", "--config=./config.toml"] |