Skip to content

Commit

Permalink
#622 Fix docker-compose depends_on (#623)
Browse files Browse the repository at this point in the history
* #622 Fix docker-compose depends_on

* #622 Add v1 docker-compose and fix CMD-SHELL

* #622 Small tweaks

* #622 Update docker-compose.sample

* #622 Fix docker-compose cmd-shell
  • Loading branch information
tariqksoliman authored Jan 29, 2025
1 parent 887277b commit b0554b4
Show file tree
Hide file tree
Showing 7 changed files with 380 additions and 214 deletions.
144 changes: 144 additions & 0 deletions API/Backend/Utils/routes/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ const express = require("express");
const router = express.Router();
const fs = require("fs");
const path = require("path");
const exec = require("child_process").exec;
const execFile = require("child_process").execFile;

const Sequelize = require("sequelize");
const { sequelizeSTAC } = require("../../../connection");

Expand Down Expand Up @@ -227,4 +230,145 @@ router.get("/queryTilesetTimes", function (req, res) {
else queryTilesetTimesDir(req, res);
});

// API
// TODO: move to API/Backend
//TEST
router.get("/healthcheck", function (req, res) {
res.send("Alive and Well!");
});

// TODO: Remove or move to Setup structure. Some are definitely still used.

//utils getprofile
router.post("/getprofile", function (req, res) {
const path = encodeURIComponent(req.body.path);
const lat1 = encodeURIComponent(req.body.lat1);
const lon1 = encodeURIComponent(req.body.lon1);
const lat2 = encodeURIComponent(req.body.lat2);
const lon2 = encodeURIComponent(req.body.lon2);
const steps = encodeURIComponent(req.body.steps);
const axes = encodeURIComponent(req.body.axes);

execFile(
"python",
[
"private/api/2ptsToProfile.py",
path,
lat1,
lon1,
lat2,
lon2,
steps,
axes,
1,
],
function (error, stdout, stderr) {
if (error) {
logger("warn", error);
res.status(400).send();
} else {
res.send(stdout.replace(/None/g, null));
}
}
);
});

//utils getbands
router.post("/getbands", function (req, res) {
const path = encodeURIComponent(req.body.path);
const x = encodeURIComponent(req.body.x);
const y = encodeURIComponent(req.body.y);
const xyorll = encodeURIComponent(req.body.xyorll);
const bands = encodeURIComponent(req.body.bands);

execFile(
"python",
["private/api/BandsToProfile.py", path, x, y, xyorll, bands],
function (error, stdout, stderr) {
if (error) {
logger("warn", error);
res.status(400).send();
} else {
res.send(stdout);
}
}
);
});

//utils ll2aerll
router.post("/ll2aerll", function (req, res) {
const lng = encodeURIComponent(req.body.lng);
const lat = encodeURIComponent(req.body.lat);
const height = encodeURIComponent(req.body.height);
const target = encodeURIComponent(req.body.target);
const time = encodeURIComponent(req.body.time)
.replace(/%20/g, " ")
.replace(/%3A/g, ":");
const obsRefFrame = encodeURIComponent(req.body.obsRefFrame) || "IAU_MARS";
const obsBody = encodeURIComponent(req.body.obsBody) || "MARS";
const includeSunEarth =
encodeURIComponent(req.body.includeSunEarth) || "False";

const isCustom = encodeURIComponent(req.body.isCustom) || "False";
const customAz = encodeURIComponent(req.body.customAz);
const customEl = encodeURIComponent(req.body.customEl);
const customRange = encodeURIComponent(req.body.customRange);

execFile(
"python",
[
"private/api/ll2aerll.py",
lng,
lat,
height,
target,
time,
obsRefFrame,
obsBody,
includeSunEarth,
isCustom,
customAz,
customEl,
customRange,
],
function (error, stdout, stderr) {
if (error) logger("error", "ll2aerll failure:", "server", null, error);
res.send(stdout);
}
);
});

//utils chronos (spice time converter)
router.post("/chronice", function (req, res) {
const body = encodeURIComponent(req.body.body);
const target = encodeURIComponent(req.body.target);
const fromFormat = encodeURIComponent(req.body.from);
const time = encodeURIComponent(req.body.time)
.replace(/%20/g, " ")
.replace(/%3A/g, ":");

execFile(
"python",
["private/api/chronice.py", body, target, fromFormat, time],
function (error, stdout, stderr) {
if (error) logger("error", "chronice failure:", "server", null, error);
res.send(stdout);
}
);
});

//utils chronos (spice time converter)
router.get("/proj42wkt", function (req, res) {
const proj4 = encodeURIComponent(req.query.proj4);

execFile(
"python",
["private/api/proj42wkt.py", proj4],
function (error, stdout, stderr) {
if (error) logger("error", "proj42wkt failure:", "server", null, error);
res.send(stdout);
}
);
});

module.exports = router;
49 changes: 44 additions & 5 deletions docker-compose.sample.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
services:
mmgis:
build: .
# build: .
image: ghcr.io/nasa-ammos/mmgis:development
depends_on:
- db
db:
condition: service_healthy
restart: true
env_file: .env
ports:
- 8888:8888
healthcheck:
# Use https if using HTTPS= env
test:
[
"CMD",
"curl",
"-XGET",
"-k",
"http://mmgis:8888/API/utils/healthcheck",
]
interval: 20s
retries: 5
start_period: 15s
timeout: 8s
restart: on-failure
volumes:
- ./Missions:/usr/src/app/Missions
Expand All @@ -26,7 +43,12 @@ services:
- DB_MIN_CONN_SIZE=1
- DB_MAX_CONN_SIZE=1
depends_on:
- db
mmgis:
condition: service_healthy
restart: true
db:
condition: service_healthy
restart: true
command: bash -c "bash /tmp/scripts/wait-for-it.sh -t 120 -h db -p 5432 && uvicorn stac_fastapi.pgstac.app:app --host 0.0.0.0 --port 8881"
volumes:
- ./adjacent-servers/docker-scripts:/tmp/scripts
Expand Down Expand Up @@ -56,7 +78,12 @@ services:
- DB_MAX_CONN_SIZE=10
command: bash -c "bash /tmp/scripts/wait-for-it.sh -t 120 -h db -p 5432 && /start.sh"
depends_on:
- db
mmgis:
condition: service_healthy
restart: true
db:
condition: service_healthy
restart: true
volumes:
- ./adjacent-servers/docker-scripts:/tmp/scripts
- ./Missions:/Missions
Expand Down Expand Up @@ -151,7 +178,12 @@ services:
- TITILER_PGSTAC_SEARCH_EXITWHENFULL=FALSE
- TITILER_PGSTAC_SEARCH_SKIPCOVERED=FALSE
depends_on:
- db
mmgis:
condition: service_healthy
restart: true
db:
condition: service_healthy
restart: true
command: bash -c "bash /tmp/scripts/wait-for-it.sh -t 120 -h db -p 5432 && /start.sh"
volumes:
- ./Missions:/Missions
Expand All @@ -161,9 +193,16 @@ services:
image: postgis/postgis:16-3.4-alpine
env_file: .env
environment:
- POSTGRES_USER=${DB_USER}
- POSTGRES_PASSWORD_OFF=Rename to 'POSTGRES_PASSWORD' and replace this with an initial root password for the DB
ports:
- 5432
healthcheck:
test: ["CMD-SHELL", "pg_isready -d postgres -U ${DB_USER}"]
interval: 10s
retries: 10
start_period: 10s
timeout: 8s
restart: on-failure
volumes:
- mmgis-db:/var/lib/postgresql/data
Expand Down
Loading

0 comments on commit b0554b4

Please sign in to comment.