From 0a9ba9ef7e14c4a8d9703043bbcd16aaed44fbde Mon Sep 17 00:00:00 2001 From: David Caro Date: Wed, 13 Mar 2024 15:45:49 +0100 Subject: [PATCH] Move to toolforge build-service 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 --- Aptfile | 2 ++ Procfile | 2 ++ README.md | 39 +++++++++++++++++++++++++++++++++++++++ scripts/build.js | 2 +- scripts/update.sh | 12 ++++++++++++ scripts/web.sh | 6 ++++++ 6 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 Aptfile create mode 100644 Procfile mode change 100644 => 100755 scripts/build.js create mode 100755 scripts/update.sh create mode 100755 scripts/web.sh diff --git a/Aptfile b/Aptfile new file mode 100644 index 0000000..ea713b8 --- /dev/null +++ b/Aptfile @@ -0,0 +1,2 @@ +# used to serve the static files +python3 diff --git a/Procfile b/Procfile new file mode 100644 index 0000000..f3564f5 --- /dev/null +++ b/Procfile @@ -0,0 +1,2 @@ +web: scripts/web.sh +update: scripts/update.sh diff --git a/README.md b/README.md index 77bca99..3300bbe 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/scripts/build.js b/scripts/build.js old mode 100644 new mode 100755 index bfe083f..258857c --- a/scripts/build.js +++ b/scripts/build.js @@ -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..."); diff --git a/scripts/update.sh b/scripts/update.sh new file mode 100755 index 0000000..63ce31c --- /dev/null +++ b/scripts/update.sh @@ -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" diff --git a/scripts/web.sh b/scripts/web.sh new file mode 100755 index 0000000..12eab56 --- /dev/null +++ b/scripts/web.sh @@ -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"