-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.production
More file actions
121 lines (101 loc) · 4.63 KB
/
Copy pathDockerfile.production
File metadata and controls
121 lines (101 loc) · 4.63 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
# Production QNet Blockchain Node - Optimized Build
FROM rust:1.86-slim as builder
WORKDIR /build
# Install system dependencies for production build
RUN apt-get update && apt-get install -y \
build-essential \
cmake \
pkg-config \
libssl-dev \
libclang-dev \
git \
&& rm -rf /var/lib/apt/lists/*
# Optimized build environment for faster compilation
ENV CARGO_BUILD_JOBS=8
ENV CARGO_PROFILE_RELEASE_LTO=thin
ENV CARGO_PROFILE_RELEASE_PANIC=abort
ENV CARGO_PROFILE_RELEASE_CODEGEN_UNITS=1
# Production port configuration
ENV QNET_P2P_PORT=9876
ENV QNET_RPC_PORT=9877
ENV QNET_METRICS_PORT=9878
ENV DOCKER_ENV=1
# Copy dependency manifests first for better caching
COPY Cargo.toml ./Cargo.toml.original
COPY core/qnet-consensus/Cargo.toml ./core/qnet-consensus/
COPY core/qnet-core/Cargo.toml ./core/qnet-core/
COPY core/qnet-mempool/Cargo.toml ./core/qnet-mempool/
COPY core/qnet-state/Cargo.toml ./core/qnet-state/
COPY core/qnet-sharding/Cargo.toml ./core/qnet-sharding/
COPY development/qnet-integration/Cargo.toml ./development/qnet-integration/
# Create production workspace Cargo.toml without qnet-api (not needed for blockchain node)
RUN echo '[workspace]' > Cargo.toml && \
echo 'members = [' >> Cargo.toml && \
echo ' "core/qnet-core",' >> Cargo.toml && \
echo ' "core/qnet-consensus",' >> Cargo.toml && \
echo ' "core/qnet-mempool",' >> Cargo.toml && \
echo ' "core/qnet-state",' >> Cargo.toml && \
echo ' "core/qnet-sharding",' >> Cargo.toml && \
echo ' "development/qnet-integration"' >> Cargo.toml && \
echo ']' >> Cargo.toml && \
echo 'resolver = "2"' >> Cargo.toml && \
echo '' >> Cargo.toml && \
echo '[workspace.dependencies]' >> Cargo.toml && \
echo 'tokio = { version = "1.35", features = ["full"] }' >> Cargo.toml && \
echo 'serde = { version = "1.0.195", features = ["derive"] }' >> Cargo.toml && \
echo 'ed25519-dalek = { version = "2.0.0", features = ["std"] }' >> Cargo.toml
# Create dummy source files to cache dependencies
RUN mkdir -p core/qnet-consensus/src core/qnet-core/src core/qnet-mempool/src \
core/qnet-state/src core/qnet-sharding/src \
development/qnet-integration/src/bin development/qnet-integration/src \
development/qnet-integration/benches \
core/qnet-consensus/benches core/qnet-mempool/benches \
core/qnet-state/benches core/qnet-sharding/benches && \
echo "pub fn dummy() {}" > core/qnet-consensus/src/lib.rs && \
echo "pub fn dummy() {}" > core/qnet-core/src/lib.rs && \
echo "pub fn dummy() {}" > core/qnet-mempool/src/lib.rs && \
echo "pub fn dummy() {}" > core/qnet-state/src/lib.rs && \
echo "pub fn dummy() {}" > core/qnet-sharding/src/lib.rs && \
echo "pub fn dummy() {}" > development/qnet-integration/src/lib.rs && \
echo "fn main() {}" > development/qnet-integration/src/bin/qnet-node.rs && \
echo "fn main() {}" > core/qnet-consensus/benches/consensus_bench.rs && \
echo "fn main() {}" > core/qnet-mempool/benches/mempool_bench.rs && \
echo "fn main() {}" > core/qnet-state/benches/state_bench.rs && \
echo "fn main() {}" > core/qnet-sharding/benches/sharding_bench.rs && \
echo "fn main() {}" > development/qnet-integration/benches/poh_benchmark.rs && \
echo "fn main() {}" > development/qnet-integration/benches/full_benchmark.rs
# Removed qnet-api dummy files - not needed for production
# Build dependencies only (this layer gets cached!)
RUN cargo build --release --bin qnet-node --manifest-path development/qnet-integration/Cargo.toml
# Copy real source code
COPY . .
# Build final optimized binary
RUN cargo build --release --bin qnet-node --manifest-path development/qnet-integration/Cargo.toml
# Final production runtime image
FROM ubuntu:22.04
# Install production runtime dependencies
RUN apt-get update && apt-get install -y \
libssl3 \
curl \
ca-certificates \
netcat-openbsd \
htop \
&& rm -rf /var/lib/apt/lists/*
# Copy production binary FIRST (as root)
COPY --from=builder /build/target/release/qnet-node /usr/local/bin/qnet-node
# Set production permissions (as root)
RUN chmod +x /usr/local/bin/qnet-node
# Verify binary was copied successfully
RUN ls -la /usr/local/bin/qnet-node
# Create directories for production
RUN mkdir -p /app/{data,logs,config,node_data}
RUN chmod -R 755 /app
# Stay as root for now - for debugging
WORKDIR /app
# Production port exposure - QNet standard ports
EXPOSE 9876 9877 9878
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD curl -f http://localhost:${QNET_RPC_PORT}/health || exit 1
# Production entrypoint - Direct execution
ENTRYPOINT ["/usr/local/bin/qnet-node"]