# Stage 1: Build Piston from source FROM rust:1.72 as builder # Install build dependencies RUN apt-get update && apt-get install -y git pkg-config libssl-dev # Clone Piston repo WORKDIR /app RUN git clone https://github.com/engineer-man/piston.git . # Move into the correct directory (engine/) WORKDIR /app/engine # Build the API binary RUN cargo build --release # Stage 2: Runtime image FROM debian:bullseye-slim # Install Docker CLI (used by Piston to run sandboxed code) RUN apt-get update && \ apt-get install -y curl gnupg lsb-release && \ curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg && \ echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null && \ apt-get update && apt-get install -y docker-ce-cli # Working directory WORKDIR /app # Copy compiled binary COPY --from=builder /app/engine/target/release/piston-api /usr/local/bin/piston # Copy Runtimes.toml (optional; may not exist in new layout) COPY --from=builder /app/engine/Runtimes.toml ./Runtimes.toml # Set Piston's port to 7860 ENV PORT=7860 EXPOSE 7860 # Start the server CMD ["piston"]