File size: 1,807 Bytes
b198f8a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# Stage 1: Build dependencies & application
FROM rust:1.94-slim-bookworm AS builder
USER root

# Install system dependencies required for compiling Rust libraries (like openssl, cmake, etc.)
RUN apt-get update \
    && apt-get install -y --no-install-recommends pkg-config libssl-dev cmake g++ ca-certificates \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /app

# Copy dependency manifests first
COPY Cargo.toml Cargo.lock ./

# Create dummy source files so we can cache dependency compilation
RUN mkdir -p src \
    && echo "" > src/lib.rs \
    && echo "fn main() {}" > src/main.rs

# Build dependencies in release mode (caching layer)
RUN cargo build --release

# Copy the real source code
COPY . .

# Touch source files to ensure cargo compiles them with the real contents
RUN touch src/lib.rs src/main.rs

# Set SQLx offline compilation mode so we don't need a database connection at compile time
ENV SQLX_OFFLINE=true

# Recompile the actual application
RUN cargo build --release --bin rtix


# Stage 2: Minimal Runtime
FROM debian:bookworm-slim AS runtime

# Install runtime SSL dependencies and curl for health check
RUN apt-get update \
    && apt-get install -y --no-install-recommends libssl3 ca-certificates curl \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /app

# Copy the compiled binary from builder
COPY --from=builder /app/target/release/rtix /usr/local/bin/rtix

# Hugging Face Spaces requires port 7860
ENV PORT=7860
ENV SERVER_PORT=7860
# OAuth defaults (override with HF Secrets in Space settings)
ENV OAUTH_REDIRECT_BASE=https://gowtham851-rtix.hf.space
ENV FRONTEND_URL=https://rtix.vercel.app
ENV CLOUD_ENV=true
EXPOSE 7860

HEALTHCHECK --interval=30s --timeout=5s --start-period=20s --retries=3 \
  CMD curl -fsS "http://127.0.0.1:7860/health" > /dev/null || exit 1

CMD ["rtix"]