Skip to content

Commit

Permalink
Merge pull request #13 from SerhiiMazurBeetroot/develop
Browse files Browse the repository at this point in the history
Develop 2.0.6
  • Loading branch information
SerhiiMazurBeetroot authored Aug 30, 2024
2 parents 82b56f0 + f070acb commit c7b2a3e
Show file tree
Hide file tree
Showing 24 changed files with 387 additions and 224 deletions.
2 changes: 2 additions & 0 deletions .env-core/sh/core/available_projects.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export PROJECT_TITLES=(
"PHP-Server"
"Next.js"
"Directus"
"Elastic Stack"
"Directus + Next.js"
"Next.WP"
"Node.js"
Expand All @@ -18,4 +19,5 @@ export AVAILABLE_PROJECTS=(
"php"
"nextjs"
"directus"
"elasticsearch"
)
73 changes: 55 additions & 18 deletions .env-core/sh/core/core_notice.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,34 +27,71 @@ notice_windows_host() {

notice_project_urls() {
OPEN_LINK=$1
get_unique_frontport

ECHO_INFO "Project URLs:"
ECHO_KEY_VALUE "DOMAIN_FULL:" "https://$DOMAIN_FULL"
if [[ "$OPEN_LINK" == 'open' ]]; then
ECHO_INFO "Project URLs:"

if [[ $PORT_FRONT =~ ^[0-9]+$ && $PORT_FRONT -ne 0 ]]; then
ECHO_KEY_VALUE "DOMAIN_FRONT:" "http://localhost:$PORT_FRONT"
fi
URLkeys=("DOMAIN_FULL" "DOMAIN_FRONT" "DOMAIN_ADMIN" "DOMAIN_DB" "DOMAIN_MAIL")
for key in "${URLkeys[@]}"; do
value="${!key}"

if [[ $DOMAIN_ADMIN != "" ]]; then
ECHO_KEY_VALUE "DOMAIN_ADMIN:" "https://$DOMAIN_ADMIN"
fi
if [[ -n "$value" ]]; then
ECHO_KEY_VALUE "$key:" "https://$value"
fi
done

if [[ $DOMAIN_DB != "" ]]; then
ECHO_KEY_VALUE "DOMAIN_DB:" "https://$DOMAIN_DB"
fi
notice_project_ips "$OPEN_LINK"

if [[ $DOMAIN_MAIL != "" ]]; then
ECHO_KEY_VALUE "DOMAIN_MAIL:" "https://$DOMAIN_MAIL"
if command -v google-chrome &>/dev/null; then
google-chrome "https://$DOMAIN_FULL" || true
else
echo "Google Chrome is not installed. Skipping opening URL."
fi
fi
}

if [[ $OPEN_LINK == 'open' ]]; then
google-chrome $DOMAIN_FULL || true
fi
notice_project_ips() {
OPEN_LINK=$1

ECHO_INFO "Project IPs:"

case $PROJECT_TYPE in
"wordpress" | "projects")
services=(
"wordpress:" #don't need port here
)
;;
"elasticsearch")
services=(
"elasticsearch:9200"
"kibana:5601"
)
;;
esac

for service_info in "${services[@]}"; do
service=${service_info%%:*}
port=${service_info#*:}

get_docker_ip "$DOMAIN_NAME-$service"

if [[ -n "$DOCKER_IP" ]]; then
DOMAIN=$(echo "$service" | tr '[:lower:]' '[:upper:]')

if [ -n "$port" ]; then
URL="$DOCKER_IP:$port"
else
URL="$DOCKER_IP"
fi
ECHO_KEY_VALUE "DOMAIN_$DOMAIN:" "http://$URL"
fi
done

env_file_load "update"
}

notice_project_vars() {
OPEN_LINK=$1
local OPEN_LINK=$1
ECHO_INFO "Project variables:"

ECHO_KEY_VALUE "PROJECT_TYPE:" "$PROJECT_TYPE"
Expand Down
4 changes: 4 additions & 0 deletions .env-core/sh/projects/actions/actions_new_project.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ actions_new_project() {
docker_create_directus
unset_variables "PROJECT_TYPE"
;;
"elasticsearch")
docker_create_elastic
unset_variables "PROJECT_TYPE"
;;
esac
;;
esac
Expand Down
13 changes: 13 additions & 0 deletions .env-core/sh/projects/database/database_helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,16 @@ get_mysql_cmd() {
db_file_find_and_replace() {
sed -i -e 's/utf8mb4_0900_ai_ci/utf8mb4_unicode_520_ci/g' "$PROJECT_DATABASE_DIR/$DB_FILE"
}

wait_for_db() {
EMPTY_LINE
env_file_load
get_mysql_cmd

docker exec -i "$DOCKER_CONTAINER_DB" sh -c "
until $MYSQL_CMD -uroot -p\"$MYSQL_ROOT_PASSWORD\" -D $DB_NAME -e '\q'; do
>&2 echo '$MYSQL_CMD is unavailable - waiting...'
sleep 2
done
"
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ docker_create_bedrock() {
ECHO_INFO "Setting up Docker containers for $DOMAIN_FULL"

#GET PORT
get_unique_port
get_all_ports

get_project_dir "skip_question"

Expand All @@ -26,7 +26,7 @@ docker_create_bedrock() {
mkdir -p $PROJECT_ROOT_DIR

# Clone templates files
git clone $TEMPLATES_REPO-$PROJECT_TYPE.git $PROJECT_ROOT_DIR --depth 1
git_clone_templates_files

# Rename files
replace_templates_files
Expand All @@ -46,6 +46,11 @@ docker_create_bedrock() {
setup_hosts_file add
fix_permissions
notice_windows_host add

wait_for_db
wp_core_install
wp_site_empty

docker_restart

# TODO: add clone
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ docker_create_directus() {
ECHO_INFO "Setting up Docker containers for $DOMAIN_FULL"

#GET PORT
get_unique_port

#GET PORT_FRONT
set_unique_frontport
get_all_ports

get_project_dir "skip_question"

Expand All @@ -31,7 +28,7 @@ docker_create_directus() {
mkdir -p $PROJECT_ROOT_DIR

# Clone templates files
git clone $TEMPLATES_REPO-$PROJECT_TYPE.git $PROJECT_ROOT_DIR --depth 1
git_clone_templates_files

# Rename files
replace_templates_files
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/bash

set -o errexit #to stop the script when an error occurs
set -o pipefail

docker_create_elastic() {
unset_variables

if [ $NGINX_EXISTS -eq 1 ]; then
get_domain_name
check_domain_exists

if [[ $DOMAIN_EXISTS == 0 ]]; then
get_project_dir ""
set_project_args
check_data_before_continue_callback docker_create_elastic

ECHO_INFO "Setting up Docker containers for $DOMAIN_FULL"

#GET PORT
get_all_ports

print_to_file_instances

# Create DIR
mkdir -p $PROJECT_ROOT_DIR

# Clone templates files
git_clone_templates_files

# Rename files
replace_templates_files

# Replace Variables
replace_variables

# Load env
env_file_load "create"

ECHO_GREEN "Docker compose file set and container can be built and started"
ECHO_TEXT "Starting Container"
docker_compose_runner "up -d --build"

ECHO_SUCCESS "Containers Started"

setup_hosts_file add
fix_permissions
notice_windows_host add
docker_restart

edit_file_gitignore

# Print for user project info
notice_project_vars "open" "ip"
else
ECHO_ERROR "Site already exists"
docker_create_elastic
fi
else
ECHO_ERROR "Nginx container not running"
nginx_actions
fi
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ docker_create_nextjs() {
ECHO_INFO "Setting up Docker containers for $DOMAIN_FULL"

#GET PORT
get_unique_port
get_all_ports
export PORT_FRONT=$PORT

get_project_dir "skip_question"
Expand All @@ -29,7 +29,7 @@ docker_create_nextjs() {
mkdir -p $PROJECT_ROOT_DIR

# Clone templates files
git clone $TEMPLATES_REPO-$PROJECT_TYPE.git $PROJECT_ROOT_DIR --depth 1
git_clone_templates_files

# Rename files
replace_templates_files
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ docker_create_nodejs() {
ECHO_INFO "Setting up Docker containers for $DOMAIN_FULL"

#GET PORT
get_unique_port
get_all_ports

get_project_dir "skip_question"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ docker_create_nodejs_api() {
ECHO_INFO "Setting up Docker containers for $DOMAIN_FULL"

#GET PORT
get_unique_port
get_all_ports

get_project_dir "skip_question"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ docker_create_php() {
ECHO_INFO "Setting up Docker containers for $DOMAIN_FULL"

#GET PORT
get_unique_port
get_all_ports

get_project_dir "skip_question"

Expand All @@ -36,7 +36,7 @@ docker_create_php() {
mkdir -p $PROJECT_ROOT_DIR

# Clone templates files
git clone $TEMPLATES_REPO-$PROJECT_TYPE.git $PROJECT_ROOT_DIR --depth 1
git_clone_templates_files

# Rename files
replace_templates_files
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ docker_create_wp() {
ECHO_INFO "Setting up Docker containers for $DOMAIN_FULL"

#GET PORT
get_unique_port
get_all_ports

print_to_file_instances

# Create DIR
mkdir -p $PROJECT_ROOT_DIR

# Clone templates files
git clone $TEMPLATES_REPO-$PROJECT_TYPE.git $PROJECT_ROOT_DIR --depth 1
git_clone_templates_files

# Rename files
replace_templates_files
Expand All @@ -46,6 +46,7 @@ docker_create_wp() {
notice_windows_host add
docker_restart

wait_for_db
wp_core_install
wp_site_empty

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ docker_create_wp_next() {
ECHO_INFO "Setting up Docker containers for $DOMAIN_FULL"

#GET PORT
get_unique_port

#GET PORT_FRONT
set_unique_frontport
get_all_ports

get_project_dir "skip_question"

Expand Down
6 changes: 6 additions & 0 deletions .env-core/sh/projects/docker/docker_helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,9 @@ docker_official_image_exists() {
fi
fi
}

get_docker_ip() {
if [ -n "$1" ]; then
export DOCKER_IP=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $1)
fi
}
Loading

0 comments on commit c7b2a3e

Please sign in to comment.