Skip to content

Commit

Permalink
Move to toolforge build-service
Browse files Browse the repository at this point in the history
This adds:
* Procfile + web.sh to run the web server
* Aptfiles with python as a dependency to serve static files
* http-server module to serve the generated json files
* Used the $TOOl_DATA_DIR in build.js to generate the files in the
  right path.
* Added info in the readme

Signed-off-by: David Caro <me@dcaro.es>
  • Loading branch information
david-caro authored and 1ec5 committed Mar 16, 2024
1 parent 59a591f commit 0a9ba9e
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Aptfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# used to serve the static files
python3
2 changes: 2 additions & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
web: scripts/web.sh
update: scripts/update.sh
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,42 @@ The goal of this project is to provide filtered versions of [Wikimedia's site ma
The data/ directory contains a prettified JSON file and a minified JSON file for each Wikimedia project. The all.json and all.min.json files include all the Wikimedia wikis, including not only the projects that have their own JSON files but also multilingual and special wikis.

To update the JSON files, run `make`.


## Running on toolforge
To run on toolforge log into the tool accounnt:
```
ssh myuser@login.toolforge.org
myuser@tools-sgebastion-10:$ become wmf-sitematrix
wmf-sitematrix@tools-sgebastion-10:$
```

Start a build to pick up the new code
```
wmf-sitematrix@tools-sgebastion-10:$ toolforge build start https://github.com/osmlab/wmf-sitematrix
... takes a minute
```


Start/restart the webservice mounting the NFS:
```
wmf-sitematrix@tools-sgebastion-10:$ toolforge webservice buildservice --mount=all restart
```

And create the job if it's not there to update `public_html/data/*json`:
```
wmf-sitematrix@tools-sgebastion-10:$ toolforge jobs run \
--schedule '0 0 */15 * *' \
--filelog \
--mount=all \
--image tool-wmf-sitematrix/tool-wmf-sitematrix:latest \
--command 'update' \
cron-tools.wmf-sitematrix-1
```

Or restart it if it exists and you want to run it right away:
```
wmf-sitematrix@tools-sgebastion-10:$ toolforge jobs restart cron-tools.wmf-sitematrix-1
```

Otherwise the next run will pull the new code.
2 changes: 1 addition & 1 deletion scripts/build.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var projects = [
];

var fs = require('fs');
let dataPath = "data";
let dataPath = `${process.env.TOOL_DATA_DIR}/public_html/data`;
var data = JSON.parse(fs.readFileSync(`${dataPath}/all.json`, 'utf8'));

console.log("Writing full site matrix...");
Expand Down
12 changes: 12 additions & 0 deletions scripts/update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
DEST_DIR="$TOOL_DATA_DIR/public_html/data"

echo "Updating"

mkdir -p "$DEST_DIR"
wget -O "$DEST_DIR/all.json" 'https://meta.wikimedia.org/w/api.php?action=sitematrix&uselang=en&format=json'

# For the first run in case there's nothing there
cp --update data/*.json "$DEST_DIR/"
node scripts/build.js
echo "Update finished"
6 changes: 6 additions & 0 deletions scripts/web.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

python -m http.server \
--bind "0.0.0.0" \
--directory "$TOOL_DATA_DIR/public_html/data" \
"$PORT"

0 comments on commit 0a9ba9e

Please sign in to comment.