Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# SPDX-License-Identifier: Apache-2.0
# Docker build context exclusions

# Git
.git
.github
.gitignore

# Documentation
*.md
docs/
LICENSE
NOTICE.md

# MongoDB data (should use volumes, not baked in)
mongodb/db/

# IDE
.vscode/
.idea/
*.iml

# OS
.DS_Store
Thumbs.db
42 changes: 25 additions & 17 deletions .github/workflows/makefile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,48 @@ name: Makefile CI

on:
push:
branches: [ "add-license-1" ]
branches: [ "add-license-1", "main" ]
pull_request:
branches: [ "add-license-1" ]
branches: [ "add-license-1", "main" ]

jobs:
build:

runs-on: ubuntu-20.04
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v4

# - name: configure
# run: ./configure

- name: Install dependencies
run: |
sudo apt install git
sudo apt install make
sudo apt install maven
sudo apt install groovy
sudo apt install python3-venv
sudo apt install python3-pip
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4
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
sudo apt install mongodb-org
sudo apt-get update
sudo apt-get install -y git make maven groovy python3-venv python3-pip curl
curl -fsSL https://www.mongodb.org/static/pgp/server-6.0.asc | sudo gpg --dearmor -o /usr/share/keyrings/mongodb-server-6.0.gpg
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
sudo apt-get update
sudo apt-get install -y mongodb-org

- name: Build
run: make build

- name: Run
run: make run
run: |
make run
sleep 30

- name: Health check
run: |
echo "Checking service health..."
curl -sf http://localhost:4382/ > /dev/null && echo "✓ Main Controller (4382) is up" || echo "✗ Main Controller (4382) is down"
curl -sf http://localhost:4390/ > /dev/null && echo "✓ Emulator (4390) is up" || echo "✗ Emulator (4390) is down"
curl -sf http://localhost:10000/ > /dev/null && echo "✓ Tester (10000) is up" || echo "✗ Tester (10000) is down"
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"
# Fail the job if the main services are not responding
curl -sf http://localhost:4382/ > /dev/null
curl -sf http://localhost:4390/ > /dev/null

- name: Stop
if: always()
run: make stop


46 changes: 46 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# SPDX-License-Identifier: Apache-2.0
# Docker Compose for APIS (Autonomous Power Interchange System)
#
# Usage:
# docker compose up --build # Build from source and start
# docker compose up -d # Start in detached mode
# docker compose down # Stop all services
# docker compose logs -f apis # Follow APIS logs

services:
mongodb:
image: mongo:6.0
container_name: apis-mongodb
ports:
- "27017:27017"
volumes:
- mongodb_data:/data/db
healthcheck:
test: ["CMD", "mongosh", "--eval", "db.adminCommand('ping')"]
interval: 10s
timeout: 5s
retries: 5
start_period: 10s
restart: unless-stopped

apis:
build:
context: .
dockerfile: docker/Dockerfile
container_name: apis-app
depends_on:
mongodb:
condition: service_healthy
ports:
- "4382:4382"
- "4390:4390"
- "8000:8000"
- "10000:10000"
environment:
- MONGODB_HOST=mongodb
- MONGODB_PORT=27017
restart: unless-stopped

volumes:
mongodb_data:
driver: local
95 changes: 95 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# SPDX-License-Identifier: Apache-2.0
# Multi-stage Dockerfile for APIS (Autonomous Power Interchange System)
# Builds all services from source for full reproducibility.

# ==============================================================================
# Stage 1: Builder - Compile Java services and prepare Python virtual environments
# ==============================================================================
FROM ubuntu:20.04 AS builder

ENV DEBIAN_FRONTEND=noninteractive
ENV TZ=Asia/Tokyo

RUN apt-get update && apt-get install -y --no-install-recommends \
git \
make \
maven \
groovy \
python3-venv \
python3-pip \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /build

# Clone and build all sub-repositories using the Makefile orchestrator
COPY Makefile runner.sh ./

# Clone all repositories
RUN make apis-bom apis-common apis-main apis-ccc apis-log apis-web \
apis-emulator apis-main_controller apis-service_center apis-tester

# Build Java dependencies first (order matters)
RUN cd apis-bom && make install
RUN cd apis-common && make install

# Build Java services (produces fat JARs)
RUN cd apis-main && make package
RUN cd apis-ccc && make package
RUN cd apis-log && make package
RUN cd apis-web && make package

# Build Python services (create virtual environments)
RUN cd apis-emulator && sh venv.sh
RUN cd apis-main_controller && sh venv.sh
RUN cd apis-service_center && sh venv.sh && sh initdb.sh
RUN cd apis-tester && sh venv.sh

# ==============================================================================
# Stage 2: Runtime - Lean image with only what's needed to run
# ==============================================================================
FROM ubuntu:20.04 AS runtime

ENV DEBIAN_FRONTEND=noninteractive
ENV TZ=Asia/Tokyo

RUN apt-get update && apt-get install -y --no-install-recommends \
default-jre-headless \
python3 \
python3-venv \
curl \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /APIS

# Copy built artifacts from builder
COPY --from=builder /build/apis-main /APIS/apis-main
COPY --from=builder /build/apis-ccc /APIS/apis-ccc
COPY --from=builder /build/apis-log /APIS/apis-log
COPY --from=builder /build/apis-web /APIS/apis-web
COPY --from=builder /build/apis-emulator /APIS/apis-emulator
COPY --from=builder /build/apis-main_controller /APIS/apis-main_controller
COPY --from=builder /build/apis-service_center /APIS/apis-service_center
COPY --from=builder /build/apis-tester /APIS/apis-tester

# Copy orchestration files
COPY Makefile runner.sh mongodb/ /APIS/
COPY mongodb/ /APIS/mongodb/

# Fix MongoDB port in service_center demo settings (27018 -> 27017)
RUN if [ -f /APIS/apis-service_center/config/settings/apis-service_center-demo.py ]; then \
sed -i 's/27018/27017/g' /APIS/apis-service_center/config/settings/apis-service_center-demo.py; \
fi

# Expose all service ports
EXPOSE 4382 4390 8000 10000

# Health check against the main controller
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
CMD curl -f http://localhost:4382/ || exit 1

# Entrypoint script to start all services
COPY docker/entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]
106 changes: 106 additions & 0 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#!/bin/bash
# SPDX-License-Identifier: Apache-2.0
# Entrypoint script for APIS container
# Starts all services and keeps the container running

set -e

APIS_DIR="/APIS"
cd "$APIS_DIR"

echo "========================================"
echo " APIS - Autonomous Power Interchange System"
echo " Starting all services..."
echo "========================================"

# Start apis-service_center (Django)
echo "[1/8] Starting apis-service_center on port 8000..."
cd "$APIS_DIR/apis-service_center"
. venv/bin/activate
python3 ./manage.py runserver --settings=config.settings.apis-service_center-demo 0.0.0.0:8000 &
deactivate 2>/dev/null || true

# Start apis-emulator
echo "[2/8] Starting apis-emulator on port 4390..."
cd "$APIS_DIR/apis-emulator"
. venv/bin/activate
python3 ./startEmul.py 4 &
deactivate 2>/dev/null || true

# Start apis-main instances (4 nodes)
echo "[3/8] Starting apis-main (4 instances)..."
cd "$APIS_DIR/apis-main/exe"
java -Djava.net.preferIPv4Stack=true -Duser.timezone=Asia/Tokyo \
-Djava.util.logging.config.file=./logging.properties \
-Dvertx.hazelcast.config=./cluster.xml \
-jar ../target/apis-main-3.0.0-fat.jar -conf ./config.json \
-cluster -cluster-host 127.0.0.1 &

java -Djava.net.preferIPv4Stack=true -Duser.timezone=Asia/Tokyo \
-Djava.util.logging.config.file=./logging.properties \
-Dvertx.hazelcast.config=./cluster.xml \
-jar ../target/apis-main-3.0.0-fat.jar -conf ./config2.json \
-cluster -cluster-host 127.0.0.1 &

java -Djava.net.preferIPv4Stack=true -Duser.timezone=Asia/Tokyo \
-Djava.util.logging.config.file=./logging.properties \
-Dvertx.hazelcast.config=./cluster.xml \
-jar ../target/apis-main-3.0.0-fat.jar -conf ./config3.json \
-cluster -cluster-host 127.0.0.1 &

java -Djava.net.preferIPv4Stack=true -Duser.timezone=Asia/Tokyo \
-Djava.util.logging.config.file=./logging.properties \
-Dvertx.hazelcast.config=./cluster.xml \
-jar ../target/apis-main-3.0.0-fat.jar -conf ./config4.json \
-cluster -cluster-host 127.0.0.1 &

# Start apis-ccc
echo "[4/8] Starting apis-ccc..."
cd "$APIS_DIR/apis-ccc/exe"
java -Djava.net.preferIPv4Stack=true -Duser.timezone=Asia/Tokyo \
-Djava.util.logging.config.file=./logging.properties \
-Dvertx.hazelcast.config=./cluster.xml \
-jar ../target/apis-ccc-3.0.0-fat.jar -conf ./config.json \
-cluster -cluster-host 127.0.0.1 &

# Start apis-log
echo "[5/8] Starting apis-log..."
cd "$APIS_DIR/apis-log/exe"
java -Djava.net.preferIPv4Stack=true -Duser.timezone=Asia/Tokyo \
-Djava.util.logging.config.file=./logging.properties \
-jar ../target/apis-log-3.0.0-fat.jar -conf ./config.json &

# Start apis-web
echo "[6/8] Starting apis-web..."
cd "$APIS_DIR/apis-web/exe"
java -Djava.net.preferIPv4Stack=true -Duser.timezone=Asia/Tokyo \
-Djava.util.logging.config.file=./logging.properties \
-Dvertx.hazelcast.config=./cluster.xml \
-jar ../target/apis-web-3.0.0-fat.jar run \
jp.co.sony.csl.dcoes.apis.tools.web.util.Starter \
--conf ./config.json --cluster --cluster-host 127.0.0.1 &

# Start apis-main_controller
echo "[7/8] Starting apis-main_controller on port 4382..."
cd "$APIS_DIR/apis-main_controller"
. venv/bin/activate
python3 ./startMain.py &
deactivate 2>/dev/null || true

# Start apis-tester
echo "[8/8] Starting apis-tester on port 10000..."
cd "$APIS_DIR/apis-tester"
. venv/bin/activate
python3 ./startTester.py &
deactivate 2>/dev/null || true

echo "========================================"
echo " All services started!"
echo " Dashboard: http://localhost:4382"
echo " Emulator: http://localhost:4390"
echo " Tester: http://localhost:10000"
echo " Admin Panel: http://localhost:8000/static/ui_example/staff/visual.html"
echo "========================================"

# Keep the container running and forward signals
wait
Loading