Files
OutFleet/Dockerfile

89 lines
2.2 KiB
Docker
Raw Normal View History

2025-10-27 09:53:37 +02:00
# Build stage with Rust
FROM rust:1.80-bookworm AS builder
2025-10-24 19:34:56 +03:00
2025-10-27 09:53:37 +02:00
WORKDIR /app
2025-10-27 09:46:39 +02:00
2025-10-27 09:53:37 +02:00
# Install system dependencies
2025-10-24 19:34:56 +03:00
RUN apt-get update && apt-get install -y \
pkg-config \
libssl-dev \
protobuf-compiler \
&& rm -rf /var/lib/apt/lists/*
2025-10-19 05:27:55 +03:00
# Build arguments
ARG GIT_COMMIT="development"
ARG GIT_COMMIT_SHORT="dev"
ARG BUILD_DATE="unknown"
ARG BRANCH_NAME="unknown"
ARG CARGO_VERSION="0.1.0"
# Environment variables from build args
ENV GIT_COMMIT=${GIT_COMMIT}
ENV GIT_COMMIT_SHORT=${GIT_COMMIT_SHORT}
ENV BUILD_DATE=${BUILD_DATE}
ENV BRANCH_NAME=${BRANCH_NAME}
ENV CARGO_VERSION=${CARGO_VERSION}
2025-10-27 09:53:37 +02:00
# Copy dependency files first for caching
COPY Cargo.toml Cargo.lock ./
# Create dummy source files to build dependencies
RUN mkdir -p src && \
echo "fn main() {}" > src/main.rs && \
echo "pub fn lib() {}" > src/lib.rs
# Build dependencies (this layer will be cached)
RUN cargo build --release && \
rm -rf src target/release/deps/xray_admin* target/release/xray-admin*
# Copy actual source code
COPY src ./src
COPY static ./static
2025-09-29 11:19:11 +01:00
2025-10-27 09:53:37 +02:00
# Build the application
2025-10-26 17:08:32 +02:00
RUN cargo build --release --locked
2025-09-29 11:19:11 +01:00
2025-10-27 09:53:37 +02:00
# Runtime stage - Ubuntu for glibc compatibility
2025-10-26 17:08:32 +02:00
FROM ubuntu:24.04 AS runtime
2025-09-29 11:19:11 +01:00
2025-10-19 05:27:55 +03:00
# Build arguments (needed for runtime stage)
ARG GIT_COMMIT="development"
ARG GIT_COMMIT_SHORT="dev"
ARG BUILD_DATE="unknown"
ARG BRANCH_NAME="unknown"
ARG CARGO_VERSION="0.1.0"
# Environment variables from build args
ENV GIT_COMMIT=${GIT_COMMIT}
ENV GIT_COMMIT_SHORT=${GIT_COMMIT_SHORT}
ENV BUILD_DATE=${BUILD_DATE}
ENV BRANCH_NAME=${BRANCH_NAME}
ENV CARGO_VERSION=${CARGO_VERSION}
2025-09-29 11:19:11 +01:00
WORKDIR /app
2025-10-24 19:34:56 +03:00
# Install minimal runtime dependencies
2025-09-29 11:19:11 +01:00
RUN apt-get update && apt-get install -y \
ca-certificates \
libssl3 \
2025-10-24 19:34:56 +03:00
libprotobuf32 \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean
2025-09-29 11:19:11 +01:00
# Copy the binary from builder
COPY --from=builder /app/target/release/xray-admin /app/xray-admin
# Copy static files
COPY --from=builder /app/static ./static
# Copy config file
COPY config.docker.toml ./config.toml
2025-10-24 19:34:56 +03:00
# Create non-root user for security
RUN groupadd -r outfleet && useradd -r -g outfleet -s /bin/false outfleet
RUN chown -R outfleet:outfleet /app
USER outfleet
2025-09-29 11:19:11 +01:00
EXPOSE 8081
2025-10-26 17:08:32 +02:00
CMD ["/app/xray-admin", "--host", "0.0.0.0"]