Forked from jrichardsz/ask_docker_compose_env_vars.sh
Created
February 7, 2026 19:18
-
-
Save bglopez/15015c5024b0b131c41285732bfd65bf to your computer and use it in GitHub Desktop.
bash devops snippets
This file contains hidden or 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
| for line in $(cat docker-compose-integration-tests.yml | tr ' ' '\n' | sort -u | grep -Po '\${.+}' ) | |
| do | |
| var="${line/\$/""}" | |
| var="${var/\{/""}" | |
| var="${var/\}/""}" | |
| var=$(echo "$var" | cut -d ":" -f 1 | xargs) | |
| if [[ -z "${!var}" ]]; then | |
| echo "Enter $var value:" && read _value | |
| export $var=$_value | |
| echo "$var=$_value" >>.env | |
| fi | |
| done |
This file contains hidden or 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
| function download_env_variables { | |
| echo_log "" | |
| echo_log "##### Starting to download environment variables #####" | |
| http_response=$(curl -s -o env_variables -w "%{http_code}" --user ${USER}:${PASSWORD} ${VARIABLES_MANAGER_SERVICE_URL}) | |
| echo_log "## status: $http_response ##" | |
| if [ $http_response == "200" ]; then | |
| cp env_variables /env/ | |
| echo_log "## Exporting Environment Variables ##" | |
| source /env/env_variables | |
| else | |
| echo_log "## New Environment Variables could not be obtained ##" | |
| if [ -e /env/env_variables ]; then | |
| echo_log "## Exporting old env variables ##" | |
| source /env/env_variables | |
| else | |
| echo_log "## Environment file not found in : /env/env_variables ##" | |
| exit 1 | |
| fi | |
| fi | |
| } |
This file contains hidden or 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
| function export_java_env { | |
| java_environments="" | |
| echo_log "## Exporting Java Environment Variables ##" | |
| while IFS='=' read -r name value ; do | |
| if [[ $name == *'JAVA_'* ]] && [[ $name != "JAVA_HOME" ]] && [[ $name != "JAVA_VERSION" ]]; then | |
| java_environments="$java_environments ${!name} "; | |
| fi | |
| done < <(env) | |
| export CATALINA_OPTS="$java_environments" | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment