-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile.python
More file actions
74 lines (58 loc) · 2.3 KB
/
Dockerfile.python
File metadata and controls
74 lines (58 loc) · 2.3 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
# Ultra-lightweight build using python:3.13-slim
# This Dockerfile provides native Python 3.13 support for rshioaji with PyO3 bridge
# Image size: ~180MB with shioaji[speed] integration
FROM python:3.13-slim as builder
# Install Rust and build dependencies for PyO3 bridge
# Using python:3.13-slim as base ensures Python 3.13 headers are available
RUN apt-get update && apt-get install -y \
curl \
pkg-config \
libssl-dev \
build-essential \
&& rm -rf /var/lib/apt/lists/* \
&& curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y \
&& . $HOME/.cargo/env
# Install shioaji[speed] for PyO3 bridge integration
RUN pip install --no-cache-dir "shioaji[speed]"
WORKDIR /app
# Copy source code
COPY Cargo.toml build.rs ./
COPY src/ ./src/
COPY lib/ ./lib/
# Set environment for Linux x86_64 platform and Rust PATH
# RSHIOAJI_PLATFORM ensures correct .so file selection at runtime
ENV RSHIOAJI_PLATFORM=manylinux_x86_64
ENV PATH="/root/.cargo/bin:${PATH}"
# Force target platform for cross-compilation compatibility
ENV CARGO_CFG_TARGET_OS=linux
ENV CARGO_CFG_TARGET_ARCH=x86_64
# Build with speed and static-link features
RUN cargo build --release --features "static-link,speed"
# Verify binary works
RUN ./target/release/rshioaji-cli --help
# Final runtime image - Python 3.13 slim (~180MB total with shioaji[speed])
FROM python:3.13-slim
# Install only essential runtime dependencies
# Minimal footprint while maintaining Python 3.13 compatibility
RUN apt-get update && apt-get install -y \
ca-certificates \
&& rm -rf /var/lib/apt/lists/* \
&& groupadd -r rshioaji && useradd -r -g rshioaji rshioaji
# Install shioaji[speed] for runtime PyO3 bridge
RUN pip install --no-cache-dir "shioaji[speed]"
WORKDIR /app
# Copy the binary and lib directory
# lib directory contains platform-specific .so files for shioaji
COPY --from=builder /app/target/release/rshioaji-cli /usr/local/bin/rshioaji
COPY --from=builder /app/lib /app/lib
# Set environment - Python 3.13 compatible
# Runtime platform detection will use RSHIOAJI_PLATFORM override
ENV RSHIOAJI_PLATFORM=manylinux_x86_64
ENV PYTHON_VERSION=3.13
# Set permissions
RUN chown rshioaji:rshioaji /usr/local/bin/rshioaji && \
chmod +x /usr/local/bin/rshioaji
USER rshioaji
# Default command
ENTRYPOINT ["rshioaji"]
CMD ["--help"]