-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: optimize envs and add support for custom root for data #117
- Loading branch information
Showing
18 changed files
with
175 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,5 @@ repos | |
dockerrepos | ||
playwright-report | ||
test-results | ||
config.yml | ||
secrets.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
#ROOT_PATH=/app | ||
#CUSTOM_REPO_ROOT=/app/repos | ||
#CONFIG_LOCATION=/app/config/config.yml | ||
#SECRETS_LOCATION=/app/config/secrets.yml | ||
DRY_RUN=true # not fully supported yet | ||
LOAD_LOCAL_SAMPLES=false | ||
DEBUG_CREATE_FILES=false | ||
LOG_LEVEL=info | ||
#DRY_RUN=true # not fully supported yet | ||
#LOAD_LOCAL_SAMPLES=false | ||
#DEBUG_CREATE_FILES=false | ||
#LOG_LEVEL=info |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
--- | ||
sidebar_position: 2 | ||
title: Environment Variables | ||
description: "Learn about the environment variables used in our application configuration." | ||
keywords: [environment variables, configuration, setup] | ||
--- | ||
|
||
# Environment Variables | ||
|
||
This document outlines the available environment variables for configuring Configarr besides the config files. | ||
Each variable can be set to customize the behavior of the application. | ||
|
||
## Available Environment Variables | ||
|
||
| Variable Name | Default Value | Required | Description | | ||
| -------------------- | ------------------------- | -------- | ------------------------------------------------------------------------------------------- | | ||
| `LOG_LEVEL` | `"info"` | No | Sets the logging level. Options are `trace`, `debug`, `info`, `warn`, `error`, and `fatal`. | | ||
| `CONFIG_LOCATION` | `"./config/config.yml"` | No | Specifies the path to the configuration file. | | ||
| `SECRETS_LOCATION` | `"./config/secrets.yml"` | No | Specifies the path to the secrets file. | | ||
| `CUSTOM_REPO_ROOT` | `"./repos"` | No | Defines the root directory for custom repositories. | | ||
| `ROOT_PATH` | Current working directory | No | Sets the root path for the application. Defaults to the current working directory. | | ||
| `DRY_RUN` | `"false"` | No | When set to `"true"`, runs the application in dry run mode without making changes. | | ||
| `LOAD_LOCAL_SAMPLES` | `"false"` | No | If `"true"`, loads local sample data for testing purposes. | | ||
| `DEBUG_CREATE_FILES` | `"false"` | No | Enables debugging for file creation processes when set to `"true"`. | | ||
|
||
## Usage | ||
|
||
To use these environment variables, set them in your shell or include them in your deployment configuration via docker or kubernetes. | ||
|
||
## Examples | ||
|
||
- For example you change the default path for all configs, repos with the `ROOT_PATH` variables. | ||
As default it would store them inside the application directory (in the container this is `/app`) | ||
|
||
## References | ||
|
||
Check the `.env.template` file in the repository [Github](https://github.com/raydak-labs/configarr/blob/main/.env.template) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
!config/*.yml | ||
dockerrepos/ | ||
data/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import path from "node:path"; | ||
import { z } from "zod"; | ||
|
||
const DEFAULT_ROOT_PATH = path.resolve(process.cwd()); | ||
|
||
const schema = z.object({ | ||
// NODE_ENV: z.enum(["production", "development", "test"] as const), | ||
LOG_LEVEL: z | ||
.enum(["trace", "debug", "info", "warn", "error", "fatal"] as const) | ||
.optional() | ||
.default("info"), | ||
CONFIG_LOCATION: z.string().optional(), | ||
SECRETS_LOCATION: z.string().optional(), | ||
// TODO: deprecate? | ||
CUSTOM_REPO_ROOT: z.string().optional(), | ||
ROOT_PATH: z.string().optional().default(DEFAULT_ROOT_PATH), | ||
DRY_RUN: z | ||
.string() | ||
.toLowerCase() | ||
.transform((x) => x === "true") | ||
.pipe(z.boolean()) | ||
.default("false"), | ||
LOAD_LOCAL_SAMPLES: z | ||
.string() | ||
.toLowerCase() | ||
.transform((x) => x === "true") | ||
.pipe(z.boolean()) | ||
.default("false"), | ||
DEBUG_CREATE_FILES: z | ||
.string() | ||
.toLowerCase() | ||
.transform((x) => x === "true") | ||
.pipe(z.boolean()) | ||
.default("false"), | ||
}); | ||
|
||
// declare global { | ||
// // eslint-disable-next-line @typescript-eslint/no-namespace | ||
// namespace NodeJS { | ||
// // eslint-disable-next-line @typescript-eslint/no-empty-object-type | ||
// interface ProcessEnv extends z.infer<typeof schema> {} | ||
// } | ||
// } | ||
|
||
let envs: z.infer<typeof schema>; | ||
|
||
export function initEnvs() { | ||
const parsed = schema.safeParse(process.env); | ||
|
||
if (parsed.success === false) { | ||
console.error("Invalid environment variables:", parsed.error.flatten().fieldErrors); | ||
throw new Error("Invalid environment variables."); | ||
} | ||
|
||
envs = parsed.data; | ||
} | ||
|
||
export const getEnvs = () => { | ||
if (envs) return envs; | ||
|
||
envs = schema.parse(process.env); | ||
|
||
return envs; | ||
}; | ||
|
||
export const getHelpers = () => ({ | ||
configLocation: getEnvs().CONFIG_LOCATION ?? `${getEnvs().ROOT_PATH}/config/config.yml`, | ||
secretLocation: getEnvs().SECRETS_LOCATION ?? `${getEnvs().ROOT_PATH}/config/secrets.yml`, | ||
// TODO: check for different env name | ||
repoPath: getEnvs().CUSTOM_REPO_ROOT ?? `${getEnvs().ROOT_PATH}/repos`, | ||
// TODO: add stuff like isDryRun,...? | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.