Skip to content

Commit

Permalink
Merge pull request #1 from Jdelpizz/j-dev
Browse files Browse the repository at this point in the history
Add docker support
  • Loading branch information
Jdelpizz authored Apr 17, 2023
2 parents a751304 + 971a602 commit 29832f2
Show file tree
Hide file tree
Showing 14 changed files with 202 additions and 4 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,6 @@ This server exposes a couple REST endpoints to send/receive data (`8008` by defa

- GET `/` will return the content of `./data.json`
- POST `/` will write the request content to `./log`

# DOCKER NOTES
The computers viewing the dashboard need access to API Containers!
12 changes: 12 additions & 0 deletions dashboard/source
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
VITE_MSN_NUMBER=1337
VITE_MSN_PLATFORM=F-35
VITE_MSN_TAKEOFF=0900
VITE_MSN_RETURN=0930
VITE_SHOPS=BCD GCCS IAMD INTEL FREQ
VITE_WS_MSN_URI=msn-api
VITE_WS_MSN_PORT=8889
VITE_WS_MSN_CONTROL_PATH=msn-control
VITE_WS_MX_URI=mx-api
VITE_WS_MX_PORT=8888
VITE_WS_MX_CONTROL_PATH=mx-controller
4 changes: 2 additions & 2 deletions dashboard/src/Control.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ ActionsCard.propTypes = {
}

export default function Control(){
const mxUrl = `ws://${VITE_WS_MX_URI}:${VITE_WS_MX_PORT}${VITE_WS_MX_CONTROL_PATH}`;
const msnUrl = `ws://${VITE_WS_MSN_URI}:${VITE_WS_MSN_PORT}${VITE_WS_MSN_CONTROL_PATH}`;
const mxUrl = `ws://${VITE_WS_MX_URI}:${VITE_WS_MX_PORT}/${VITE_WS_MX_CONTROL_PATH}`;
const msnUrl = `ws://${VITE_WS_MSN_URI}:${VITE_WS_MSN_PORT}/${VITE_WS_MSN_CONTROL_PATH}`;

return (
<Flex h="100vh" w="100vw" align="center" justify="center">
Expand Down
1 change: 1 addition & 0 deletions dashboard/src/MsnDashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import usePersistentSocket from './usePersistentSocket'
const {VITE_WS_MSN_URI, VITE_WS_MSN_PORT, VITE_WS_MSN_PATH} = import.meta.env

export default function MsnDashboard(){

const [msnState, setMsnState] = React.useState({ intel: {}})
const { lastMessage, connectionStatus } = usePersistentSocket(`ws://${VITE_WS_MSN_URI}:${VITE_WS_MSN_PORT}${VITE_WS_MSN_PATH}`);

Expand Down
2 changes: 2 additions & 0 deletions dashboard/src/MxDashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import AircraftList from './AircraftList'
import Layout from './Layout'
import usePersistentSocket from './usePersistentSocket'


const {VITE_WS_MX_URI, VITE_WS_MX_PORT, VITE_WS_MX_PATH, VITE_WS_MX_SORTIE_PATH} = import.meta.env
const TAIL_NUMBERS = ["tv-01", "tv-02", "tv-05", "tv-06"]

Expand All @@ -12,6 +13,7 @@ export default function MxDashboard(){
const { lastMessage, connectionStatus } = usePersistentSocket(`ws://${VITE_WS_MX_URI}:${VITE_WS_MX_PORT}${VITE_WS_MX_PATH}`);
const { lastMessage: lastSortieMessage } = usePersistentSocket(`ws://${VITE_WS_MX_URI}:${VITE_WS_MX_PORT}${VITE_WS_MX_SORTIE_PATH}`);


React.useEffect(() => {
if(lastMessage){
setMxState(JSON.parse(lastMessage.data))
Expand Down
137 changes: 137 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
services:
dashboard:
image: tv-dashboard
build:
context: .
target: dashboard
ports:
- "1000:5173"
environment:
- VITE_MSN_NUMBER=1337
- VITE_MSN_PLATFORM=F-16
- VITE_MSN_TAKEOFF=0900
- VITE_MSN_RETURN=0930
- VITE_SHOPS=BCD GCCS IAMD INTEL FREQ WX

- VITE_WS_MSN_URI=msn-api
- VITE_WS_MSN_PORT=8889
- VITE_WS_MSN_PATH=msn-dashboard
- VITE_WS_MSN_CONTROL_PATH=msn-controller

- VITE_WS_MX_URI=mx-api
- VITE_WS_MX_PORT=8888
- VITE_WS_MX_PATH=mx-dashboard
- VITE_WS_MX_CONTROL_PATH=mx-controller


msn-api:
image: tv-msn-api-server
build:
context: .
target: msn-api-server
ports:
- "1010:8889"
environment:
- VITE_DATA_SERVERS=http://msn-data-1:8012 http://msn-data-2:8012 http://msn-data-3:8012 http://msn-data-4:8012 http://msn-data-5:8012 http://msn-data-6:8012

msn-data-1:
image: tv-msn-data-server
build:
context: .
target: msn-data-server
ports:
- "1011:8012"
command: make start p=8012 t=bcd

msn-data-2:
image: tv-msn-data-server
build:
context: .
target: msn-data-server
ports:
- "1012:8012"
command: make start p=8012 t=gccs

msn-data-3:
image: tv-msn-data-server
build:
context: .
target: msn-data-server
ports:
- "1013:8012"
command: make start p=8012 t=iamd

msn-data-4:
image: tv-msn-data-server
build:
context: .
target: msn-data-server
ports:
- "1014:8012"
command: make start p=8012 t=intel

msn-data-5:
image: tv-msn-data-server
build:
context: .
target: msn-data-server
ports:
- "1015:8012"
command: make start p=8012 t=freq

msn-data-6:
image: tv-msn-data-server
build:
context: .
target: msn-data-server
ports:
- "1016:8012"
command: make start p=8012 t=wx

mx-api:
image: tv-mx-api-server
build:
context: .
target: mx-api-server
ports:
- "1020:8888"
environment:
- VITE_DATA_SERVERS=http://mx-data-1:8008 http://mx-data-2:8008 http://mx-data-3:8008 http://mx-data-4:8008

mx-data-1:
image: tv-mx-data-server
build:
context: .
target: mx-data-server
ports:
- "1021:8008"
command: make start p=8008 t=tv-01

mx-data-2:
image: tv-mx-data-server
build:
context: .
target: mx-data-server
ports:
- "1022:8008"
command: make start p=8008 t=tv-02

mx-data-3:
image: tv-mx-data-server
build:
context: .
target: mx-data-server
ports:
- "1023:8008"
command: make start p=8008 t=tv-05

mx-data-4:
image: tv-mx-data-server
build:
context: .
target: mx-data-server
ports:
- "1024:8008"
command: make start p=8008 t=tv-06


34 changes: 34 additions & 0 deletions dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
FROM ubuntu AS base
# Install dependencies
RUN apt-get update
RUN apt-get install -y curl make net-tools pip && curl -fsSL https://deb.nodesource.com/setup_19.x | bash - && apt-get install -y nodejs
RUN pip install websockets

WORKDIR /app

FROM base as dashboard
COPY dashboard /app
RUN npm install
EXPOSE 5173
CMD make


FROM base as msn-api-server
COPY msn-api-server /app
EXPOSE 8889
CMD make

FROM base as msn-data-server
COPY msn-data-server /app
EXPOSE 8012
CMD make start1

FROM base as mx-api-server
COPY mx-api-server /app
EXPOSE 8889
CMD make

FROM base as mx-data-server
COPY mx-data-server /app
EXPOSE 8008
CMD make start1
3 changes: 2 additions & 1 deletion msn-api-server/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
LOCAL_IP=$$(ifconfig en0 | awk '/inet / {print $$2}')
#LOCAL_IP=$$(ifconfig en0 | awk '/inet / {print $$2}')
LOCAL_IP=$$(python3 -c 'import socket; ip=socket.gethostbyname(socket.gethostname()); print(ip)')
WS_PORT=8889

start:
Expand Down
2 changes: 2 additions & 0 deletions msn-api-server/msn-api-server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import asyncio
import json
import socket
import os
import websockets

MSN_DATA_FILE = 'msn-data.json'
Expand All @@ -15,6 +16,7 @@
{"name": "wx", "url": "http://localhost:8017"},
]


# Connection channels
connections = {
'/msn-controller': set(),
Expand Down
2 changes: 2 additions & 0 deletions msn-api-server/source
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
VITE_DATA_SERVERS = http://msn-data-1:8012 http://msn-data-2:8012 http://msn-data-3:8012 http://msn-data-4:8012 http://msn-data-5:8012 http://msn-data-6:8012
2 changes: 1 addition & 1 deletion mx-api-server/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
LOCAL_IP=$$(ifconfig en0 | awk '/inet / {print $$2}')
LOCAL_IP=$$(python3 -c 'import socket; ip=socket.gethostbyname(socket.gethostname()); print(ip)')
WS_PORT=8888

start:
Expand Down
1 change: 1 addition & 0 deletions mx-api-server/mx-api-server.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import socket
import websockets


MX_DATA_FILE = 'mx-data.json'
DATA_SERVERS = [
{ "name": "tv-01", "url": "http://localhost:8008"},
Expand Down
2 changes: 2 additions & 0 deletions mx-api-server/source
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
VITE_DATA_SERVERS=http://mx-data-1:8008 http://mx-data-2:8008 http://mx-data-3:8008 http://mx-data-4:8008
1 change: 1 addition & 0 deletions rebuild_and_start_containers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docker compose down; docker compose build; docker compose up -d

0 comments on commit 29832f2

Please sign in to comment.