-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathDockerfile
More file actions
196 lines (158 loc) · 6.19 KB
/
Dockerfile
File metadata and controls
196 lines (158 loc) · 6.19 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# Multi-stage Dockerfile for production builds
# Based on generative-protein-binder-design Docker patterns
# Supports multi-architecture builds (amd64, arm64)
ARG PYTHON_VERSION=3.12
ARG BUILD_TYPE=production
ARG TARGETPLATFORM
ARG BUILDPLATFORM
# Base stage with Python and system dependencies
FROM python:${PYTHON_VERSION}-slim-bookworm AS base
# Platform information for debugging
RUN echo "Building on $BUILDPLATFORM, targeting $TARGETPLATFORM"
# Set environment variables
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1 \
DEBIAN_FRONTEND=noninteractive
# Install system dependencies including Go for building from source
RUN apt-get update && apt-get install -y \
build-essential \
git \
curl \
wget \
ca-certificates \
gnupg2 \
software-properties-common \
golang-go \
make \
pkg-config \
hwloc \
libhwloc-dev \
mesa-opencl-icd \
ocl-icd-opencl-dev \
&& rm -rf /var/lib/apt/lists/*
# Create non-root user and home directory with proper ownership
RUN groupadd -r appuser && useradd -r -g appuser -d /home/appuser -m appuser \
&& mkdir -p /app /home/appuser/.cache /home/appuser/.local \
&& chown -R appuser:appuser /app /home/appuser \
&& chmod -R 0777 /home/appuser
# Ensure HOME points to a writable directory for pip and other tools
ENV HOME=/home/appuser \
PIP_CACHE_DIR=/home/appuser/.cache/pip \
PATH=/home/appuser/.local/bin:$PATH
WORKDIR /app
# Development stage
FROM base AS development
ENV DEVELOPMENT=1
# Install development dependencies
RUN apt-get update && apt-get install -y \
vim \
nano \
tree \
htop \
strace \
gdb \
valgrind \
&& rm -rf /var/lib/apt/lists/*
# Install Python development tools
RUN pip install --upgrade pip setuptools wheel
# Copy source code
COPY --chown=appuser:appuser . .
# Install package in editable mode with development/test tools and common runtime extras
RUN pip install -e ".[dev,api,webrtc,arrow]"
USER appuser
ENV HOME=/home/appuser
EXPOSE 8000 5678
CMD ["python", "-m", "ipfs_kit_py"]
# Testing stage
FROM development AS testing
ENV TESTING=1
# Install testing dependencies are provided by dev/test extras in previous stage
# Run tests by default from the tests directory
# Exclude tests with import errors (empty/incomplete modules)
CMD ["pytest", "--verbose", "--cov=ipfs_kit_py", "--ignore=tests/test_mcp_restoration.py", "--ignore=tests/test_merged_dashboard.py", "--ignore=tests/test_mock_format.py", "--ignore=tests/test_modern_bridge.py", "--ignore=tests/test_modernized_dashboard.py", "--ignore=tests/test_unified_bucket_api.py", "--ignore=tests/test_websocket.py", "-k", "not integration", "-x", "tests/"]
# Production build stage
FROM base AS builder
# Install build dependencies as root (we're still root in base stage)
RUN pip install --upgrade pip setuptools wheel build
# Copy source files
COPY . /app/src/
WORKDIR /app/src
# Build wheel
RUN python -m build --wheel
# Production stage
FROM base AS production
ENV BUILD_TYPE=production
# Copy wheel from builder and install as root before switching users
COPY --from=builder /app/src/dist/*.whl /tmp/
# Install package with API support for daemon functionality
# Install as root to ensure system-wide availability
# Skip problematic binary dependencies that may fail on some architectures
RUN pip install --upgrade pip setuptools wheel && \
WHEEL_FILE=$(find /tmp -name "*.whl" | head -1) && \
pip install "${WHEEL_FILE}[api]" || \
(echo "Full installation failed, trying minimal install..." && pip install "${WHEEL_FILE}") && \
rm -rf /tmp/*.whl && \
python -c "import ipfs_kit_py; print('IPFS Kit installed successfully')"
# Create necessary directories
RUN mkdir -p /app/data /app/logs /app/config /app/scripts && \
chown -R appuser:appuser /app
# Copy config files if they exist
# Copy config files from build context (directory exists in repo)
COPY --chown=appuser:appuser config/ /app/config/
# Copy dependency checker and entrypoint scripts
COPY --chown=appuser:appuser scripts/check_and_install_dependencies.py /app/scripts/
COPY --chown=appuser:appuser scripts/docker_entrypoint.sh /app/scripts/
RUN chmod +x /app/scripts/docker_entrypoint.sh
USER appuser
ENV HOME=/home/appuser
WORKDIR /app
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
CMD python -c "import ipfs_kit_py; print('OK')" || exit 1
EXPOSE 8000
# Use entrypoint script for proper initialization
ENTRYPOINT ["/app/scripts/docker_entrypoint.sh"]
CMD ["python", "-m", "ipfs_kit_py"]
# Documentation stage
FROM base AS documentation
# Install documentation dependencies
RUN apt-get update && apt-get install -y \
pandoc \
texlive-latex-base \
texlive-latex-extra \
&& rm -rf /var/lib/apt/lists/*
# Install Python documentation tools
RUN pip install mkdocs mkdocs-material mkdocstrings[python] \
mkdocs-jupyter mkdocs-mermaid2-plugin
COPY --chown=appuser:appuser docs/ /app/docs/
# Create default mkdocs.yml if it doesn't exist in the repo
RUN if [ ! -f mkdocs.yml ]; then \
echo "site_name: IPFS Kit Python" > mkdocs.yml && \
echo "site_description: Python toolkit for IPFS operations" >> mkdocs.yml && \
echo "site_url: https://ipfs-kit-py.readthedocs.io/" >> mkdocs.yml && \
echo "" >> mkdocs.yml && \
echo "theme:" >> mkdocs.yml && \
echo " name: material" >> mkdocs.yml && \
echo "" >> mkdocs.yml && \
echo "plugins:" >> mkdocs.yml && \
echo " - search" >> mkdocs.yml && \
echo " - mkdocstrings:" >> mkdocs.yml && \
echo " handlers:" >> mkdocs.yml && \
echo " python:" >> mkdocs.yml && \
echo " options:" >> mkdocs.yml && \
echo " show_source: true" >> mkdocs.yml && \
echo "" >> mkdocs.yml && \
echo "nav:" >> mkdocs.yml && \
echo " - Home: index.md" >> mkdocs.yml && \
echo " - API Reference: reference/" >> mkdocs.yml; \
fi
COPY --chown=appuser:appuser . /app/src/
# Install package for documentation
RUN pip install -e /app/src/
USER appuser
ENV HOME=/home/appuser
WORKDIR /app
EXPOSE 8080
CMD ["mkdocs", "serve", "--dev-addr", "0.0.0.0:8080"]