Skip to content

Commit 67dc789

Browse files
committed
Add Docker support
1 parent 402f1b9 commit 67dc789

File tree

6 files changed

+104
-0
lines changed

6 files changed

+104
-0
lines changed

docker/.env

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Database configuration
2+
DB_PASSWORD=your_secure_password
3+
4+
# Host machine connection for IB Gateway
5+
HOST_IP=127.0.0.1
6+
IB_PORT=4001
7+
IB_CLIENT_ID=1

docker/Dockerfile

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
FROM ubuntu:22.04 as builder
2+
3+
# Install build dependencies
4+
RUN apt-get update && apt-get install -y \
5+
build-essential \
6+
cmake \
7+
libboost-all-dev \
8+
libpq-dev \
9+
git \
10+
&& rm -rf /var/lib/apt/lists/*
11+
12+
# Copy source code
13+
WORKDIR /build
14+
COPY . .
15+
16+
# Configure with performance flags
17+
RUN mkdir -p build && cd build && \
18+
cmake -DCMAKE_BUILD_TYPE=Release \
19+
-DCMAKE_CXX_FLAGS="-O3 -march=native -ffast-math -flto" ..
20+
21+
# Compile with all cores
22+
RUN cd build && make -j$(nproc)
23+
24+
# Create minimal runtime image
25+
FROM ubuntu:22.04
26+
27+
# Install only runtime dependencies
28+
RUN apt-get update && apt-get install -y \
29+
libboost-system1.74.0 \
30+
libboost-thread1.74.0 \
31+
libpq5 \
32+
postgresql-client \
33+
&& rm -rf /var/lib/apt/lists/*
34+
35+
# Copy the compiled application and configs
36+
COPY --from=builder /build/build/thales /usr/local/bin/
37+
COPY config /etc/thales/config/
38+
39+
# Create entrypoint script
40+
COPY docker/entrypoint.sh /entrypoint.sh
41+
RUN chmod +x /entrypoint.sh
42+
43+
ENTRYPOINT ["/entrypoint.sh"]

docker/docker-compose.yml

Whitespace-only changes.

docker/entrypoint.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Wait for PostgreSQL to be ready
5+
echo "Waiting for PostgreSQL..."
6+
until PGPASSWORD=$DB_PASSWORD psql -h $DB_HOST -U $DB_USER -d $DB_NAME -c '\q' 2>/dev/null; do
7+
echo "PostgreSQL is unavailable - sleeping"
8+
sleep 1
9+
done
10+
11+
echo "PostgreSQL is up - starting Thales"
12+
13+
# Start the trading bot with optimized settings
14+
exec /usr/local/bin/thales /etc/thales/config/config.json

scripts/docker_start.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
set -e
3+
4+
cd "$(git rev-parse --show-toplevel)"
5+
6+
# Detect host IP for different platforms
7+
if [[ "$OSTYPE" == "darwin"* ]]; then
8+
# macOS
9+
HOST_IP="host.docker.internal"
10+
elif [[ "$OSTYPE" == "msys"* || "$OSTYPE" == "cygwin"* ]]; then
11+
# Windows
12+
HOST_IP="host.docker.internal"
13+
else
14+
# Linux
15+
HOST_IP=$(ip route get 1 | awk '{print $7;exit}')
16+
fi
17+
18+
# Update .env file
19+
cd docker
20+
sed -i.bak "s/HOST_IP=.*/HOST_IP=$HOST_IP/" .env
21+
rm -f .env.bak 2>/dev/null || true
22+
cd ..
23+
24+
# Create directories
25+
mkdir -p logs data
26+
27+
echo "Starting Thales Trading Bot with host IP: $HOST_IP"
28+
echo "Make sure IB Gateway is running on your host machine on port 4001"
29+
30+
# Start containers
31+
cd docker && docker-compose up -d
32+
33+
echo "Containers started successfully!"

scripts/docker_stop.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
set -e
3+
4+
cd "$(git rev-parse --show-toplevel)"
5+
cd docker && docker-compose down
6+
7+
echo "Thales trading containers have been stopped."

0 commit comments

Comments
 (0)