General framework documentation explaining main framework features:
- Configuration files loading management
- Docker namespace usage
- Best practices and recipes
For creating your first binary file, see the Commands documentation.
--- { "slug": "docker-related-articles" } ---
This is the multi-page printable view of this section. Click here to print.
General framework documentation explaining main framework features:
For creating your first binary file, see the Commands documentation.
Inspired by Evan “Hippy” Slatis work
Configuration files loading is following these rules or best practices:
VAR1=value1
VAR1=value2
BASH_FRAMEWORK_LOG_LEVEL="${BASH_FRAMEWORK_LOG_LEVEL:-0}"
Provide –config argument to see resulting config file + information about order of loaded config files for debugging purpose.
It is also possible to use environment variable, but highly discouraged to generalize this practice as it could lead to unwanted results if variables are not well scoped.
The framework function Env::requireLoad loads the following files in this order if they are existing and are readable:
Options can override values provided by these env files:
BASH_FRAMEWORK_DISPLAY_LEVEL to 3 (INFO)BASH_FRAMEWORK_DISPLAY_LEVEL to 4 (DEBUG)Eg: additional environment files
BASH_FRAMEWORK_ENV_FILES=("${HOME}/.bash-tools/.env" "${HOME}/.env")
Eg: framework default values file
BASH_FRAMEWORK_LOG_LEVEL="${BASH_FRAMEWORK_LOG_LEVEL:-0}"
BASH_FRAMEWORK_DISPLAY_LEVEL="${BASH_FRAMEWORK_DISPLAY_LEVEL:-${__LEVEL_WARNING}}"
BASH_FRAMEWORK_LOG_FILE="${BASH_FRAMEWORK_LOG_FILE:-"${FRAMEWORK_ROOT_DIR}/logs/${SCRIPT_NAME}.log"}"
BASH_FRAMEWORK_LOG_FILE_MAX_ROTATION="${BASH_FRAMEWORK_LOG_FILE_MAX_ROTATION:-5}"
Activity diagram to explain how Env::requireLoad is working:
Usage example: try to pull image from 3 tags in order (from more specific or recent to the less one)
# try to pull image from 3 tags in order (from more specific or recent to the less one)
args=(
'id.dkr.ecr.eu-west-1.amazonaws.com/bash-tools:d93e03d5ab9e127647f575855f605bd189ca8a56'
'id.dkr.ecr.eu-west-1.amazonaws.com/bash-tools:branchName'
'id.dkr.ecr.eu-west-1.amazonaws.com/bash-tools:master'
)
digestPulled="$(Docker::pullImage "${args[@]}")"
# build the image using eventual image pulled as cache
# image will be tagged bash-tools:latest upon successful build
args=(
"." ".docker/Dockerfile" "bash-tools"
# it's important to not double quote following instruction
$(Docker::getBuildCacheFromArg ${digestPulled})
# you can add any additional docker build arg as needed
--build-arg USER_ID="$(id -u)"
--build-arg GROUP_ID="$(id -g)"
)
Docker::buildImage "${args[@]}"
# tag the image with a remote tag
args=(
"id.dkr.ecr.eu-west-1.amazonaws.com/bash-tools"
"bash-tools:latest"
# tags list
"branchName" "d93e03d5ab9e127647f575855f605bd189ca8a56"
)
Docker::tagImage "${args[@]}"
# finally push the image
args=(
"id.dkr.ecr.eu-west-1.amazonaws.com/bash-tools"
"bash-tools:latest"
# tags list
"branchName" "d93e03d5ab9e127647f575855f605bd189ca8a56"
)
Docker::pushImage "${args[@]}"
DISCLAIMER: Some of the best practices mentioned are not fully applied in this project as they were written during development.
The @embed keyword is really useful to inline configuration files. However, to run framework functions using sudo, it
is recommended to call the same binary but passing options to change the behavior. This way the content of the script
file does not seem to be obfuscated.
Follow the framework’s naming conventions:
Namespace::functionName pattern# bats test_tags=ubuntu_only for Ubuntu-specific tests