diff --git a/README.md b/README.md index f09eb19..48c1f91 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ 👤 Author: [Nick Yeoman](https://www.nickyeoman.com/). -These cookbooks are created with the intent of using Docker's extend feature. This way, you can run multiple containers in different domains but still have only one file to update. +Production ready docker compose files ## 🤔 Assumptions @@ -22,34 +22,4 @@ The intended workflow is as follows: You will likely want to override a number of things in the project folder, such as networks. -## 🔍 Example Result - -Here is an example of how your project's docker-compose file might look: - -```yaml -services: - proxy: - extends: - file: ${COOKBOOK}/nginx-proxy-manager/docker-compose.yml - service: proxy - env_file: - - .env - networks: - - proxy - -networks: - proxy: - external: true -``` - -with the .env file: - -```text -COOKBOOK=/docker-compose-cookbooks -COMPOSE_PROJECT_NAME=www-4lt-ca -TZ=America/Vancouver -VOL_CONFIG_PATH=/websites/www-4lt-ca/config -VOL_PATH=/websites/www-4lt-ca/data -``` - Now use ```docker compose up -d``` to start the project. diff --git a/_builder/dc-env.sh b/_builder/dc-env.sh deleted file mode 100644 index 02393e2..0000000 --- a/_builder/dc-env.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash - -process_env_vars() { - local env_vars="$1" # Accept the environment variables as the first parameter - local APP_NAME="$(echo "$2" | tr '[:lower:]' '[:upper:]')" # Convert app name to uppercase - local results=() # Array to collect results - - # Loop through each environment variable - while IFS= read -r env_var; do - # Split into name and value parts based on ':' - var_name="${env_var%%:*}" # Variable name - var_value="${env_var#*:}" # Variable value - - # Remove leading and trailing whitespace - var_name=$(echo "$var_name" | xargs) - var_value=$(echo "$var_value" | xargs) - - # Format the variable as required - modified_var="${var_name}=\${${APP_NAME}_${var_name}:-${var_value}}" - - # Append the modified variable to results - results+=("$modified_var") - done <<< "$env_vars" - - # Output the results joined with new lines - printf "%s\n" "${results[@]}" | sort -} \ No newline at end of file diff --git a/_builder/dc-image.sh b/_builder/dc-image.sh deleted file mode 100644 index 35a8e04..0000000 --- a/_builder/dc-image.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -# Function to parse and handle the variable -extract_image_name() { - local dirty_img="$1" - - if [[ "$dirty_img" == *\$* ]]; then - extracted_value=$(echo "$dirty_img" | sed -n 's/.*:-\([^}]*\)}.*/\1/p') - else - extracted_value=$dirty_img - fi - - echo "$extracted_value" -} - diff --git a/_builder/dc-new.sh b/_builder/dc-new.sh deleted file mode 100644 index 025448a..0000000 --- a/_builder/dc-new.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash - -BLDR_IMAGE_VAR="\${${BLDR_APP^^}_IMAGE:-$BLDR_DC_IMAGE}" - -# Generate Docker Compose content and save it to a variable -BLDR_NEW_DCF=$(cat < ${BLDR_DIR}/docker-compose.yml diff --git a/_builder/dc-vols.sh b/_builder/dc-vols.sh deleted file mode 100644 index 7f8f34d..0000000 --- a/_builder/dc-vols.sh +++ /dev/null @@ -1,44 +0,0 @@ -#!/bin/bash - -# Function to process volumes -process_volumes() { - local volumes="$1" # Accept volumes as the first parameter - local results=() # Array to collect results - - # Loop through each volume - while IFS= read -r volume; do - # Perform actions with each volume - if [[ "$volume" == *\$* ]]; then - if [[ "$volume" == *'VOL'* && "$volume" == *'PATH'* ]]; then - results+=("$volume") - else - part="${volume#*\}}/" # Note the \} to handle the literal } - part="${part#./}" - part="${part#/}" - results+=('${VOL_PATH:-./data}/'"$part") - fi - else - if [[ "${volume:0:1}" == '/' ]]; then - results+=("$volume") - else - if [[ "$volume" == './data'* ]]; then - part="${volume#./data}" - part="${part#/}" - results+=('${VOL_PATH:-./data}/'"$part") - elif [[ "$volume" == './config'* ]]; then - part="${volume#./config}" - part="${part#/}" - results+=('${VOL_CONFIG_PATH:-./config}/'"$part") - else - part="${volume#./}" - results+=("./$part") - fi - fi - fi - # Add your commands here to handle each volume - done <<< "$volumes" - - # Output the results joined with new lines - printf "%s\n" "${results[@]}" | sort -} - diff --git a/_builder/debug.sh b/_builder/debug.sh deleted file mode 100644 index 822b421..0000000 --- a/_builder/debug.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -debug_print_helper_variables() { - echo "DEBUGGING $(date +%s): " - for var in $(compgen -v | grep '^BLDR_'); do - echo "$var=${!var}" - done -} \ No newline at end of file diff --git a/_builder/extends-new.sh b/_builder/extends-new.sh deleted file mode 100644 index 31f7c07..0000000 --- a/_builder/extends-new.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash - -# Define the content to write to the file -file_content=$(cat < ${BLDR_DIR}/sample-extends.yml diff --git a/_builder/getdir.bash b/_builder/getdir.bash deleted file mode 100644 index 8ac8fe5..0000000 --- a/_builder/getdir.bash +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -# List all directories in the current directory that don't start with an underscore -directories=$(find . -maxdepth 1 -type d -not -name '_*' -exec basename {} \; | grep -v '[_\.]' | sort -r) - -# Use fzf to allow the user to select a directory -selected_dir=$(echo "$directories" | fzf --prompt="Select a directory: ") - -# Check if a directory was selected -if [[ -z "$selected_dir" ]]; then - echo "No directory selected." - return 1 -fi - -# Set the BLDR_DIR variable to the selected directory -BLDR_DIR="${BLDR_PARENT_PATH}/${selected_dir}" -BLDR_APP=${selected_dir} diff --git a/_builder/olddcf.bash b/_builder/olddcf.bash deleted file mode 100644 index 8ab10f0..0000000 --- a/_builder/olddcf.bash +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash - -# Check if BLDR_DIR is set -if [[ -z "$BLDR_DIR" ]]; then - echo "Error: BLDR_DIR is not set. Please ensure it points to a valid directory." - exit 1 -fi - -# Define the path to the docker-compose.yml file -compose_file="$BLDR_DIR/docker-compose.yml" - -# Check if the docker-compose.yml file exists -if [[ ! -f "$compose_file" ]]; then - echo "Error: No docker-compose.yml file found in $BLDR_DIR" - exit 1 -fi - -# Read the contents of the docker-compose.yml file into BLDR_OLD_DCF variable -BLDR_OLD_DCF=$(<"$compose_file") diff --git a/_builder/parse.bash b/_builder/parse.bash deleted file mode 100644 index 977523c..0000000 --- a/_builder/parse.bash +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/bash - -get_vols() { - local compose_content="$1" - local volumes="" - - # Use yq to extract volumes from services - volumes=$(echo "$compose_content" | yq eval '.services.*.volumes[]' - 2>/dev/null) - - # Print the volumes, preserving line breaks - printf "%s\n" "$volumes" -} - -get_env_vars() { - local compose_content="$1" - local env_vars="" - - # Use yq to extract environment variables in 'key=value' format without indices - env_vars=$(echo "$compose_content" | yq eval '.services.*.environment[]' - 2>/dev/null) - - echo "$env_vars" -} - -get_image() { - local compose_content="$1" - local images="" - - # Use yq to extract image names from services - images=$(echo "$compose_content" | yq eval '.services.*.image' - 2>/dev/null) - - echo "$images" -} \ No newline at end of file diff --git a/_builder/precheck.sh b/_builder/precheck.sh deleted file mode 100644 index b3ea989..0000000 --- a/_builder/precheck.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/bash - -# Function to check if a command is installed and provide installation instructions if not -check_command() { - local command_name="$1" - - if ! command -v "$command_name" &> /dev/null; then - echo "$command_name is not installed." - echo "To install $command_name:" - - case "$(uname -s)" in - Linux*) - if [ -f /etc/os-release ]; then - . /etc/os-release - case "$ID" in - fedora) - echo " - Fedora: sudo dnf install $command_name" - ;; - arch) - echo " - Arch: sudo pacman -S $command_name" - ;; - debian | ubuntu) - echo " - Debian/Ubuntu: sudo apt install $command_name" - ;; - *) - echo " - On other Linux distros, refer to your package manager's documentation." - ;; - esac - else - echo " - Linux: refer to your package manager's documentation for installation." - fi - ;; - Darwin*) - echo " - macOS: brew install $command_name (Homebrew)" - ;; - *) - echo " - Unsupported OS. Please install $command_name manually." - ;; - esac - - exit 1 - fi -} diff --git a/_builder/readme-new.sh b/_builder/readme-new.sh deleted file mode 100644 index 6637265..0000000 --- a/_builder/readme-new.sh +++ /dev/null @@ -1,57 +0,0 @@ -#!/bin/bash - -# Variables for README content -DESCRIPTION="${DESCRIPTION:-This is a sample project.}" -AUTHOR="${AUTHOR:-Nick Yeoman}" -UPDATED=$(date +"%a %B %d, %Y %H:%M:%S %Z") - -# Function to generate a README file -generate_readme() { - local readme_content="" - - # Header - readme_content+="# $BLDR_APP\n\n" - readme_content+="Last Updated: $UPDATED\n\n" - - # Overview - readme_content+="## Overview\n" - readme_content+="Docker Hub: \n" - readme_content+="Project: \n" - readme_content+="Docker Compose Example: \n" - readme_content+="Proxy Port: \n" - - # Description - readme_content+="## Description\n" - readme_content+="$DESCRIPTION\n\n" - - # Usage - readme_content+="## Usage\n" - readme_content+="Provide examples of how to use the project:\n\n" - readme_content+="\`\`\`bash\n" - readme_content+="# Example command\n" - readme_content+="\`\`\`\n\n" - - # Environment Variables - readme_content+="## Environment Variables\n" - readme_content+="List of environment variables used in the project:\n\n" - - # Extract environment variables from BLDR_NEW_SE - while IFS= read -r line; do - # Use regex to match and extract variable names and defaults - if [[ $line =~ ^([A-Za-z_][A-Za-z0-9_]*)=(.*)$ ]]; then - var_name="${BASH_REMATCH[1]}" - var_value="${BASH_REMATCH[2]}" - readme_content+="* \`$var_name\`: $var_value\n" - fi - done <<< "$BLDR_NEW_SE" - - readme_content+="\n" - - # Author - readme_content+="## Author\n" - readme_content+="Developed by $AUTHOR.\n" - - # Output the README content to a file - echo -e "$readme_content" -} - diff --git a/_builder/se-new.sh b/_builder/se-new.sh deleted file mode 100644 index 3787940..0000000 --- a/_builder/se-new.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash - -BLDR_ENV_FILE+="# $BLDR_APP\n" -BLDR_ENV_FILE+="COOKBOOK=/git/docker-compose-cookbooks #HELP: cookbooks\n" - -while IFS= read -r line; do - # Use a regex to match and extract variable names and defaults - if [[ $line =~ \$\{([A-Za-z_][A-Za-z0-9_]*)\} ]]; then - # Matched ${VAR_NAME} (without default) - var_name="${BASH_REMATCH[1]}" - BLDR_ENV_FILE+="${var_name}=\n" - elif [[ $line =~ \$\{([A-Za-z_][A-Za-z0-9_]*)[:-](.*)\} ]]; then - # Matched ${VAR_DEF:-default} (with default) - var_name="${BASH_REMATCH[1]}" - default_value="${BASH_REMATCH[2]:1}" - BLDR_ENV_FILE+="${var_name}=${default_value}\n" - fi -done <<< "$BLDR_NEW_DCF" - -# Remove duplicates from the output -BLDR_ENV_FILE=$(echo -e "$BLDR_ENV_FILE" | sort -u) - -echo "$BLDR_ENV_FILE" > ${BLDR_DIR}/sample.env diff --git a/_helper/debug.sh b/_helper/debug.sh deleted file mode 100644 index c539f05..0000000 --- a/_helper/debug.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -debug_print_helper_variables() { - for var in $(compgen -v | grep '^HLPR_'); do - echo "$var=${!var}" - done -} \ No newline at end of file diff --git a/_helper/dirs.sh b/_helper/dirs.sh deleted file mode 100644 index d7596ab..0000000 --- a/_helper/dirs.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/bash - -# Function to create directories based on volumes in docker-compose files -create_dirs() { - local project_path="$1" - local selected_dirs="$2" - local cookbook_dir="$3" - - local data_dir="$project_path/data" - - # Loop through selected directories - for dir in $selected_dirs; do - local compose_file="$cookbook_dir/$dir/docker-compose.yml" - - # Check if the docker-compose file exists - if [ -f "$compose_file" ]; then - # Loop through each line in the file - while IFS= read -r line; do - trimmed_line=$(echo "$line" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//') - # Check if the line starts with a dash - if [[ $trimmed_line =~ ^- ]]; then - if [[ $trimmed_line =~ VOL_PATH ]]; then - extracted=$(echo "$trimmed_line" | sed -n 's/.*\${VOL_PATH:-[^}]*}\([^:]*\):.*/\1/p' | sed 's/^\/\+//') - # Echo the line if it starts with a dash - mkdir -p $project_path/data/${extracted} - fi - fi - done < "$compose_file" - - else - echo "Warning: No docker-compose.yml found in $dir" - fi - done -} diff --git a/_helper/dockercompose.sh b/_helper/dockercompose.sh deleted file mode 100644 index 8d900d6..0000000 --- a/_helper/dockercompose.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/bash - -# Function to create a new docker-compose file using extends -create_dockercompose() { - local project_path="$1" - local selected_dirs="$2" - local script_dir="$3" # Directory where helper.bash is located - - # Initialize the new docker-compose file - local new_compose_file="$project_path/docker-compose.yml" - - # Write the initial part of the docker-compose file - echo "version: '3.4'" > "$new_compose_file" - echo "" >> "$new_compose_file" - echo "services:" >> "$new_compose_file" - - # Loop through selected directories - for dir in $selected_dirs; do - local sample_file="$script_dir/$dir/sample-extends.yml" - - if [ -f "$sample_file" ]; then - # Extract services section from the sample file and append it - awk '/^services:/{flag=1; next}/^$/{flag=0}flag' "$sample_file" >> "$new_compose_file" - echo "" >> "$new_compose_file" # Add a newline after each file's content - else - echo "Warning: Create an issue: No sample-extends.yml found in $dir" - cp $script_dir/$dir/docker-compose.yml $new_compose_file - fi - done -} diff --git a/_helper/env.sh b/_helper/env.sh deleted file mode 100644 index af5a704..0000000 --- a/_helper/env.sh +++ /dev/null @@ -1,104 +0,0 @@ -#!/bin/bash - -process_help_comments() { - local input_file="$1" - local output_file="$2" - local project_path="$3" - local cookbook_dir="$4" - - local temp_file=$(mktemp) - - while IFS= read -r line; do - # Handle headings (keep headings and process below lines) - if [[ "$line" =~ ^# ]]; then - echo "$line" >> "$temp_file" - elif [[ "$line" =~ ^([^=]+)= ]]; then - local var_name="${BASH_REMATCH[1]}" - local var_value="${line#*=}" - var_value=$(echo "$var_value" | sed 's/\s*#HELP:.*$//') - - # Process #HELP comments - if [[ "$line" =~ \#HELP:\ project_path ]]; then - var_value="$HLPR_PROJECTPATH" - elif [[ "$line" =~ \#HELP:\ volpath ]]; then - var_value="$HLPR_PROJECTPATH/data" - elif [[ "$line" =~ \#HELP:\ configpath ]]; then - var_value="$HLPR_PROJECTPATH/config" - elif [[ "$line" =~ \#HELP:\ cookbooks ]]; then - var_value="$HLPR_COOKBOOKDIR" - elif [[ "$line" =~ \#HELP:\ gen32 ]]; then - var_value=$(pwgen -cnsB1v 32) - fi - - # Add the processed variable to the temp file - echo "${var_name}=${var_value}" >> "$temp_file" - else - # If the line doesn't match a variable, just echo it - echo "$line" >> "$temp_file" - fi - done < "$input_file" - - # Call remove_duplicate_variables to process temp_file and write to output_file - cat "$temp_file" >> $output_file - rm "$temp_file" -} - -remove_duplicate_variables() { - local input_file="$1" - local temp_file=$(mktemp) - declare -A seen_keys - - while IFS= read -r line; do - - # Skip lines that start with # or are blank - if [[ ! $line =~ ^# ]] && [[ -n $line ]]; then - # Extract the part before the equals sign - key=$(echo "$line" | awk -F '=' '{print $1}') - - # Check if the key has already been seen - if [[ -z "${seen_keys[$key]}" ]]; then - # Mark the key as seen - seen_keys[$key]=1 - # Output the key - echo "$line" >> "$temp_file" - fi - else - echo "$line" >> "$temp_file" - fi - done < "$input_file" - - # Replace the original file with the deduplicated version - mv "$temp_file" "$input_file" -} - -# Function to create .env file -create_env() { - local project_path="$1" - local selected_dirs="$2" - local cookbook_dir="$3" - local new_env_file="$project_path/.env" - local current_date=$(date) - local git_user=$(git config --get user.name) - if [[ -z "$git_user" ]]; then - local git_user=$USER - fi - - # Create the file - touch $new_env_file - echo "# Auto Generated env file on $current_date by $git_user" >> "$new_env_file" - - # Loop through selected directories and process sample.env files - for dir in $selected_dirs; do - local sample_file="$cookbook_dir/$dir/sample.env" - - if [ -f "$sample_file" ]; then - process_help_comments "$sample_file" "$new_env_file" "$project_path" "$cookbook_dir" - else - echo "Warning: Create an issue: No sample.env found in $dir" >&2 - echo "#No Sample File found, raise a bug" >> "$new_env_file" - fi - done - - remove_duplicate_variables "$new_env_file" - -} diff --git a/_helper/footer.sh b/_helper/footer.sh deleted file mode 100644 index 150e28e..0000000 --- a/_helper/footer.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash - -function display_footer() { - echo "======================================" - echo "All Done" - echo "Created Project: $HLPR_PROJECTNAME in $HLPR_PROJECTDIR" - echo "With the following containers:" - echo $HLPR_CONTAINERS -} \ No newline at end of file diff --git a/_helper/gitignore.sh b/_helper/gitignore.sh deleted file mode 100644 index b3cb27a..0000000 --- a/_helper/gitignore.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash - -# Function to create a .gitignore file with standard ignores -create_gitignore() { - local project_path="$1" - local gitignore_path="$project_path/.gitignore" - - # Create the .gitignore file - cat < "$gitignore_path" -data/ -logs/ -*.log -.vscode/ -.idea/ -*.suo -*.ntvs* -*.njsproj -*.sln -.DS_Store -Thumbs.db -EOL -} diff --git a/_helper/header.sh b/_helper/header.sh deleted file mode 100644 index c4200b9..0000000 --- a/_helper/header.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -function display_header() { - echo "======================================" - echo " Docker Compose Project Setup Wizard" - echo "======================================" -} diff --git a/_helper/precheck.sh b/_helper/precheck.sh deleted file mode 100644 index 9cc67de..0000000 --- a/_helper/precheck.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash - -# Function to check if fzf is installed and provide installation instructions if not -check_fzf() { - if ! command -v fzf &> /dev/null; then - echo "fzf is not installed." - echo "To install fzf:" - echo " - Fedora: sudo dnf install fzf" - echo " - Arch: sudo pacman -S fzf" - echo " - Debian: sudo apt install fzf" - exit 1 - fi -} - -# Function to check if pwgen is installed and provide installation instructions if not -check_pwgen() { - if ! command -v pwgen &> /dev/null; then - echo "pwgen is not installed." - echo "To install pwgen:" - echo " - Fedora: sudo dnf install pwgen" - echo " - Arch: sudo pacman -S pwgen" - echo " - Debian: sudo apt install pwgen" - exit 1 - fi -} \ No newline at end of file diff --git a/_helper/project-create.sh b/_helper/project-create.sh deleted file mode 100644 index 0502791..0000000 --- a/_helper/project-create.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/bash - -# Function to check if the project directory already exists -check_project() { - local path="$1" - if [ -d "$path" ]; then - echo "Error: Directory '$path' already exists." - return 1 - fi - return 0 -} - -# Function to create the project directory -create_project() { - local path="$1" - mkdir -p "$path" - if [ $? -ne 0 ]; then - echo "Error: Failed to create directory '$path'. Exiting." - exit 1 - fi -} - -# Function to handle the project directory creation process -handle_project_creation() { - local project_path="$1" - local project_name="$2" - - while true; do - check_project "$HLPR_PROJECTDIR" - if [ $? -eq 0 ]; then - create_project "$HLPR_PROJECTDIR" - break - else - read -p "Please enter a new directory path (must not exist): " new_project_path - if [ -z "$new_project_path" ]; then - echo "Error: Path cannot be empty. Exiting." - exit 1 - fi - project_path="$new_project_path" - HLPR_PROJECTDIR="$project_path/$project_name" - fi - done -} diff --git a/_helper/project-name.sh b/_helper/project-name.sh deleted file mode 100644 index 923fc14..0000000 --- a/_helper/project-name.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash - -# Function to get user input for project name -get_project_name() { - while true; do - read -p "Enter project name (usually the domain name, like www-example-com): " HLPR_PROJECTNAME - if [[ "$HLPR_PROJECTNAME" =~ ^[a-zA-Z0-9-]+$ ]]; then - break - else - echo "Invalid project name. Please use only letters, numbers, and dashes. No spaces allowed." - fi - done -} diff --git a/_helper/project-path.sh b/_helper/project-path.sh deleted file mode 100644 index 4fd45b1..0000000 --- a/_helper/project-path.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash - -# Function to display directories using fzf with enhanced parameters -select_directory_with_fzf() { - # Find all directories under the user's home directory, excluding dot directories and suppressing permission errors - local fzf_input=$(find "$HOME" -type d -not -path '*/\.*' 2>/dev/null | while read -r dir; do [ -r "$dir" ] && echo "$dir"; done) - - # Use fzf with enhanced parameters for better usability - selected_path=$(echo "$fzf_input" | fzf --height 40% --layout=reverse --border --preview 'echo {} | xargs -I % du -sh % 2>/dev/null' --preview-window=up:30% --prompt="Select a directory: ") - - # Handle the case where no directory was selected - if [ -z "$selected_path" ]; then - echo "No directory selected. Exiting." - exit 1 - fi - - # Output the selected path - HLPR_PROJECTPATH="$selected_path" -} diff --git a/_helper/readme.sh b/_helper/readme.sh deleted file mode 100644 index 3e9c61f..0000000 --- a/_helper/readme.sh +++ /dev/null @@ -1,50 +0,0 @@ -#!/bin/bash - -# Function to create a README.md file -create_readme() { - local project_path="$1" - local project_name="$2" - local selected_dirs="$3" - local readme_path="$project_path/README.md" - local current_date=$(date +"%Y-%m-%d") - - # Retrieve the full name from the global Git config - local git_name=$(git config --global user.name) - if [ -z "$git_name" ]; then - echo 'WARNING: Set your git username: git config --global user.name "Your Name"' - git_name="$USER" - fi - - # Create the README.md file - cat < "$readme_path" -# $project_name - -Project created on $current_date by $git_name - -## Description - -A brief description of your project goes here. - -## Project Structure - -This project includes the following containers: - -EOL - - # Add the selected directories to the README - if [ -n "$selected_dirs" ]; then - echo "$selected_dirs" | while read -r dir; do - echo "- $(basename "$dir")" >> "$readme_path" - done - else - echo "No containers selected." >> "$readme_path" - fi - - cat <> "$readme_path" - -## Usage - -podman-compose up -d - -EOL -} diff --git a/_helper/select-containers.sh b/_helper/select-containers.sh deleted file mode 100644 index 0145ed7..0000000 --- a/_helper/select-containers.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash - -# Function to list all directories in the same directory as the helper script and allow the user to select multiple directories -select_directories() { - # Get the directory where this script is located - local script_dir=$(dirname "$(realpath "$0")") - - # Find all directories in the same directory as the helper script and get their basenames, excluding those starting with an underscore - local dir_list=$(find "$script_dir" -maxdepth 1 -type d -not -path '*/\.*' -not -path "$script_dir" -not -name '_*' | xargs -I {} basename {}) - - # Use fzf to allow the user to select multiple directories with checkboxes - local selected_dirs=$(echo "$dir_list" | fzf --multi --height 40% --layout=reverse --border --prompt="Select directories (TAB to toggle, ENTER to confirm): " --bind 'tab:toggle+down') - - # Handle the case where no directory was selected - if [ -z "$selected_dirs" ]; then - echo "No directories selected. Exiting." - exit 1 - fi - - HLPR_CONTAINERS="$selected_dirs" -} \ No newline at end of file diff --git a/builder.bash b/builder.bash deleted file mode 100644 index 19f9e66..0000000 --- a/builder.bash +++ /dev/null @@ -1,90 +0,0 @@ -#!/bin/bash - - -BLDR_APP="" -BLDR_DC_ENV="" -BLDR_DC_IMAGE="" -BLDR_DC_VOLS="" -BLDR_DIR="" -BLDR_ENV_FILE="" -BLDR_NEW_DCF="" # Content of New Docker Compose File -BLDR_NEW_README="" -BLDR_NEW_SE="" # sample-extends -BLDR_OLD_DCF="" # Content of Old Docker Compose File -BLDR_PARENT_PATH=$(dirname "$(realpath "${BASH_SOURCE[0]}")") - -source ./_builder/debug.sh -#debug_print_helper_variables - -################################################ -# Pre Check -################################################ -source ./_builder/precheck.sh -check_command "fzf" -check_command "yq" - -################################################ -# Get Directory we are working with -################################################ -source ./_builder/getdir.bash - -################################################ -# Save file to work with -################################################ -source ./_builder/olddcf.bash - -################################################ -# Take out the stuff we need -################################################ -source ./_builder/parse.bash -BLDR_DC_VOLS=$(get_vols "$BLDR_OLD_DCF") -BLDR_DC_ENV=$(get_env_vars "$BLDR_OLD_DCF") -BLDR_DC_IMAGE=$(get_image "$BLDR_OLD_DCF") -unset BLDR_OLD_DCF # Done, got the stuff we need - -################################################ -# Clean up the IMAGE -################################################ -source ./_builder/dc-image.sh -BLDR_DC_IMAGE=$(extract_image_name "$BLDR_DC_IMAGE") - -################################################ -# Clean up VOLS -################################################ -source ./_builder/dc-vols.sh -BLDR_DC_VOLS=$(process_volumes "$BLDR_DC_VOLS") - -################################################ -# Clean up ENV -################################################ -source ./_builder/dc-env.sh -# echo "The Input: " -# echo "$BLDR_DC_ENV" -BLDR_DC_ENV=$(process_env_vars "$BLDR_DC_ENV" "$BLDR_APP") -# echo "The Output: " -# echo "$BLDR_DC_ENV" -# exit - -################################################ -# Compile New Docker Var BLDR_NEW_DCF -################################################ -source ./_builder/dc-new.sh - -################################################ -# Create sample-env -################################################ -source ./_builder/se-new.sh - -################################################ -# Create sample-extends -################################################ -source ./_builder/extends-new.sh - -################################################ -# Create Readme.md -################################################ -if [[ ! -f "${BLDR_DIR}/README.md" ]]; then - source ./_builder/readme-new.sh - BLDR_NEW_README=$(generate_readme) - echo "$BLDR_NEW_README" > ${BLDR_DIR}/README.md -fi diff --git a/helper.bash b/helper.bash deleted file mode 100644 index 455b0dc..0000000 --- a/helper.bash +++ /dev/null @@ -1,84 +0,0 @@ -#!/bin/bash - -HLPR_COOKBOOKDIR="$(dirname "$(realpath "$BASH_SOURCE")")" -HLPR_PROJECTNAME='NEW_PROJECT' -HLPR_PROJECTPATH=$HOME -HLPR_PROJECTDIR="$HLPR_PROJECTPATH/$HLPR_PROJECTNAME" -HLPR_CONTAINERS='' - -#source ./_helper/debug.sh -# debug_print_helper_variables - -################################################ -# Pre Check -################################################ -source ./_helper/precheck.sh -check_fzf -check_pwgen - -################################################ -# Display Header -################################################ -source ./_helper/header.sh -display_header - -################################################ -# Get Project Name -################################################ -source ./_helper/project-name.sh -get_project_name - -################################################ -# Get Project Path -################################################ -source ./_helper/project-path.sh -select_directory_with_fzf -HLPR_PROJECTDIR="$HLPR_PROJECTPATH/$HLPR_PROJECTNAME" - -################################################ -# Select containers -################################################ -source ./_helper/select-containers.sh -select_directories - -################################################ -# Create Project Directory -################################################ -source ./_helper/project-create.sh -handle_project_creation "$HLPR_PROJECTPATH" "$HLPR_PROJECTNAME" - -################################################ -# Create a .gitignore -################################################ -source ./_helper/gitignore.sh -create_gitignore "$HLPR_PROJECTDIR" - -################################################ -# Create a README.md -################################################ -source ./_helper/readme.sh -create_readme "$HLPR_PROJECTDIR" "$HLPR_PROJECTNAME" "$HLPR_CONTAINERS" - -################################################ -# Create docker-compose -################################################ -source ./_helper/dockercompose.sh -create_dockercompose "$HLPR_PROJECTDIR" "$HLPR_CONTAINERS" "$HLPR_COOKBOOKDIR" - -################################################ -# Create env -################################################ -source ./_helper/env.sh -create_env "$HLPR_PROJECTDIR" "$HLPR_CONTAINERS" "$HLPR_COOKBOOKDIR" - -################################################ -# Create directories -################################################ -source ./_helper/dirs.sh -create_dirs "$HLPR_PROJECTDIR" "$HLPR_CONTAINERS" "$HLPR_COOKBOOKDIR" - -################################################ -# Display Footer -################################################ -source ./_helper/footer.sh -display_footer \ No newline at end of file