update sth at 2025-10-12 18:10:40
Browse files- Dockerfile +35 -9
- Dockerfile.simple +41 -0
- README.md +29 -1
Dockerfile
CHANGED
|
@@ -1,13 +1,39 @@
|
|
| 1 |
-
#
|
| 2 |
-
FROM rust:1.90-alpine
|
| 3 |
|
| 4 |
-
# Install build
|
| 5 |
RUN apk add --no-cache \
|
| 6 |
musl-dev \
|
| 7 |
pkgconfig \
|
| 8 |
openssl-dev \
|
| 9 |
-
openssl-libs-static
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
# Create app user
|
| 13 |
RUN addgroup -g 1001 -S appgroup && \
|
|
@@ -16,8 +42,8 @@ RUN addgroup -g 1001 -S appgroup && \
|
|
| 16 |
# Set working directory
|
| 17 |
WORKDIR /app
|
| 18 |
|
| 19 |
-
# Copy
|
| 20 |
-
COPY
|
| 21 |
|
| 22 |
# Change ownership to app user
|
| 23 |
RUN chown -R appuser:appgroup /app
|
|
@@ -33,5 +59,5 @@ ENV RUST_LOG=info
|
|
| 33 |
ENV API_HOST=0.0.0.0
|
| 34 |
ENV API_PORT=7860
|
| 35 |
|
| 36 |
-
# Run the application
|
| 37 |
-
CMD ["
|
|
|
|
| 1 |
+
# Multi-stage build to reduce final image size and handle permissions properly
|
| 2 |
+
FROM rust:1.90-alpine AS builder
|
| 3 |
|
| 4 |
+
# Install build dependencies
|
| 5 |
RUN apk add --no-cache \
|
| 6 |
musl-dev \
|
| 7 |
pkgconfig \
|
| 8 |
openssl-dev \
|
| 9 |
+
openssl-libs-static
|
| 10 |
+
|
| 11 |
+
# Set working directory
|
| 12 |
+
WORKDIR /app
|
| 13 |
+
|
| 14 |
+
# Copy manifest files first for better caching
|
| 15 |
+
COPY Cargo.toml Cargo.lock ./
|
| 16 |
+
|
| 17 |
+
# Create dummy main file to cache dependencies
|
| 18 |
+
RUN mkdir src && echo "fn main() {}" > src/main.rs
|
| 19 |
+
|
| 20 |
+
# Build dependencies (this step will be cached if dependencies don't change)
|
| 21 |
+
RUN cargo build --release --bin api_server
|
| 22 |
+
RUN rm -rf src
|
| 23 |
+
|
| 24 |
+
# Copy actual source code
|
| 25 |
+
COPY src ./src
|
| 26 |
+
|
| 27 |
+
# Build the application
|
| 28 |
+
RUN touch src/main.rs && cargo build --release --bin api_server
|
| 29 |
+
|
| 30 |
+
# Final runtime stage
|
| 31 |
+
FROM alpine:3.20
|
| 32 |
+
|
| 33 |
+
# Install runtime dependencies
|
| 34 |
+
RUN apk add --no-cache \
|
| 35 |
+
ca-certificates \
|
| 36 |
+
openssl-libs-static
|
| 37 |
|
| 38 |
# Create app user
|
| 39 |
RUN addgroup -g 1001 -S appgroup && \
|
|
|
|
| 42 |
# Set working directory
|
| 43 |
WORKDIR /app
|
| 44 |
|
| 45 |
+
# Copy the binary from builder stage
|
| 46 |
+
COPY --from=builder /app/target/release/api_server .
|
| 47 |
|
| 48 |
# Change ownership to app user
|
| 49 |
RUN chown -R appuser:appgroup /app
|
|
|
|
| 59 |
ENV API_HOST=0.0.0.0
|
| 60 |
ENV API_PORT=7860
|
| 61 |
|
| 62 |
+
# Run the application directly from binary
|
| 63 |
+
CMD ["./api_server", "--no-proxy"]
|
Dockerfile.simple
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Use rust image with all tools included
|
| 2 |
+
FROM rust:1.90-alpine
|
| 3 |
+
|
| 4 |
+
# Install build and runtime dependencies
|
| 5 |
+
RUN apk add --no-cache \
|
| 6 |
+
musl-dev \
|
| 7 |
+
pkgconfig \
|
| 8 |
+
openssl-dev \
|
| 9 |
+
openssl-libs-static \
|
| 10 |
+
ca-certificates
|
| 11 |
+
|
| 12 |
+
# Create app user
|
| 13 |
+
RUN addgroup -g 1001 -S appgroup && \
|
| 14 |
+
adduser -S appuser -u 1001 -G appgroup
|
| 15 |
+
|
| 16 |
+
# Set working directory
|
| 17 |
+
WORKDIR /app
|
| 18 |
+
|
| 19 |
+
# Copy source code
|
| 20 |
+
COPY . .
|
| 21 |
+
|
| 22 |
+
# Change ownership to app user before building
|
| 23 |
+
RUN chown -R appuser:appgroup /app
|
| 24 |
+
|
| 25 |
+
# Switch to non-root user
|
| 26 |
+
USER appuser
|
| 27 |
+
|
| 28 |
+
# Set environment variables for proper Rust compilation
|
| 29 |
+
ENV CARGO_TARGET_DIR=/app/target
|
| 30 |
+
ENV CARGO_HOME=/app/.cargo
|
| 31 |
+
|
| 32 |
+
# Expose the default port
|
| 33 |
+
EXPOSE 7860
|
| 34 |
+
|
| 35 |
+
# Set environment variables
|
| 36 |
+
ENV RUST_LOG=info
|
| 37 |
+
ENV API_HOST=0.0.0.0
|
| 38 |
+
ENV API_PORT=7860
|
| 39 |
+
|
| 40 |
+
# Run the application using cargo run
|
| 41 |
+
CMD ["cargo", "run", "--bin", "api_server", "--", "--no-proxy"]
|
README.md
CHANGED
|
@@ -7,4 +7,32 @@ sdk: docker
|
|
| 7 |
pinned: false
|
| 8 |
---
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
pinned: false
|
| 8 |
---
|
| 9 |
|
| 10 |
+
# ChatGPT Rust Client
|
| 11 |
+
|
| 12 |
+
A reverse-engineered ChatGPT client written in Rust, deployed on Hugging Face Spaces.
|
| 13 |
+
|
| 14 |
+
## Features
|
| 15 |
+
|
| 16 |
+
- ChatGPT API client implementation
|
| 17 |
+
- WebSocket streaming support
|
| 18 |
+
- REST API server
|
| 19 |
+
- Image processing capabilities
|
| 20 |
+
- Docker-based deployment
|
| 21 |
+
|
| 22 |
+
## Deployment
|
| 23 |
+
|
| 24 |
+
This Space uses Docker to build and run the Rust application. The multi-stage build process ensures:
|
| 25 |
+
|
| 26 |
+
1. Proper dependency caching
|
| 27 |
+
2. Permission handling for Hugging Face Spaces
|
| 28 |
+
3. Optimized final image size
|
| 29 |
+
|
| 30 |
+
## Environment Variables
|
| 31 |
+
|
| 32 |
+
- `RUST_LOG`: Logging level (default: info)
|
| 33 |
+
- `API_HOST`: Server host (default: 0.0.0.0)
|
| 34 |
+
- `API_PORT`: Server port (default: 7860)
|
| 35 |
+
|
| 36 |
+
## Usage
|
| 37 |
+
|
| 38 |
+
The application runs automatically on Space startup and provides an API endpoint at the configured port.
|