Support RIJU_DEPLOY_CONFIG
This commit is contained in:
parent
bd831fa931
commit
c85ed6d586
|
@ -4,6 +4,29 @@ import process from "process";
|
|||
|
||||
import { v4 as getUUIDOrig } from "uuid";
|
||||
|
||||
function computeImageHashes() {
|
||||
let deployConfig = process.env.RIJU_DEPLOY_CONFIG;
|
||||
if (!deployConfig)
|
||||
return {};
|
||||
deployConfig = JSON.parse(deployConfig);
|
||||
const imageHashes = {};
|
||||
for (const [lang, tag] of Object.entries(deployConfig.langImageTags)) {
|
||||
const prefix = `lang-${lang}-`
|
||||
if (!tag.startsWith(prefix)) {
|
||||
throw new Error(`malformed tag ${tag}`);
|
||||
}
|
||||
const imageHash = tag.slice(prefix.length);
|
||||
if (imageHash.length !== 40) {
|
||||
throw new Error(`malformed tag ${tag}`);
|
||||
}
|
||||
imageHashes[lang] = imageHash;
|
||||
}
|
||||
console.log(imageHashes);
|
||||
return imageHashes;
|
||||
}
|
||||
|
||||
const imageHashes = computeImageHashes();
|
||||
|
||||
export function quote(str) {
|
||||
return "'" + str.replace(/'/g, `'"'"'`) + "'";
|
||||
}
|
||||
|
@ -48,7 +71,11 @@ export async function run(args, log, options) {
|
|||
}
|
||||
|
||||
export function privilegedSession({ uuid, lang }) {
|
||||
return [rijuSystemPrivileged, "session", uuid, lang];
|
||||
const cmdline = [rijuSystemPrivileged, "session", uuid, lang];
|
||||
if (imageHashes[lang]) {
|
||||
cmdline.push(imageHashes[lang]);
|
||||
}
|
||||
return cmdline;
|
||||
}
|
||||
|
||||
export function privilegedExec({ uuid }, args) {
|
||||
|
|
|
@ -22,7 +22,7 @@ void __attribute__ ((noreturn)) die(char *msg)
|
|||
void die_with_usage()
|
||||
{
|
||||
die("usage:\n"
|
||||
" riju-system-privileged session UUID LANG\n"
|
||||
" riju-system-privileged session UUID LANG [IMAGE-HASH]\n"
|
||||
" riju-system-privileged exec UUID CMDLINE...\n"
|
||||
" riju-system-privileged pty UUID CMDLINE...");
|
||||
}
|
||||
|
@ -44,16 +44,28 @@ char *parseLang(char *lang) {
|
|||
return lang;
|
||||
}
|
||||
|
||||
char *parseImageHash(char *imageHash)
|
||||
{
|
||||
if (strnlen(imageHash, 41) != 40)
|
||||
die("illegal imageHash");
|
||||
for (char *ptr = imageHash; *ptr; ++ptr)
|
||||
if (!((*ptr >= 'a' && *ptr <= 'z') || (*ptr >= '0' && *ptr <= '9')))
|
||||
die("illegal imageHash");
|
||||
return imageHash;
|
||||
}
|
||||
|
||||
void wait_alarm(int signum)
|
||||
{
|
||||
(void)signum;
|
||||
die("container did not come up within 1 second");
|
||||
}
|
||||
|
||||
void session(char *uuid, char *lang)
|
||||
void session(char *uuid, char *lang, char *imageHash)
|
||||
{
|
||||
char *image, *container, *hostname, *volume, *fifo;
|
||||
if (asprintf(&image, "riju:lang-%s", lang) < 0)
|
||||
if ((imageHash != NULL ?
|
||||
asprintf(&image, "riju:lang-%s-%s", lang, imageHash) :
|
||||
asprintf(&image, "riju:lang-%s", lang)) < 0)
|
||||
die("asprintf failed");
|
||||
if (asprintf(&container, "riju-session-%s", uuid) < 0)
|
||||
die("asprintf failed");
|
||||
|
@ -157,11 +169,12 @@ int main(int argc, char **argv)
|
|||
if (argc < 2)
|
||||
die_with_usage();
|
||||
if (!strcmp(argv[1], "session")) {
|
||||
if (argc != 4)
|
||||
if (argc < 4 || argc > 5)
|
||||
die_with_usage();
|
||||
char *uuid = parseUUID(argv[2]);
|
||||
char *lang = parseLang(argv[3]);
|
||||
session(uuid, lang);
|
||||
char *imageHash = argc == 5 ? parseImageHash(argv[4]) : NULL;
|
||||
session(uuid, lang, imageHash);
|
||||
return 0;
|
||||
}
|
||||
if (!strcmp(argv[1], "exec")) {
|
||||
|
|
Loading…
Reference in New Issue