-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added simple api to launch scripts, docker / compose test files
- Loading branch information
Showing
17 changed files
with
589 additions
and
179 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
This file contains 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 |
---|---|---|
|
@@ -69,5 +69,3 @@ compile_processed_data( | |
mostRecent = TRUE | ||
) | ||
|
||
|
||
browser() |
This file contains 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 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 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,19 @@ | ||
FROM fredmoser/accessmod:5.8.3-alpha.1 | ||
|
||
RUN apk add --no-cache nodejs npm | ||
|
||
# context = parent ! | ||
COPY helpers /helpers | ||
COPY 04_travel_time /run | ||
COPY api /api | ||
|
||
|
||
WORKDIR /api | ||
RUN npm install | ||
|
||
|
||
VOLUME /data | ||
|
||
EXPOSE 3000 | ||
|
||
CMD ["node", "app.js"] |
This file contains 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,72 @@ | ||
import express from "express"; | ||
import { getListLocations, computeTravelTime } from "./helpers.js"; | ||
import { TifContour } from "./contour.js"; | ||
const app = express(); | ||
const port = process.env.NODE_ENV === "development" ? 3030 : 3000; | ||
|
||
import path from "path"; | ||
import { fileURLToPath } from "url"; | ||
|
||
const __filename = fileURLToPath(import.meta.url); | ||
const __dirname = path.dirname(__filename); | ||
|
||
app.use(express.json()); | ||
app.use("/data/location", express.static("/data/location")); | ||
|
||
app.get("/data/location/*", (req, res) => { | ||
const filePath = path.join(__dirname, "data/location", req.params[0]); | ||
res.sendFile(filePath, (err) => { | ||
if (err) { | ||
res.status(404).send(`File not found at ${filePath}`); | ||
} | ||
}); | ||
}); | ||
|
||
// GET endpoint to list available locations | ||
app.get("/get_list_locations", async (_, res) => { | ||
try { | ||
const locations = await getListLocations(); | ||
res.json(locations); | ||
} catch (error) { | ||
res.status(500).json({ error: error.message }); | ||
} | ||
}); | ||
|
||
// POST endpoint to compute travel time | ||
app.post("/compute_travel_time", async (req, res) => { | ||
const { location, scenario, add_contours } = req.body; | ||
|
||
try { | ||
const locations = await getListLocations(); | ||
|
||
if (!locations.includes(location)) { | ||
throw new Error( | ||
`Location ${location} is not yet available, come back later` | ||
); | ||
} | ||
|
||
const output = await computeTravelTime(location, scenario); | ||
|
||
if (add_contours) { | ||
const cc = new TifContour({ | ||
thresholds: output.thresholds, | ||
raster: output.travel_time, | ||
proj4: output.proj_4, | ||
}); | ||
output.contours = await cc.render(); | ||
} | ||
|
||
res.json({ | ||
message: "Travel time computation completed", | ||
data: output, | ||
}); | ||
} catch (error) { | ||
debugger; | ||
console.error("Error computing travel time:", error); | ||
res.status(500).json({ error: "Error running AccessMod scripts" }); | ||
} | ||
}); | ||
|
||
app.listen(port, () => { | ||
console.log(`Server running at http://localhost:${port}`); | ||
}); |
This file contains 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,8 @@ | ||
#!/bin/bash | ||
|
||
docker build --push \ | ||
--platform linux/amd64,linux/arm64 \ | ||
-t fredmoser/accessmod_api:latest \ | ||
-f ./Dockerfile \ | ||
.. | ||
|
This file contains 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,55 @@ | ||
services: | ||
accessmod_api: | ||
image: fredmoser/accessmod_api:latest | ||
container_name: accessmod_api | ||
restart: unless-stopped | ||
healthcheck: | ||
test: ["CMD", "wget", "--spider", "http://localhost:3000/get_list_locations"] | ||
interval: 5s | ||
timeout: 60s | ||
retries: 10 | ||
start_period: 10s | ||
ports: | ||
- "3000:3000" | ||
volumes: | ||
- /home/accessmod/data:/data | ||
networks: | ||
- traefik-network | ||
|
||
traefik: | ||
image: traefik:3.0.4 | ||
container_name: traefik | ||
restart: unless-stopped | ||
ports: | ||
- "80:80" | ||
- "443:443" | ||
volumes: | ||
- /var/run/docker.sock:/var/run/docker.sock | ||
- traefik-volume:/etc/traefik | ||
command: | ||
- "--entrypoints.web.address=:80" | ||
- "--entrypoints.websecure.address=:443" | ||
- "--certificatesresolvers.letsencrypt.acme.tlschallenge=true" | ||
- "--certificatesresolvers.letsencrypt.acme.email=${EMAIL}" | ||
- "--certificatesresolvers.letsencrypt.acme.storage=/etc/traefik/acme.json" | ||
- "--providers.docker=true" | ||
- "--providers.docker.exposedbydefault=false" | ||
- "--log.level=INFO" | ||
- "--accesslog=true" | ||
- "--entrypoints.web.http.redirections.entrypoint.to=websecure" | ||
- "--entrypoints.web.http.redirections.entrypoint.scheme=https" | ||
|
||
labels: | ||
- "traefik.enable=true" | ||
- "traefik.http.routers.accessmod.rule=Host(`accessmod.mapx.org`)" | ||
- "traefik.http.routers.accessmod.entrypoints=websecure" | ||
- "traefik.http.routers.accessmod.tls=true" | ||
- "traefik.http.routers.accessmod.tls.certresolver=letsencrypt" | ||
- "traefik.http.services.accessmod.loadbalancer.server.port=3000" | ||
|
||
networks: | ||
traefik-network: | ||
external: true | ||
|
||
volumes: | ||
traefik-volume: |
Oops, something went wrong.