Skip to content

Commit

Permalink
Export database credentials to env WIP 2
Browse files Browse the repository at this point in the history
  • Loading branch information
dasscheman committed Jun 25, 2024
1 parent 3f51934 commit 2965d6e
Show file tree
Hide file tree
Showing 7 changed files with 427 additions and 46 deletions.
10 changes: 5 additions & 5 deletions config/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', getenv('OPENSHIFT_MYSQL_DB_HOST')),
'database' => env('DB_DATABASE', getenv('OPENSHIFT_APP_NAME')),
'username' => env('DB_USERNAME', getenv('OPENSHIFT_MYSQL_DB_USERNAME')),
'password' => env('DB_PASSWORD', getenv('OPENSHIFT_MYSQL_DB_PASSWORD')),
'port' => env('DB_PORT', getenv('OPENSHIFT_MYSQL_DB_PORT')),
'host' => env('DB_HOST', getenv('LARAVEL_DATABASE_HOST')),
'database' => env('DB_DATABASE', getenv('LARAVEL_DATABASE_NAME')),
'username' => env('DB_USERNAME', getenv('LARAVEL_DATABASE_USER')),
'password' => env('DB_PASSWORD', getenv('LARAVEL_DATABASE_PASSWORD')),
'port' => env('DB_PORT', getenv('LARAVEL_DATABASE_PORT_NUMBER')),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
Expand Down
1 change: 1 addition & 0 deletions openshift/openshift-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pwd

/var/www/openshift/scripts/setup.sh


# run artisan migrate & seed
echo "⭐️ Run artisan migrate";
php artisan migrate --seed
Expand Down
38 changes: 0 additions & 38 deletions openshift/scripts/liblaravel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,41 +41,3 @@ laravel_validate() {

return "$error_code"
}

########################
# Ensure the Laravel app is initialized
# Globals:
# None
# Arguments:
# None
# Returns:
# None
#########################
laravel_initialize() {
if is_dir_empty "/app"; then
info "Creating Laravel application in /app"
cp -r "${LARAVEL_BASE_DIR}/." .

info "Regenerating APP_KEY"
debug_execute php artisan key:generate --ansi

if ! is_boolean_yes "$LARAVEL_SKIP_COMPOSER_UPDATE"; then
log "Updating dependencies"
debug_execute composer update
fi

info "Trying to connect to the database server"
if ! retry_while "debug_execute wait-for-port --timeout 5 --host ${LARAVEL_DATABASE_HOST} ${LARAVEL_DATABASE_PORT_NUMBER}"; then
error "Could not connect to the database"
return 1
fi

info "Executing database migrations"
debug_execute php artisan migrate
else
info "An existing project was detected, skipping project creation"
fi

# Avoid exit code of previous commands to affect the result of this function
true
}
114 changes: 114 additions & 0 deletions openshift/scripts/liblog.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#!/bin/bash
# Copyright Broadcom, Inc. All Rights Reserved.
# SPDX-License-Identifier: APACHE-2.0
#
# Library for logging functions

# Constants
RESET='\033[0m'
RED='\033[38;5;1m'
GREEN='\033[38;5;2m'
YELLOW='\033[38;5;3m'
MAGENTA='\033[38;5;5m'
CYAN='\033[38;5;6m'

# Functions

########################
# Print to STDERR
# Arguments:
# Message to print
# Returns:
# None
#########################
stderr_print() {
# 'is_boolean_yes' is defined in libvalidations.sh, but depends on this file so we cannot source it
local bool="${BITNAMI_QUIET:-false}"
# comparison is performed without regard to the case of alphabetic characters
shopt -s nocasematch
if ! [[ "$bool" = 1 || "$bool" =~ ^(yes|true)$ ]]; then
printf "%b\\n" "${*}" >&2
fi
}

########################
# Log message
# Arguments:
# Message to log
# Returns:
# None
#########################
log() {
stderr_print "${CYAN}${MODULE:-} ${MAGENTA}$(date "+%T.%2N ")${RESET}${*}"
}
########################
# Log an 'info' message
# Arguments:
# Message to log
# Returns:
# None
#########################
info() {
log "${GREEN}INFO ${RESET} ==> ${*}"
}
########################
# Log message
# Arguments:
# Message to log
# Returns:
# None
#########################
warn() {
log "${YELLOW}WARN ${RESET} ==> ${*}"
}
########################
# Log an 'error' message
# Arguments:
# Message to log
# Returns:
# None
#########################
error() {
log "${RED}ERROR${RESET} ==> ${*}"
}
########################
# Log a 'debug' message
# Globals:
# BITNAMI_DEBUG
# Arguments:
# None
# Returns:
# None
#########################
debug() {
# 'is_boolean_yes' is defined in libvalidations.sh, but depends on this file so we cannot source it
local bool="${BITNAMI_DEBUG:-false}"
# comparison is performed without regard to the case of alphabetic characters
shopt -s nocasematch
if [[ "$bool" = 1 || "$bool" =~ ^(yes|true)$ ]]; then
log "${MAGENTA}DEBUG${RESET} ==> ${*}"
fi
}

########################
# Indent a string
# Arguments:
# $1 - string
# $2 - number of indentation characters (default: 4)
# $3 - indentation character (default: " ")
# Returns:
# None
#########################
indent() {
local string="${1:-}"
local num="${2:?missing num}"
local char="${3:-" "}"
# Build the indentation unit string
local indent_unit=""
for ((i = 0; i < num; i++)); do
indent_unit="${indent_unit}${char}"
done
# shellcheck disable=SC2001
# Complex regex, see https://github.com/koalaman/shellcheck/wiki/SC2001#exceptions
echo "$string" | sed "s/^/${indent_unit}/"
}
Loading

0 comments on commit 2965d6e

Please sign in to comment.