diff --git a/compose.yml b/compose.yml index 0211a33..6d683a1 100644 --- a/compose.yml +++ b/compose.yml @@ -1,7 +1,7 @@ services: fpm: hostname: fpm - image: git.shihaam.dev/dockerfiles/php-fpm:8.3 + image: git.shihaam.dev/dockerfiles/php-fpm:latest volumes: - ./:/var/www/html/ nginx: @@ -13,13 +13,19 @@ services: - 9000:80 composer: hostname: composer - image: composer:2.7.9 + image: composer:latest volumes: - ./:/var/www/html/ working_dir: /var/www/html - database: - image: mariadb:lts - hostname: database + node: + hostname: node + image: node:18.20.4 + volumes: + - ./:/var/www/html/ + working_dir: /var/www/html + mysql: + image: mysql:5.7.44 + hostname: mysql restart: always environment: - MYSQL_RANDOM_ROOT_PASSWORD=yes diff --git a/helper b/helper index 51285b0..a9eeb88 100755 --- a/helper +++ b/helper @@ -32,13 +32,80 @@ yarn() { docker compose exec node "${@}" } -# Function to initialize the composer.yml file +# Function to initialize the compose.yml file with user inputs init() { - cat < composer.yml + # Prompt for PHP version + read -p "Enter PHP version (default is latest): " php_version + php_version=${php_version:-latest} + + # Prompt for Composer version + echo "Fetching available composer versions from Docker Hub..." + curl -s "https://hub.docker.com/v2/repositories/library/node/tags/?page_size=100" | jq -r '.results[].name' | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | sort -V + read -p "Enter Composer version (default is latest): " composer_version + composer_version=${composer_version:-latest} + + # Prompt for Node.js version and if they want to use Node + read -p "Do you want to include Node.js? (yes/no, default: yes): " include_node + include_node=${include_node:-yes} + if [[ "$include_node" =~ ^([yY][eE][sS]|[yY])$ ]]; then + echo "Fetching available Node.js versions from Docker Hub..." + curl -s "https://hub.docker.com/v2/repositories/library/node/tags/?page_size=100" | jq -r '.results[].name' | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | sort -V + read -p "Enter Node.js version (default is latest): " node_version + node_version=${node_version:-latest} + fi + + # Prompt for database type + echo "Select database type:" + echo "1. MariaDB" + echo "2. MySQL" + echo "3. PostgreSQL" + echo "4. None" + read -p "Enter the number corresponding to your choice (default: MariaDB): " db_choice + db_choice=${db_choice:-1} + + # Set default database versions and variables + case "$db_choice" in + 1) + db_service="mariadb" + echo "Fetching available Mariadb versions from Docker Hub..." + curl -s "https://hub.docker.com/v2/repositories/library/mariadb/tags/?page_size=100" | jq -r '.results[].name' | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | sort -V + read -p "Enter MariaDB version (default is latest): " db_version + db_version=${db_version:-latest} + db_image="mariadb:$db_version" + ;; + 2) + db_service="mysql" + echo "Fetching available MySQL versions from Docker Hub..." + curl -s "https://hub.docker.com/v2/repositories/library/mysql/tags/?page_size=100" | jq -r '.results[].name' | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | sort -V + read -p "Enter MySQL version (default is latest): " db_version + db_version=${db_version:-latest} + db_image="mysql:$db_version" + ;; + 3) + db_service="postgres" + echo "Fetching available PostgreSQL versions from Docker Hub..." + curl -s "https://hub.docker.com/v2/repositories/library/postgres/tags/?page_size=100" | jq -r '.results[].name' | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | sort -V + read -p "Enter PostgreSQL version (default is latest): " db_version + db_version=${db_version:-latest} + db_image="postgres:$db_version" + ;; + 4) + db_service="" + db_image="" + ;; + *) + echo "Invalid choice, defaulting to MariaDB." + db_service="mariadb" + db_image="mariadb:latest" + ;; + esac + + # Create compose.yml based on the input + cat < compose.yml services: fpm: hostname: fpm - image: git.shihaam.dev/dockerfiles/php-fpm:8.3 + image: git.shihaam.dev/dockerfiles/php-fpm:$php_version volumes: - ./:/var/www/html/ nginx: @@ -50,13 +117,30 @@ services: - 9000:80 composer: hostname: composer - image: composer:2.7.9 + image: composer:$composer_version volumes: - ./:/var/www/html/ working_dir: /var/www/html - database: - image: mariadb:lts - hostname: database +EOL + + # Add the node service if included + if [[ "$include_node" =~ ^([yY][eE][sS]|[yY])$ ]]; then + cat <> compose.yml + node: + hostname: node + image: node:$node_version + volumes: + - ./:/var/www/html/ + working_dir: /var/www/html +EOL + fi + + # Add the database service if selected + if [[ -n "$db_service" ]]; then + cat <> compose.yml + $db_service: + image: $db_image + hostname: $db_service restart: always environment: - MYSQL_RANDOM_ROOT_PASSWORD=yes @@ -65,12 +149,15 @@ services: - MYSQL_DATABASE=cusport volumes: - ./.db:/var/lib/mysql - node: - hostname: node - image: node:lts - volumes: - - ./:/var/www/html/ - working_dir: /var/www/html EOL - echo "composer.yml file created successfully!" + fi + + echo "compose.yml file created successfully!" + + # Run composer create-project to initialize Laravel after creating compose.yml + echo "Initializing Laravel project..." + docker compose run --rm composer bash -c "composer create-project --prefer-dist laravel/laravel tmp && cp -R tmp/. . && rm -rf tmp" + docker compose up -d + echo "Laravel project initialized successfully!" } + diff --git a/vendor/composer/tmp-31a2426b798b9cbc3f3e1f79951514cb.zip~ b/vendor/composer/tmp-31a2426b798b9cbc3f3e1f79951514cb.zip~ new file mode 100644 index 0000000..e69de29