-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
173 lines (133 loc) · 4.41 KB
/
Copy pathDockerfile
File metadata and controls
173 lines (133 loc) · 4.41 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
# Machinery - Continuous Individual Health Modeling Framework
# Multi-stage Dockerfile for development and production
# Development stage with all tools
FROM rust:1.75-slim as development
# Install system dependencies for development
RUN apt-get update && apt-get install -y \
pkg-config \
libssl-dev \
libpq-dev \
libsqlite3-dev \
build-essential \
curl \
git \
postgresql-client \
redis-tools \
valgrind \
perf-tools-unstable \
&& rm -rf /var/lib/apt/lists/*
# Install additional Rust tools for development
RUN cargo install cargo-watch cargo-audit cargo-tarpaulin cargo-flamegraph
# Set working directory
WORKDIR /workspace
# Copy workspace configuration
COPY rust-toolchain.toml ./
COPY Cargo.toml ./
COPY Cargo.lock ./
# Create workspace structure
RUN mkdir -p src crates/{orchestrator,seke-engine,data-collectors,prediction,modeling,validation,patterns}
# Copy source code
COPY . .
# Development command
CMD ["cargo", "build"]
# Build stage
FROM rust:1.75-slim as builder
# Install build dependencies
RUN apt-get update && apt-get install -y \
pkg-config \
libssl-dev \
libpq-dev \
libsqlite3-dev \
build-essential \
&& rm -rf /var/lib/apt/lists/*
# Create app user for security
RUN useradd -m -u 1001 machinery
# Set working directory
WORKDIR /app
# Copy workspace configuration first for better caching
COPY rust-toolchain.toml ./
COPY Cargo.toml ./
COPY Cargo.lock ./
# Create dummy source files to cache dependencies
RUN mkdir -p src/bin crates/{orchestrator,seke-engine,data-collectors,prediction,modeling,validation,patterns}/src
RUN echo "fn main() {}" > src/main.rs
RUN echo "fn main() {}" > src/bin/orchestrator.rs
RUN echo "fn main() {}" > src/bin/setup.rs
RUN echo "fn main() {}" > src/bin/cli.rs
# Create dummy Cargo.toml files for workspace crates
RUN for crate in orchestrator seke-engine data-collectors prediction modeling validation patterns; do \
echo '[package]' > crates/$crate/Cargo.toml && \
echo "name = \"machinery-$crate\"" >> crates/$crate/Cargo.toml && \
echo 'version = "0.1.0"' >> crates/$crate/Cargo.toml && \
echo 'edition = "2021"' >> crates/$crate/Cargo.toml && \
echo '[dependencies]' >> crates/$crate/Cargo.toml && \
echo 'pub fn dummy() {}' > crates/$crate/src/lib.rs; \
done
# Build dependencies (this layer will be cached)
RUN cargo build --release --bins
RUN rm -rf src crates
# Copy actual source code
COPY src ./src
COPY crates ./crates
# Build the actual application
RUN cargo build --release --bins
# 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 app user
RUN useradd -m -u 1001 machinery
# Create necessary directories
RUN mkdir -p /app/{data,logs,models,scripts,seke_cache} && \
chown -R machinery:machinery /app
# Copy binaries from builder stage
COPY --from=builder /app/target/release/machinery-orchestrator /usr/local/bin/
COPY --from=builder /app/target/release/machinery-setup /usr/local/bin/
COPY --from=builder /app/target/release/machinery-cli /usr/local/bin/
# Copy configuration files
COPY machinery.toml /app/
COPY scripts/ /app/scripts/
# Set permissions
RUN chmod +x /usr/local/bin/machinery-*
RUN chown -R machinery:machinery /app
# Switch to app user
USER machinery
# Set working directory
WORKDIR /app
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
CMD curl -f http://localhost:8080/health || exit 1
# Expose ports
EXPOSE 8080 9090
# Default command
CMD ["machinery-orchestrator", "--config", "/app/machinery.toml"]
# Production stage with additional optimizations
FROM runtime as production
# Copy production configuration
COPY machinery.production.toml /app/machinery.toml
# Set production environment variables
ENV RUST_LOG=info
ENV MACHINERY_ENV=production
# Use production command
CMD ["machinery-orchestrator", "--config", "/app/machinery.toml", "--production"]
# Minimal stage for CI/testing
FROM rust:1.75-slim as ci
# Install minimal dependencies for CI
RUN apt-get update && apt-get install -y \
pkg-config \
libssl-dev \
libpq-dev \
build-essential \
&& rm -rf /var/lib/apt/lists/*
# Install CI tools
RUN cargo install cargo-audit cargo-tarpaulin
WORKDIR /workspace
# Copy source
COPY . .
# Default CI command
CMD ["cargo", "test", "--workspace"]