diff --git a/.drone.yml b/.drone.yml index 2aee469..d86b356 100644 --- a/.drone.yml +++ b/.drone.yml @@ -15,4 +15,4 @@ steps: repo: hibas123.azurecr.io/denreg registry: hibas123.azurecr.io dockerfile: registry/Dockerfile - debug: true + debug: false diff --git a/registry/.gitignore b/registry/.gitignore index 3fec32c..60cd341 100644 --- a/registry/.gitignore +++ b/registry/.gitignore @@ -1 +1,2 @@ tmp/ +data/ diff --git a/registry/src/config.ts b/registry/src/config.ts index 9a9c8c2..2a9da21 100644 --- a/registry/src/config.ts +++ b/registry/src/config.ts @@ -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; diff --git a/registry/src/registry.ts b/registry/src/registry.ts index 7b5347d..3141458 100644 --- a/registry/src/registry.ts +++ b/registry/src/registry.ts @@ -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";