-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
172 lines (136 loc) · 4.52 KB
/
Dockerfile
File metadata and controls
172 lines (136 loc) · 4.52 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
# RTF Infrastructure - Multi-stage Docker Build
# Optimized for production deployment with security and performance
# ===== BUILD STAGE =====
FROM rust:1.70-slim as builder
# Install system dependencies
RUN apt-get update && apt-get install -y \
pkg-config \
libssl-dev \
libpq-dev \
build-essential \
curl \
git \
&& rm -rf /var/lib/apt/lists/*
# Set working directory
WORKDIR /app
# Copy dependency files first for better caching
COPY Cargo.toml Cargo.lock ./
COPY backend/*/Cargo.toml ./backend/
COPY utils/*/Cargo.toml ./utils/
COPY infrastructure/*/Cargo.toml ./infrastructure/
# Create dummy source files to build dependencies
RUN mkdir -p backend/api/src \
backend/bridge-defense/src \
backend/compliance/src \
backend/cross-chain/src \
backend/emergency-handler/src \
backend/esg-compliance/src \
backend/exposure-detector/src \
backend/governance/src \
backend/llm-agent/src \
backend/metrics/src \
backend/monitoring/src \
backend/oracle/src \
backend/treasury/src \
backend/zk-nav/src \
utils/crypto/src \
utils/post-quantum/src \
utils/zk-proofs/src \
infrastructure/deployment/src \
infrastructure/monitoring/src
# Create dummy main.rs files
RUN echo "fn main() {}" > backend/api/src/main.rs
RUN echo "fn main() {}" > backend/bridge-defense/src/lib.rs
RUN echo "fn main() {}" > backend/compliance/src/lib.rs
RUN echo "fn main() {}" > backend/cross-chain/src/lib.rs
RUN echo "fn main() {}" > backend/emergency-handler/src/lib.rs
RUN echo "fn main() {}" > backend/esg-compliance/src/lib.rs
RUN echo "fn main() {}" > backend/exposure-detector/src/lib.rs
RUN echo "fn main() {}" > backend/governance/src/lib.rs
RUN echo "fn main() {}" > backend/llm-agent/src/lib.rs
RUN echo "fn main() {}" > backend/metrics/src/lib.rs
RUN echo "fn main() {}" > backend/monitoring/src/lib.rs
RUN echo "fn main() {}" > backend/oracle/src/lib.rs
RUN echo "fn main() {}" > backend/treasury/src/lib.rs
RUN echo "fn main() {}" > backend/zk-nav/src/lib.rs
RUN echo "fn main() {}" > utils/crypto/src/lib.rs
RUN echo "fn main() {}" > utils/post-quantum/src/lib.rs
RUN echo "fn main() {}" > utils/zk-proofs/src/lib.rs
RUN echo "fn main() {}" > infrastructure/deployment/src/lib.rs
RUN echo "fn main() {}" > infrastructure/monitoring/src/lib.rs
# Build dependencies (this layer will be cached)
RUN cargo build --release --workspace
RUN rm -rf backend/*/src utils/*/src infrastructure/*/src
# Copy actual source code
COPY backend/ ./backend/
COPY utils/ ./utils/
COPY infrastructure/ ./infrastructure/
COPY config/ ./config/
# Build the actual application
RUN cargo build --release --workspace
# ===== RUNTIME STAGE =====
FROM debian:bookworm-slim as runtime
# Install runtime dependencies
RUN apt-get update && apt-get install -y \
ca-certificates \
libssl3 \
libpq5 \
curl \
&& rm -rf /var/lib/apt/lists/*
# Create non-root user for security
RUN groupadd -r rtf && useradd -r -g rtf rtf
# Set working directory
WORKDIR /app
# Copy built binaries from builder stage
COPY --from=builder /app/target/release/rtf-* ./bin/
COPY --from=builder /app/config/ ./config/
# Copy scripts
COPY scripts/ ./scripts/
RUN chmod +x scripts/*.sh
# Create necessary directories
RUN mkdir -p logs data tmp \
&& chown -R rtf:rtf /app
# Switch to non-root user
USER rtf
# Expose ports
EXPOSE 8000 8001 8002 9090
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8000/health || exit 1
# Default command
CMD ["./bin/rtf-api"]
# ===== DEVELOPMENT STAGE =====
FROM builder as development
# Install additional development tools
RUN cargo install cargo-watch cargo-audit cargo-tarpaulin
# Copy source code
COPY . .
# Set development environment
ENV RUST_LOG=debug
ENV ENVIRONMENT=development
# Expose additional ports for development
EXPOSE 8000 8001 8002 9090 9091
# Development command with hot reload
CMD ["cargo", "watch", "-x", "run"]
# ===== TESTING STAGE =====
FROM builder as testing
# Copy test files
COPY tests/ ./tests/
# Run tests
RUN cargo test --release --workspace
# Run security audit
RUN cargo audit
# Generate coverage report
RUN cargo tarpaulin --all-features --workspace --timeout 120
# ===== PRODUCTION STAGE =====
FROM runtime as production
# Production-specific configurations
ENV RUST_LOG=info
ENV ENVIRONMENT=production
# Copy production configuration
COPY config/production.toml ./config/
# Set resource limits
USER rtf
WORKDIR /app
# Production command
CMD ["./bin/rtf-api", "--config", "config/production.toml"]