forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor environment variable processing for Docker (elastic#49612)
Closes elastic#45223. The current Docker entrypoint script picks up environment variables and translates them into -E command line arguments. However, since any tool executes via `docker exec` doesn't run the entrypoint, it results in a poorer user experience. Therefore, refactor the env var handling so that the -E options are generated in `elasticsearch-env`. These have to be appended to any existing command arguments, since some CLI tools have subcommands and -E arguments must come after the subcommand. Also extract the support for `_FILE` env vars into a separate script, so that it can be called from more than once place (the behaviour is idempotent). Finally, add noop -E handling to CronEvalTool for parity, and support `-E` in MultiCommand before subcommands.
- Loading branch information
1 parent
3717c73
commit eec3eb5
Showing
10 changed files
with
193 additions
and
96 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
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,42 @@ | ||
#!/bin/bash | ||
|
||
set -e -o pipefail | ||
|
||
# Allow environment variables to be set by creating a file with the | ||
# contents, and setting an environment variable with the suffix _FILE to | ||
# point to it. This can be used to provide secrets to a container, without | ||
# the values being specified explicitly when running the container. | ||
# | ||
# This script is intended to be sourced, not executed, and modifies the | ||
# environment. | ||
|
||
for VAR_NAME_FILE in $(env | cut -f1 -d= | grep '_FILE$'); do | ||
if [[ -n "$VAR_NAME_FILE" ]]; then | ||
VAR_NAME="${VAR_NAME_FILE%_FILE}" | ||
|
||
if env | grep "^${VAR_NAME}="; then | ||
echo "ERROR: Both $VAR_NAME_FILE and $VAR_NAME are set. These are mutually exclusive." >&2 | ||
exit 1 | ||
fi | ||
|
||
if [[ ! -e "${!VAR_NAME_FILE}" ]]; then | ||
echo "ERROR: File ${!VAR_NAME_FILE} from $VAR_NAME_FILE does not exist" >&2 | ||
exit 1 | ||
fi | ||
|
||
FILE_PERMS="$(stat -c '%a' ${!VAR_NAME_FILE})" | ||
|
||
if [[ "$FILE_PERMS" != "400" && "$FILE_PERMS" != 600 ]]; then | ||
echo "ERROR: File ${!VAR_NAME_FILE} from $VAR_NAME_FILE must have file permissions 400 or 600, but actually has: $FILE_PERMS" >&2 | ||
exit 1 | ||
fi | ||
|
||
echo "Setting $VAR_NAME from $VAR_NAME_FILE at ${!VAR_NAME_FILE}" >&2 | ||
export "$VAR_NAME"="$(cat ${!VAR_NAME_FILE})" | ||
|
||
unset VAR_NAME | ||
# Unset the suffixed environment variable | ||
unset "$VAR_NAME_FILE" | ||
fi | ||
done | ||
|
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
Oops, something went wrong.