Skip to content

Commit 055e1e7

Browse files
committed
makes docker build fast for local dev/testing
1 parent 53d80db commit 055e1e7

File tree

3 files changed

+214
-7
lines changed

3 files changed

+214
-7
lines changed

Dockerfile

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,19 @@ FROM rust:latest AS builder
44
# Set the working directory
55
WORKDIR /app
66

7+
RUN mkdir -p /app/build/target
8+
79
# Install sqlx-cli
810
RUN cargo install sqlx-cli
911

1012
# Copy the entire workspace
1113
COPY . .
1214

13-
# Build the project
14-
RUN cargo build --release
15+
RUN --mount=type=cache,target=/usr/local/cargo/registry \
16+
--mount=type=cache,target=/usr/local/cargo/git \
17+
--mount=type=cache,target=/app/target \
18+
cargo build --release && \
19+
cp -r /app/target /app/build
1520

1621
# Use a minimal base image for the final container
1722
FROM debian:bookworm-slim
@@ -24,11 +29,11 @@ RUN apt-get update && apt-get install -y \
2429
WORKDIR /app
2530

2631
# Copy the built binaries from the builder stage
27-
COPY --from=builder /app/target/release/server /app/server
28-
COPY --from=builder /app/target/release/chain_loader /app/chain_loader
29-
COPY --from=builder /app/target/release/dservice /app/dservice
30-
COPY --from=builder /app/target/release/dworker /app/dworker
31-
COPY --from=builder /app/target/release/prover /app/prover
32+
COPY --from=builder /app/build/target/release/server /app/server
33+
COPY --from=builder /app/build/target/release/chain_loader /app/chain_loader
34+
COPY --from=builder /app/build/target/release/dservice /app/dservice
35+
COPY --from=builder /app/build/target/release/dworker /app/dworker
36+
COPY --from=builder /app/build/target/release/prover /app/prover
3237

3338
# Copy the sqlx binary from the builder stage
3439
COPY --from=builder /usr/local/cargo/bin/sqlx /app/sqlx

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,31 @@ A tool to fetch blocks from rpc and save in local db for better performance duri
2020
## 2. Guide-level explanation
2121

2222
![basic arch](assets/arch_v2.png)
23+
24+
## Docker
25+
26+
Build
27+
28+
```bash
29+
docker build -t oreowallet .
30+
```
31+
32+
Run node:
33+
34+
```bash
35+
ironfish start -d ~/.ironfish-testnet --rpc.http --rpc.http.port 9092 --rpc.http.host 0.0.0.0
36+
```
37+
38+
Run
39+
40+
```bash
41+
DB_USER=postgres \
42+
DB_PASSWORD=postgres \
43+
DB_PORT=5444 \
44+
NODE_HOST=host.docker.internal \
45+
NODE_PORT=9092 \
46+
SECRET_KEY=a0882c5ac5e2fa771dde52b2d5639734a4411df14f4748c6f991a96e5dd9f997 \
47+
PUBLIC_KEY=03221b2a0ebd9d6798aadee2861a5307ced1a33d143f34c571a98ab4fa534b7d3e \
48+
SERVER_PORT=8080 \
49+
docker-compose up
50+
```

docker-compose.yml

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
version: '2.4'
2+
services:
3+
dbconfig:
4+
image: alpine:latest
5+
volumes:
6+
- conf:/app/conf # Mount the config directory on the host to the container
7+
command: |
8+
/bin/sh -c "echo 'host: postgres
9+
port: 5432
10+
user: ${DB_USER}
11+
password: ${DB_PASSWORD}
12+
dbname: oreowallet
13+
default_pool_size: 200
14+
protocol: \"postgres\"' > /app/conf/dbconfig"
15+
16+
postgres:
17+
image: postgres:latest
18+
environment:
19+
POSTGRES_USER: ${DB_USER}
20+
POSTGRES_PASSWORD: ${DB_PASSWORD}
21+
POSTGRES_DB: oreowallet
22+
ports:
23+
- "${DB_PORT}:5432"
24+
volumes:
25+
- postgres_data:/var/lib/postgresql/data
26+
networks:
27+
- oreowallet_network
28+
healthcheck:
29+
test: ["CMD-SHELL", "pg_isready -U ${DB_USER}"]
30+
interval: 10s
31+
timeout: 5s
32+
retries: 5
33+
34+
migration:
35+
image: "oreowallet"
36+
command: /bin/sh -c "./sqlx database create && ./sqlx migrate run"
37+
environment:
38+
- DATABASE_URL=postgres://${DB_USER}:${DB_PASSWORD}@postgres:5432/oreowallet
39+
networks:
40+
- oreowallet_network
41+
depends_on:
42+
- postgres
43+
- dbconfig
44+
logging:
45+
driver: "json-file"
46+
options:
47+
max-file: "4"
48+
max-size: "25m"
49+
50+
chainloader:
51+
restart: always
52+
image: "oreowallet"
53+
command: ./chain_loader --dbconfig /app/conf/dbconfig --node ${NODE_HOST}:${NODE_PORT} --verbosity ${VERBOSITY:-0}
54+
volumes:
55+
- conf:/app/conf
56+
depends_on:
57+
- migration
58+
networks:
59+
- oreowallet_network
60+
ulimits:
61+
core:
62+
hard: 0
63+
soft: 0
64+
logging:
65+
driver: "json-file"
66+
options:
67+
max-file: "4"
68+
max-size: "25m"
69+
70+
prover:
71+
restart: always
72+
image: "oreowallet"
73+
command: ./prover --verbosity ${VERBOSITY:-0}
74+
ports:
75+
- "10002:10002"
76+
depends_on:
77+
- migration
78+
- chainloader
79+
networks:
80+
- oreowallet_network
81+
ulimits:
82+
core:
83+
hard: 0
84+
soft: 0
85+
logging:
86+
driver: "json-file"
87+
options:
88+
max-file: "4"
89+
max-size: "25m"
90+
91+
server:
92+
restart: always
93+
image: "oreowallet"
94+
environment:
95+
- SECRET_KEY=${SECRET_KEY}
96+
- PUBLIC_KEY=${PUBLIC_KEY}
97+
command: |
98+
./server --listen 0.0.0.0:${SERVER_PORT} --dbconfig /app/conf/dbconfig --node ${NODE_HOST}:${NODE_PORT} --scan dservice:20001 --verbosity ${VERBOSITY:-0}
99+
ports:
100+
- "${SERVER_PORT}:${SERVER_PORT}"
101+
volumes:
102+
- conf:/app/conf
103+
depends_on:
104+
- migration
105+
- chainloader
106+
networks:
107+
- oreowallet_network
108+
ulimits:
109+
core:
110+
hard: 0
111+
soft: 0
112+
logging:
113+
driver: "json-file"
114+
options:
115+
max-file: "4"
116+
max-size: "25m"
117+
118+
dservice:
119+
restart: always
120+
image: "oreowallet"
121+
environment:
122+
- SECRET_KEY=${SECRET_KEY}
123+
- PUBLIC_KEY=${PUBLIC_KEY}
124+
command: ./dservice --dbconfig /app/conf/dbconfig --node ${NODE_HOST}:${NODE_PORT} --server server:${SERVER_PORT} --verbosity ${VERBOSITY:-0}
125+
ports:
126+
- "10001:10001"
127+
- "20001:20001"
128+
volumes:
129+
- conf:/app/conf
130+
depends_on:
131+
- migration
132+
- chainloader
133+
networks:
134+
oreowallet_network:
135+
ipv4_address: 172.19.0.10
136+
ulimits:
137+
core:
138+
hard: 0
139+
soft: 0
140+
logging:
141+
driver: "json-file"
142+
options:
143+
max-file: "4"
144+
max-size: "25m"
145+
146+
dworker:
147+
restart: always
148+
image: "oreowallet"
149+
command: ./dworker --address 172.19.0.10:10001 --verbosity ${VERBOSITY:-0}
150+
depends_on:
151+
- migration
152+
- chainloader
153+
networks:
154+
- oreowallet_network
155+
ulimits:
156+
core:
157+
hard: 0
158+
soft: 0
159+
logging:
160+
driver: "json-file"
161+
options:
162+
max-file: "4"
163+
max-size: "25m"
164+
165+
networks:
166+
oreowallet_network:
167+
driver: bridge
168+
ipam:
169+
config:
170+
- subnet: 172.19.0.0/16
171+
172+
volumes:
173+
postgres_data:
174+
conf:

0 commit comments

Comments
 (0)