-
Notifications
You must be signed in to change notification settings - Fork 37
[Feature] Automated Multi-Service Deployment with Docker Compose and Production-Ready CI/CD Pipeline #99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
GaneshPatil7517
wants to merge
2
commits into
hyphae:add-license-1
Choose a base branch
from
GaneshPatil7517:feature/docker-compose-cicd-pipeline
base: add-license-1
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[Feature] Automated Multi-Service Deployment with Docker Compose and Production-Ready CI/CD Pipeline #99
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| # 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 | ||
|
|
||
GaneshPatil7517 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # 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/ | ||
|
|
||
| # Fix MongoDB port in service_center demo settings (27018 -> 27017) | ||
| RUN for settings_file in \ | ||
| /APIS/apis-service_center/config/settings/apis_service_center_demo.py \ | ||
| /APIS/apis-service_center/config/settings/apis-service_center-demo.py; do \ | ||
| if [ -f "$settings_file" ]; then \ | ||
| sed -i 's/27018/27017/g' "$settings_file"; \ | ||
| fi; \ | ||
| done | ||
|
|
||
| # 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"] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| #!/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 -m gunicorn config.wsgi:application --bind 0.0.0.0:8000 --env DJANGO_SETTINGS_MODULE=config.settings.apis_service_center_demo & | ||
| 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 "========================================" | ||
|
|
||
| terminate_children() { | ||
| local pids | ||
| pids="$(jobs -pr)" | ||
| if [ -n "$pids" ]; then | ||
| kill -TERM $pids 2>/dev/null || true | ||
| fi | ||
| } | ||
|
|
||
| trap 'terminate_children; wait || true; exit 143' TERM INT | ||
|
|
||
| # Keep the container running, forward signals, and exit if any service stops | ||
| wait -n | ||
| status=$? | ||
| terminate_children | ||
| wait || true | ||
| exit "$status" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.