From c15991458cad08e881c3fd830a0a2e9af126d717 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=D0=B0ramtamt=C4=81m?= <7326800+tarampampam@users.noreply.github.com> Date: Sat, 6 Jul 2024 03:01:17 -0700 Subject: [PATCH] Add env variable ADD_TEMPLATE (#295) --- Dockerfile | 9 ++++----- README.md | 4 ++-- internal/cli/shared/flags.go | 1 + internal/cli/shared/flags_test.go | 1 + 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index fbabb340..4c2bbbcb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -91,13 +91,12 @@ WORKDIR /opt # to find out which environment variables and CLI arguments are supported by the application, run the app # with the `--help` flag or refer to the documentation at https://github.com/tarampampam/error-pages#readme -ENV LOG_LEVEL="warn" +ENV LOG_LEVEL="warn" \ + LOG_FORMAT="json" # docs: https://docs.docker.com/reference/dockerfile/#healthcheck -HEALTHCHECK --interval=10s --start-interval=1s --start-period=5s --timeout=2s CMD [\ - "/bin/error-pages", "--log-format", "json", "healthcheck" \ -] +HEALTHCHECK --interval=10s --start-interval=1s --start-period=5s --timeout=2s CMD ["/bin/error-pages", "healthcheck"] ENTRYPOINT ["/bin/error-pages"] -CMD ["--log-format", "json", "serve"] +CMD ["serve"] diff --git a/README.md b/README.md index ddf1b094..53436a6e 100644 --- a/README.md +++ b/README.md @@ -665,7 +665,7 @@ The following flags are supported: |------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:-----------------------------------------:|:---------------------------:| | `--listen="…"` (`-l`) | The HTTP server will listen on this IP (v4 or v6) address (set 127.0.0.1/::1 for localhost, 0.0.0.0 to listen on all interfaces, or specify a custom IP) | `0.0.0.0` | `LISTEN_ADDR` | | `--port="…"` (`-p`) | The TCP port number for the HTTP server to listen on (0-65535) | `8080` | `LISTEN_PORT` | -| `--add-template="…"` | To add a new template, provide the path to the file using this flag (the filename without the extension will be used as the template name) | `[]` | *none* | +| `--add-template="…"` | To add a new template, provide the path to the file using this flag (the filename without the extension will be used as the template name) | `[]` | `ADD_TEMPLATE` | | `--disable-template="…"` | Disable the specified template by its name (useful to disable the built-in templates and use only custom ones) | `[]` | *none* | | `--add-code="…"` | To add a new HTTP status code, provide the code and its message/description using this flag (the format should be '%code%=%message%/%description%'; the code may contain a wildcard '*' to cover multiple codes at once, for example, '4**' will cover all 4xx codes unless a more specific code is described previously) | `map[]` | *none* | | `--json-format="…"` | Override the default error page response in JSON format (Go templates are supported; the error page will use this template if the client requests JSON content type) | | `RESPONSE_JSON_FORMAT` | @@ -695,7 +695,7 @@ The following flags are supported: | Name | Description | Default value | Environment variables | |---------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:-------------:|:----------------------:| -| `--add-template="…"` | To add a new template, provide the path to the file using this flag (the filename without the extension will be used as the template name) | `[]` | *none* | +| `--add-template="…"` | To add a new template, provide the path to the file using this flag (the filename without the extension will be used as the template name) | `[]` | `ADD_TEMPLATE` | | `--disable-template="…"` | Disable the specified template by its name (useful to disable the built-in templates and use only custom ones) | `[]` | *none* | | `--add-code="…"` | To add a new HTTP status code, provide the code and its message/description using this flag (the format should be '%code%=%message%/%description%'; the code may contain a wildcard '*' to cover multiple codes at once, for example, '4**' will cover all 4xx codes unless a more specific code is described previously) | `map[]` | *none* | | `--disable-l10n` | Disable localization of error pages (if the template supports localization) | `false` | `DISABLE_L10N` | diff --git a/internal/cli/shared/flags.go b/internal/cli/shared/flags.go index 1e448233..430072ef 100644 --- a/internal/cli/shared/flags.go +++ b/internal/cli/shared/flags.go @@ -67,6 +67,7 @@ var AddTemplatesFlag = cli.StringSliceFlag{ Usage: "To add a new template, provide the path to the file using this flag (the filename without the extension " + "will be used as the template name)", Config: cli.StringConfig{TrimSpace: true}, + Sources: cli.EnvVars("ADD_TEMPLATE"), Category: CategoryTemplates, Validator: func(paths []string) error { for _, path := range paths { diff --git a/internal/cli/shared/flags_test.go b/internal/cli/shared/flags_test.go index e3813446..9ed6dc7b 100644 --- a/internal/cli/shared/flags_test.go +++ b/internal/cli/shared/flags_test.go @@ -91,6 +91,7 @@ func TestAddTemplatesFlag(t *testing.T) { var flag = shared.AddTemplatesFlag assert.Equal(t, "add-template", flag.Name) + assert.Contains(t, flag.Sources.String(), "ADD_TEMPLATE") for wantErrMsg, giveValue := range map[string][]string{ "missing template path": {""},