Skip to content

Commit 05b3992

Browse files
[Feature] Add Docker Compose deployment, fix CI/CD pipeline, and standardize MongoDB port
- Add multi-stage Dockerfile that builds all APIS services from source - Add docker-compose.yml with MongoDB 6.0 service and health checks - Add entrypoint.sh to orchestrate all service startup - Add .dockerignore to optimize Docker build context - Fix CI workflow: target main branch, upgrade to ubuntu-22.04 and MongoDB 6.0 - Add post-deployment health checks to CI pipeline - Standardize MongoDB port from 27018 to 27017 across start.sh and stop.sh - Update docs/INSTALL_DOCKER.md with docker compose quick start - Add docs/DEVELOPMENT.md with architecture overview and dev guide Closes #98 Signed-off-by: Ganesh Patil <7030871503ganeshpatil@gmail.com>
1 parent 10c736e commit 05b3992

File tree

9 files changed

+450
-20
lines changed

9 files changed

+450
-20
lines changed

.dockerignore

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
# Docker build context exclusions
3+
4+
# Git
5+
.git
6+
.github
7+
.gitignore
8+
9+
# Documentation
10+
*.md
11+
docs/
12+
LICENSE
13+
NOTICE.md
14+
15+
# MongoDB data (should use volumes, not baked in)
16+
mongodb/db/
17+
18+
# IDE
19+
.vscode/
20+
.idea/
21+
*.iml
22+
23+
# OS
24+
.DS_Store
25+
Thumbs.db

.github/workflows/makefile.yml

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,48 @@ name: Makefile CI
22

33
on:
44
push:
5-
branches: [ "add-license-1" ]
5+
branches: [ "add-license-1", "main" ]
66
pull_request:
7-
branches: [ "add-license-1" ]
7+
branches: [ "add-license-1", "main" ]
88

99
jobs:
1010
build:
1111

12-
runs-on: ubuntu-20.04
12+
runs-on: ubuntu-22.04
1313

1414
steps:
1515
- uses: actions/checkout@v4
1616

17-
# - name: configure
18-
# run: ./configure
19-
2017
- name: Install dependencies
2118
run: |
22-
sudo apt install git
23-
sudo apt install make
24-
sudo apt install maven
25-
sudo apt install groovy
26-
sudo apt install python3-venv
27-
sudo apt install python3-pip
28-
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4
29-
echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list
30-
sudo apt install mongodb-org
19+
sudo apt-get update
20+
sudo apt-get install -y git make maven groovy python3-venv python3-pip curl
21+
curl -fsSL https://www.mongodb.org/static/pgp/server-6.0.asc | sudo gpg --dearmor -o /usr/share/keyrings/mongodb-server-6.0.gpg
22+
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-6.0.gpg ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list
23+
sudo apt-get update
24+
sudo apt-get install -y mongodb-org
3125
3226
- name: Build
3327
run: make build
34-
28+
3529
- name: Run
36-
run: make run
30+
run: |
31+
make run
32+
sleep 30
33+
34+
- name: Health check
35+
run: |
36+
echo "Checking service health..."
37+
curl -sf http://localhost:4382/ > /dev/null && echo "✓ Main Controller (4382) is up" || echo "✗ Main Controller (4382) is down"
38+
curl -sf http://localhost:4390/ > /dev/null && echo "✓ Emulator (4390) is up" || echo "✗ Emulator (4390) is down"
39+
curl -sf http://localhost:10000/ > /dev/null && echo "✓ Tester (10000) is up" || echo "✗ Tester (10000) is down"
40+
curl -sf http://localhost:8000/static/ui_example/staff/visual.html > /dev/null && echo "✓ Service Center (8000) is up" || echo "✗ Service Center (8000) is down"
41+
# Fail the job if the main services are not responding
42+
curl -sf http://localhost:4382/ > /dev/null
43+
curl -sf http://localhost:4390/ > /dev/null
3744
3845
- name: Stop
46+
if: always()
3947
run: make stop
4048

4149

docker-compose.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
# Docker Compose for APIS (Autonomous Power Interchange System)
3+
#
4+
# Usage:
5+
# docker compose up --build # Build from source and start
6+
# docker compose up -d # Start in detached mode
7+
# docker compose down # Stop all services
8+
# docker compose logs -f apis # Follow APIS logs
9+
10+
services:
11+
mongodb:
12+
image: mongo:6.0
13+
container_name: apis-mongodb
14+
ports:
15+
- "27017:27017"
16+
volumes:
17+
- mongodb_data:/data/db
18+
healthcheck:
19+
test: ["CMD", "mongosh", "--eval", "db.adminCommand('ping')"]
20+
interval: 10s
21+
timeout: 5s
22+
retries: 5
23+
start_period: 10s
24+
restart: unless-stopped
25+
26+
apis:
27+
build:
28+
context: .
29+
dockerfile: docker/Dockerfile
30+
container_name: apis-app
31+
depends_on:
32+
mongodb:
33+
condition: service_healthy
34+
ports:
35+
- "4382:4382"
36+
- "4390:4390"
37+
- "8000:8000"
38+
- "10000:10000"
39+
environment:
40+
- MONGODB_HOST=mongodb
41+
- MONGODB_PORT=27017
42+
restart: unless-stopped
43+
44+
volumes:
45+
mongodb_data:
46+
driver: local

docker/Dockerfile

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
# Multi-stage Dockerfile for APIS (Autonomous Power Interchange System)
3+
# Builds all services from source for full reproducibility.
4+
5+
# ==============================================================================
6+
# Stage 1: Builder - Compile Java services and prepare Python virtual environments
7+
# ==============================================================================
8+
FROM ubuntu:20.04 AS builder
9+
10+
ENV DEBIAN_FRONTEND=noninteractive
11+
ENV TZ=Asia/Tokyo
12+
13+
RUN apt-get update && apt-get install -y --no-install-recommends \
14+
git \
15+
make \
16+
maven \
17+
groovy \
18+
python3-venv \
19+
python3-pip \
20+
ca-certificates \
21+
&& rm -rf /var/lib/apt/lists/*
22+
23+
WORKDIR /build
24+
25+
# Clone and build all sub-repositories using the Makefile orchestrator
26+
COPY Makefile runner.sh ./
27+
28+
# Clone all repositories
29+
RUN make apis-bom apis-common apis-main apis-ccc apis-log apis-web \
30+
apis-emulator apis-main_controller apis-service_center apis-tester
31+
32+
# Build Java dependencies first (order matters)
33+
RUN cd apis-bom && make install
34+
RUN cd apis-common && make install
35+
36+
# Build Java services (produces fat JARs)
37+
RUN cd apis-main && make package
38+
RUN cd apis-ccc && make package
39+
RUN cd apis-log && make package
40+
RUN cd apis-web && make package
41+
42+
# Build Python services (create virtual environments)
43+
RUN cd apis-emulator && sh venv.sh
44+
RUN cd apis-main_controller && sh venv.sh
45+
RUN cd apis-service_center && sh venv.sh && sh initdb.sh
46+
RUN cd apis-tester && sh venv.sh
47+
48+
# ==============================================================================
49+
# Stage 2: Runtime - Lean image with only what's needed to run
50+
# ==============================================================================
51+
FROM ubuntu:20.04 AS runtime
52+
53+
ENV DEBIAN_FRONTEND=noninteractive
54+
ENV TZ=Asia/Tokyo
55+
56+
RUN apt-get update && apt-get install -y --no-install-recommends \
57+
default-jre-headless \
58+
python3 \
59+
python3-venv \
60+
curl \
61+
&& rm -rf /var/lib/apt/lists/*
62+
63+
WORKDIR /APIS
64+
65+
# Copy built artifacts from builder
66+
COPY --from=builder /build/apis-main /APIS/apis-main
67+
COPY --from=builder /build/apis-ccc /APIS/apis-ccc
68+
COPY --from=builder /build/apis-log /APIS/apis-log
69+
COPY --from=builder /build/apis-web /APIS/apis-web
70+
COPY --from=builder /build/apis-emulator /APIS/apis-emulator
71+
COPY --from=builder /build/apis-main_controller /APIS/apis-main_controller
72+
COPY --from=builder /build/apis-service_center /APIS/apis-service_center
73+
COPY --from=builder /build/apis-tester /APIS/apis-tester
74+
75+
# Copy orchestration files
76+
COPY Makefile runner.sh mongodb/ /APIS/
77+
COPY mongodb/ /APIS/mongodb/
78+
79+
# Fix MongoDB port in service_center demo settings (27018 -> 27017)
80+
RUN if [ -f /APIS/apis-service_center/config/settings/apis-service_center-demo.py ]; then \
81+
sed -i 's/27018/27017/g' /APIS/apis-service_center/config/settings/apis-service_center-demo.py; \
82+
fi
83+
84+
# Expose all service ports
85+
EXPOSE 4382 4390 8000 10000
86+
87+
# Health check against the main controller
88+
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
89+
CMD curl -f http://localhost:4382/ || exit 1
90+
91+
# Entrypoint script to start all services
92+
COPY docker/entrypoint.sh /entrypoint.sh
93+
RUN chmod +x /entrypoint.sh
94+
95+
ENTRYPOINT ["/entrypoint.sh"]

docker/entrypoint.sh

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: Apache-2.0
3+
# Entrypoint script for APIS container
4+
# Starts all services and keeps the container running
5+
6+
set -e
7+
8+
APIS_DIR="/APIS"
9+
cd "$APIS_DIR"
10+
11+
echo "========================================"
12+
echo " APIS - Autonomous Power Interchange System"
13+
echo " Starting all services..."
14+
echo "========================================"
15+
16+
# Start apis-service_center (Django)
17+
echo "[1/8] Starting apis-service_center on port 8000..."
18+
cd "$APIS_DIR/apis-service_center"
19+
. venv/bin/activate
20+
python3 ./manage.py runserver --settings=config.settings.apis-service_center-demo 0.0.0.0:8000 &
21+
deactivate 2>/dev/null || true
22+
23+
# Start apis-emulator
24+
echo "[2/8] Starting apis-emulator on port 4390..."
25+
cd "$APIS_DIR/apis-emulator"
26+
. venv/bin/activate
27+
python3 ./startEmul.py 4 &
28+
deactivate 2>/dev/null || true
29+
30+
# Start apis-main instances (4 nodes)
31+
echo "[3/8] Starting apis-main (4 instances)..."
32+
cd "$APIS_DIR/apis-main/exe"
33+
java -Djava.net.preferIPv4Stack=true -Duser.timezone=Asia/Tokyo \
34+
-Djava.util.logging.config.file=./logging.properties \
35+
-Dvertx.hazelcast.config=./cluster.xml \
36+
-jar ../target/apis-main-3.0.0-fat.jar -conf ./config.json \
37+
-cluster -cluster-host 127.0.0.1 &
38+
39+
java -Djava.net.preferIPv4Stack=true -Duser.timezone=Asia/Tokyo \
40+
-Djava.util.logging.config.file=./logging.properties \
41+
-Dvertx.hazelcast.config=./cluster.xml \
42+
-jar ../target/apis-main-3.0.0-fat.jar -conf ./config2.json \
43+
-cluster -cluster-host 127.0.0.1 &
44+
45+
java -Djava.net.preferIPv4Stack=true -Duser.timezone=Asia/Tokyo \
46+
-Djava.util.logging.config.file=./logging.properties \
47+
-Dvertx.hazelcast.config=./cluster.xml \
48+
-jar ../target/apis-main-3.0.0-fat.jar -conf ./config3.json \
49+
-cluster -cluster-host 127.0.0.1 &
50+
51+
java -Djava.net.preferIPv4Stack=true -Duser.timezone=Asia/Tokyo \
52+
-Djava.util.logging.config.file=./logging.properties \
53+
-Dvertx.hazelcast.config=./cluster.xml \
54+
-jar ../target/apis-main-3.0.0-fat.jar -conf ./config4.json \
55+
-cluster -cluster-host 127.0.0.1 &
56+
57+
# Start apis-ccc
58+
echo "[4/8] Starting apis-ccc..."
59+
cd "$APIS_DIR/apis-ccc/exe"
60+
java -Djava.net.preferIPv4Stack=true -Duser.timezone=Asia/Tokyo \
61+
-Djava.util.logging.config.file=./logging.properties \
62+
-Dvertx.hazelcast.config=./cluster.xml \
63+
-jar ../target/apis-ccc-3.0.0-fat.jar -conf ./config.json \
64+
-cluster -cluster-host 127.0.0.1 &
65+
66+
# Start apis-log
67+
echo "[5/8] Starting apis-log..."
68+
cd "$APIS_DIR/apis-log/exe"
69+
java -Djava.net.preferIPv4Stack=true -Duser.timezone=Asia/Tokyo \
70+
-Djava.util.logging.config.file=./logging.properties \
71+
-jar ../target/apis-log-3.0.0-fat.jar -conf ./config.json &
72+
73+
# Start apis-web
74+
echo "[6/8] Starting apis-web..."
75+
cd "$APIS_DIR/apis-web/exe"
76+
java -Djava.net.preferIPv4Stack=true -Duser.timezone=Asia/Tokyo \
77+
-Djava.util.logging.config.file=./logging.properties \
78+
-Dvertx.hazelcast.config=./cluster.xml \
79+
-jar ../target/apis-web-3.0.0-fat.jar run \
80+
jp.co.sony.csl.dcoes.apis.tools.web.util.Starter \
81+
--conf ./config.json --cluster --cluster-host 127.0.0.1 &
82+
83+
# Start apis-main_controller
84+
echo "[7/8] Starting apis-main_controller on port 4382..."
85+
cd "$APIS_DIR/apis-main_controller"
86+
. venv/bin/activate
87+
python3 ./startMain.py &
88+
deactivate 2>/dev/null || true
89+
90+
# Start apis-tester
91+
echo "[8/8] Starting apis-tester on port 10000..."
92+
cd "$APIS_DIR/apis-tester"
93+
. venv/bin/activate
94+
python3 ./startTester.py &
95+
deactivate 2>/dev/null || true
96+
97+
echo "========================================"
98+
echo " All services started!"
99+
echo " Dashboard: http://localhost:4382"
100+
echo " Emulator: http://localhost:4390"
101+
echo " Tester: http://localhost:10000"
102+
echo " Admin Panel: http://localhost:8000/static/ui_example/staff/visual.html"
103+
echo "========================================"
104+
105+
# Keep the container running and forward signals
106+
wait

0 commit comments

Comments
 (0)