From 5c669bcce92de6c4b3ef9f89a66dbd751b10e19f Mon Sep 17 00:00:00 2001 From: cupcakearmy Date: Sun, 28 Nov 2021 17:48:50 +0100 Subject: [PATCH] docs for storage envs --- README.md | 53 ++++++++++++++++++++++------ scripts/generate_markdown_tables.mjs | 20 +++++++++++ src/config.ts | 15 ++++---- src/storage/index.ts | 2 +- 4 files changed, 73 insertions(+), 17 deletions(-) create mode 100644 scripts/generate_markdown_tables.mjs diff --git a/README.md b/README.md index 6c0866d..6788a44 100644 --- a/README.md +++ b/README.md @@ -76,16 +76,49 @@ Config files are searched in the current working directory under `morphus.yaml`. Configuration can be done either thorough config files or env variables. The usage of a config file is recommended. Below is a table of available configuration options, for more details see below. -| Config | Environment | Default | Description | -| ---------------- | ---------------- | ---------- | -------------------------------------------------------------------------------------- | -| `port` | `PORT` | 80 | The port to bind | -| `address` | `ADDRESS` | 127.0.0.1 | The address to bind | -| `allowedDomains` | `ALLOWED_DOMAIN` | null | The domains that are allowed to be used as image sources | -| `allowedHosts` | `ALLOWED_HOSTS` | null | The hosts that are allowed to access the images | -| `cleanUrls` | `CLEAN_URL` | Fragment | Whether source URLs are cleaned | -| `maxAge` | `MAX_AGE` | 1d | How long the served images are marked as cached, after that ETag is used to revalidate | -| `storage` | `STORAGE` | Local | The storage driver to use | -| `local_assets` | `LOCAL_ASSETS` | `./assets` | Directory where the local storage driver persists files | +| Config | Environment | Default | Description | +| ---------------- | ---------------- | --------- | -------------------------------------------------------------------------------------- | +| `port` | `PORT` | 80 | The port to bind | +| `address` | `ADDRESS` | 127.0.0.1 | The address to bind | +| `allowedDomains` | `ALLOWED_DOMAIN` | null | The domains that are allowed to be used as image sources | +| `allowedHosts` | `ALLOWED_HOSTS` | null | The hosts that are allowed to access the images | +| `cleanUrls` | `CLEAN_URL` | Fragment | Whether source URLs are cleaned | +| `maxAge` | `MAX_AGE` | 1d | How long the served images are marked as cached, after that ETag is used to revalidate | +| `storage` | `STORAGE` | `local` | The storage driver to use. Possible values: `local`, `minio`, `s3`, `gcs`. | + +### Storage Drivers + +#### Local + +| Config | Environment | Default | Description | +| -------------- | -------------- | -------- | ----------------------------- | +| `local.assets` | `LOCAL_ASSETS` | ./assets | The path to the assets folder | + +#### Minio + +| Config | Environment | Default | Description | +| ----------------- | ------------------ | ------- | --------------------------- | +| `minio.accessKey` | `MINIO_ACCESS_KEY` | | The access key for Minio | +| `minio.secretKey` | `MINIO_SECRET_KEY` | | The secret key for Minio | +| `minio.endpoint` | `MINIO_ENDPOINT` | | The endpoint for Minio | +| `minio.bucket` | `MINIO_BUCKET` | | The bucket to use for Minio | +| `minio.region` | `MINIO_REGION` | | The region for Minio | + +#### AWS S3 + +| Config | Environment | Default | Description | +| -------------- | ---------------------- | ------- | ------------------------------- | +| `s3.bucket` | `S3_BUCKET` | | The S3 bucket to use | +| `s3.region` | `S3_REGION` | | The S3 region to use | +| `s3.accessKey` | `S3_ACCESS_KEY_ID` | | The S3 access key id to use | +| `s3.secretKey` | `S3_SECRET_ACCESS_KEY` | | The S3 secret access key to use | + +#### Google Cloud Storage + +| Config | Environment | Default | Description | +| ----------------- | ------------------ | ------- | ----------------------- | +| `gcs.bucket` | `GCS_BUCKET` | | The GCS bucket to use | +| `gcs.keyFilename` | `GCS_KEY_FILENAME` | | The GCS key file to use | ### Allowed Domains diff --git a/scripts/generate_markdown_tables.mjs b/scripts/generate_markdown_tables.mjs new file mode 100644 index 0000000..78addd9 --- /dev/null +++ b/scripts/generate_markdown_tables.mjs @@ -0,0 +1,20 @@ +import { config, StorageType } from '../dist/src/config.js' + +const schema = config._def + +function stringAsMarkdownCode(string) { + return '`' + string + '`' +} + +for (const storage of Object.values(StorageType)) { + const storageType = schema[storage] + let table = ` + | Config | Environment | Default | Description | + | ---------------- | ------------------ | ------- | ------------------------ | + ` + for (const [key, value] of Object.entries(storageType)) { + table += `| \`${storage}.${key}\` | \`${value.env}\` | ${value.default} | ${value.doc} |\n` + } + + console.log(table) +} diff --git a/src/config.ts b/src/config.ts index 58e44f0..aa9704a 100644 --- a/src/config.ts +++ b/src/config.ts @@ -40,7 +40,8 @@ function formatNullableStringOrRegexpArray(values: any) { } convict.addParser({ extension: ['yml', 'yaml'], parse: (s) => yaml.load(s, { schema: Schema }) }) -const config = convict({ + +export const config = convict({ // Server port: { doc: 'The port to bind.', @@ -101,11 +102,13 @@ const config = convict({ }, // Local storage - localAssets: { - doc: 'The path to the assets folder', - format: String, - default: './assets', - env: 'LOCAL_ASSETS', + local: { + assets: { + doc: 'The path to the assets folder', + format: String, + default: './assets', + env: 'LOCAL_ASSETS', + }, }, // Minio storage diff --git a/src/storage/index.ts b/src/storage/index.ts index c53c106..6035d25 100644 --- a/src/storage/index.ts +++ b/src/storage/index.ts @@ -22,7 +22,7 @@ export async function init(App: FastifyInstance) { if (!storage) { switch (Config.storage) { case StorageType.Local: - storage = new Local(Config.localAssets) + storage = new Local(Config.local.assets) break case StorageType.S3: storage = new Minio({