From 16e98b56638e85a00d09d454660bb5444bf47612 Mon Sep 17 00:00:00 2001 From: y9938 Date: Sun, 14 Dec 2025 23:12:08 +0300 Subject: [PATCH] feat: add db recreation target and update Laravel setup docs --- .editorconfig | 3 +++ Makefile | 7 ++++++- README.md | 23 +++++++++++++++++++---- compose.yaml | 6 ++++-- docker/Dockerfile | 1 - docker/entrypoint.sh | 17 +++++++++++------ 6 files changed, 43 insertions(+), 14 deletions(-) diff --git a/.editorconfig b/.editorconfig index 432737a..42a78b8 100644 --- a/.editorconfig +++ b/.editorconfig @@ -16,3 +16,6 @@ indent_size = 2 [*.sh] indent_size = 2 + +[Makefile] +indent_style = tab diff --git a/Makefile b/Makefile index 686d7d2..45a22ee 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ IMAGE_TAG := latest IMAGE := $(IMAGE_NAME):$(IMAGE_TAG) TAR_FILE := $(IMAGE_NAME)_$(IMAGE_TAG).tar.gz -.PHONY: help build load shell docs +.PHONY: help build load shell docs db help: @echo "Usage:" @@ -19,6 +19,7 @@ help: @echo " Optional: SOURCE=url_or_file" @echo " shell Enter php-fpm container as www" @echo " docs Regenerate API documentation" + @echo " db Recreate DB" build: @@ -54,3 +55,7 @@ shell: docs: @echo "Regenerating API documentation..." docker compose exec --user www php-fpm php artisan scribe:generate + +db: + @echo "Recreate DB..." + docker compose exec --user www php-fpm bash -c "php artisan migrate:fresh && php artisan db:seed" diff --git a/README.md b/README.md index 9040ae3..45b6655 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Laravel Docker Setup -- NGINX, MySQL, phpMyAdmin +- PHP-FPM, NGINX, MySQL, phpMyAdmin (in `compose.yaml`) ## Create a project: @@ -12,19 +12,34 @@ docker compose exec php-fpm bash # or `make shell` ``` -Rewrite below for yourself: +**_Rewrite below for yourself:_** + +*RECOMENDED:* + +**The latest version** via [laravel/installer package](https://packagist.org/packages/laravel/installer) ```bash -composer global require laravel/installer - +composer global require laravel/installer && \ export PATH="$HOME/.composer/vendor/bin:$PATH" +# Check options via `laravel new -h` laravel new example-app mv example-app/* example-app/.* ./ rmdir example-app ``` +*OR:* + +**The specific version** via composer + +```bash +composer create-project --prefer-dist laravel/laravel example-app ^11.0 + +mv example-app/* example-app/.* ./ +rmdir example-app +``` + ## Quick Actions ```bash diff --git a/compose.yaml b/compose.yaml index 3eb0d5b..9802b0f 100644 --- a/compose.yaml +++ b/compose.yaml @@ -26,6 +26,7 @@ services: volumes: - ./:/var/www + mysql: image: mysql:8.0 ports: @@ -36,7 +37,8 @@ services: - MYSQL_PASSWORD=${DB_PASSWORD} - MYSQL_ROOT_PASSWORD=${DB_ROOT_PASSWORD} volumes: - - mysql-data:/var/lib/mysql + - mysql-data-development:/var/lib/mysql + phpmyadmin: image: phpmyadmin:latest @@ -52,4 +54,4 @@ services: condition: service_started volumes: - mysql-data: + mysql-data-development: diff --git a/docker/Dockerfile b/docker/Dockerfile index 4dbbfc9..9612359 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -13,7 +13,6 @@ ARG UID ARG GID # Create a new user with the specified UID and GID, reusing an existing group if GID exists -# and update php-fpm to use the new user and group RUN if getent group ${GID}; then \ group_name=$(getent group ${GID} | cut -d: -f1); \ useradd -m -u ${UID} -g ${GID} -s /bin/bash www; \ diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 60938c7..dcd7dc1 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -9,10 +9,13 @@ if [ ! -f "artisan" ]; then exec "$@" fi -if [ ! -f .composer-hash ] || ! sha1sum -c .composer-hash > /dev/null 2>&1; then +gosu www mkdir -p .hashes + +if [ ! -f .hashes/.composer-hash ] || ! sha1sum -c .hashes/.composer-hash; then echo ">> composer.json or composer.lock changed, installing dependencies..." gosu www composer install --optimize-autoloader --no-interaction - sha1sum composer.json composer.lock > .composer-hash + gosu www sha1sum composer.json composer.lock > .hashes/.composer-hash + chown www: .hashes/.composer-hash else echo ">> Composer dependencies up to date (hash match), skipping install." fi @@ -36,17 +39,19 @@ fi echo ">> Running seeders..." gosu www php artisan db:seed --force -if composer show knuckleswtf/scribe > /dev/null 2>&1; then +if composer show knuckleswtf/scribe >/dev/null 2>&1; then # Define all directories/files Scribe cares about SCRIBE_SOURCES="config/scribe.php routes/ app/Http/Controllers/ app/Http/Requests/ app/Models/" # Create combined hash of all .php files in those paths CURRENT_HASH=$(find $SCRIBE_SOURCES -type f -name "*.php" -exec sha1sum {} + | sha1sum) - if [ ! -f .scribe-hash ] || [ "$CURRENT_HASH" != "$(cat .scribe-hash)" ]; then + if [ ! -f .hashes/.scribe-hash ] || [ "$CURRENT_HASH" != "$(cat .hashes/.scribe-hash)" ]; then echo ">> Generating API documentation..." - gosu www php artisan scribe:generate --no-interaction || true - echo "$CURRENT_HASH" > .scribe-hash + gosu www php artisan scribe:generate --no-interaction \ + || echo ">> Warning: Scribe generation failed, continuing..." + echo "$CURRENT_HASH" > .hashes/.scribe-hash + chown www: .hashes/.scribe-hash else echo ">> API docs up to date, skipping Scribe generation." fi