Load language configurations into server

This commit is contained in:
Radon Rosborough 2021-03-18 19:03:28 -07:00
parent feb5aad8f0
commit 83208355d4
11 changed files with 28 additions and 29 deletions

View File

@ -5,5 +5,6 @@
**/.lsp-repl-history
**/.terraform
**/build
**/build-docker
**/node_modules
**/out

3
.gitignore vendored
View File

@ -4,5 +4,8 @@
.lsp-repl-history
.terraform
build
# Separate directory for things that are ignored by Git but not by
# Docker.
build-docker
node_modules
out

View File

@ -256,11 +256,11 @@ publish: # Full synchronization and prod deployment
### Miscellaneous
## Run this every time you update .gitignore.
## Run this every time you update .gitignore or .dockerignore.in.
dockerignore: # Update .dockerignore from .gitignore
dockerignore: # Update .dockerignore from .gitignore and .dockerignore.in
echo "# This file is generated by 'make dockerignore', do not edit." > .dockerignore
cat .gitignore | sed 's#^#**/#' >> .dockerignore
cat .gitignore | sed 's/#.*//' | grep . | sed 's#^#**/#' >> .dockerignore
## You need to be inside a 'make env' shell whenever you are running
## manual commands (Docker, Terraform, Packer, etc.) directly, as

View File

@ -3,6 +3,7 @@ import path from "path";
import debounce from "debounce";
import { getLangs, readLangConfig } from "../lib/yaml.js";
import { log } from "./util.js";
// Map from language IDs to language configuration objects. This is
@ -16,24 +17,14 @@ export let aliases = {};
// global langs variable in this module. Never throw an error. If
// there is a problem then just leave the languages as they previously
// were.
async function readLangsFromDisk() {
async function updateLangsFromDisk() {
try {
const newLangs = {};
const newAliases = {};
for (const filename of await fs.readdir("/opt/riju/langs")) {
if (path.parse(filename).ext !== ".json") {
continue;
}
const id = path.parse(filename).name;
const langConfig = JSON.parse(
await fs.readFile(`/opt/riju/langs/${filename}`, "utf-8")
);
if (langConfig.id !== id) {
log.error(
"Language config ${filename} has mismatched language ID ${id}, ignoring"
);
continue;
}
for (const langConfig of await Promise.all(
(await getLangs()).map(readLangConfig)
)) {
const { id } = langConfig;
newLangs[id] = langConfig;
newAliases[id] = id;
for (const alias of langConfig.aliases || []) {
@ -52,6 +43,6 @@ async function readLangsFromDisk() {
}
}
export const langsPromise = readLangsFromDisk().then(() => langs);
export const langsPromise = updateLangsFromDisk().then(() => langs);
fsOrig.watch("/opt/riju/langs", debounce(readLangsFromDisk, 200));
fsOrig.watch("langs", debounce(updateLangsFromDisk, 200));

View File

@ -18,7 +18,9 @@ RUN make frontend
COPY frontend/pages ./frontend/pages/
COPY frontend/styles ./frontend/styles/
COPY lib ./lib/
COPY backend ./backend/
COPY langs ./langs/
FROM ubuntu:rolling

View File

@ -4,7 +4,7 @@ import http from "http";
import { Command } from "commander";
import express from "express";
import { readLangConfig } from "./config.js";
import { readLangConfig } from "../lib/yaml.js";
import { getLocalImageLabel } from "./docker-util.js";
import { hashDockerfile } from "./hash-dockerfile.js";
import { getDebHash, runCommand } from "./util.js";
@ -67,7 +67,9 @@ async function main() {
process.exit(0);
}
main().catch((err) => {
console.error(err);
process.exit(1);
});
if (process.argv[1] === url.fileURLToPath(import.meta.url)) {
main().catch((err) => {
console.error(err);
process.exit(1);
});
}

View File

@ -5,7 +5,7 @@ import url from "url";
import { Command } from "commander";
import YAML from "yaml";
import { readLangConfig, readSharedDepConfig } from "./config.js";
import { readLangConfig, readSharedDepConfig } from "../lib/yaml.js";
// Given a language config object, return the text of a Bash script
// that will build the (unpacked) riju-lang-foo Debian package into

View File

@ -1,7 +1,7 @@
import process from "process";
import url from "url";
import { getPackages } from "./config.js";
import { getPackages } from "../lib/yaml.js";
import { runCommand } from "./util.js";
// Parse command-line arguments, run main functionality, and exit.

View File

@ -7,7 +7,7 @@ import { Command } from "commander";
import _ from "lodash";
import { v4 as getUUID } from "uuid";
import { getLangs, getPackages, readLangConfig } from "./config.js";
import { getLangs, getPackages, readLangConfig } from "../lib/yaml.js";
import {
getLocalImageDigest,
getLocalImageLabel,

View File

@ -7,7 +7,7 @@ import nodePath from "path";
import process from "process";
import url from "url";
import { getPackages } from "./config.js";
import { getPackages } from "../lib/yaml.js";
import { generateBuildScript } from "./generate-build-script.js";
// Parse command-line arguments, run main functionality, and exit.