Read config values from env
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Fabian Stamm 2020-07-28 15:35:50 +02:00
parent afd98148b2
commit 65f1c52581
4 changed files with 47 additions and 16 deletions

View File

@ -15,4 +15,4 @@ steps:
repo: hibas123.azurecr.io/denreg
registry: hibas123.azurecr.io
dockerfile: registry/Dockerfile
debug: true
debug: false

1
registry/.gitignore vendored
View File

@ -1 +1,2 @@
tmp/
data/

View File

@ -2,9 +2,47 @@ import { Ini } from "./deps.ts";
const config =
Ini.decode(
await Deno.readFile("./data/config.ini").then((e) =>
new TextDecoder().decode(e)
)
await Deno.readFile("./data/config.ini")
.then((e) => new TextDecoder().decode(e))
.catch((err) => {
if (!(err instanceof Deno.errors.NotFound)) {
throw err;
}
return "";
})
) || {};
const env = Deno.env.toObject();
for (const key in env) {
if (key.startsWith("DENREG_")) {
const stripped = key.slice(7);
if (stripped.startsWith("USER_")) {
const username = stripped.slice(5);
const password = env[key];
config.user = config.user || {};
config.user[username] = { password };
} else {
switch (stripped) {
case "S3_ENDPOINT":
config.s3 = { ...(config.s3 || {}), endpoint: env[key] };
break;
case "S3_BUCKET":
config.s3 = { ...(config.s3 || {}), bucket: env[key] };
break;
case "S3_ACCESS":
config.s3 = { ...(config.s3 || {}), accessKey: env[key] };
break;
case "S3_SECRET":
config.s3 = { ...(config.s3 || {}), secretKey: env[key] };
break;
}
}
}
}
console.log("Known users:", Object.keys(config.user));
export default config;

View File

@ -1,18 +1,10 @@
const ensureDir = async (name: string) => {
if (
!(await Deno.stat(name)
.then(() => true)
.catch(() => false))
) {
await Deno.mkdir(name);
}
};
import { FS } from "./deps.ts";
try {
await Deno.remove("./tmp", { recursive: true });
Deno.removeSync("./tmp", { recursive: true });
} catch (err) {}
await ensureDir("./tmp");
await ensureDir("./data");
FS.ensureDirSync("./tmp");
FS.ensureDirSync("./data");
import "./http.ts";