feat: add db recreation target and update Laravel setup docs

This commit is contained in:
2025-12-14 23:12:08 +03:00
parent 2c86eda6be
commit a5a1c7d2a7
6 changed files with 42 additions and 13 deletions

View File

@@ -16,3 +16,6 @@ indent_size = 2
[*.sh] [*.sh]
indent_size = 2 indent_size = 2
[Makefile]
indent_style = tab

View File

@@ -7,7 +7,7 @@ IMAGE_TAG := latest
IMAGE := $(IMAGE_NAME):$(IMAGE_TAG) IMAGE := $(IMAGE_NAME):$(IMAGE_TAG)
TAR_FILE := $(IMAGE_NAME)_$(IMAGE_TAG).tar.gz TAR_FILE := $(IMAGE_NAME)_$(IMAGE_TAG).tar.gz
.PHONY: help build load shell docs .PHONY: help build load shell docs db
help: help:
@echo "Usage:" @echo "Usage:"
@@ -19,6 +19,7 @@ help:
@echo " Optional: SOURCE=url_or_file" @echo " Optional: SOURCE=url_or_file"
@echo " shell Enter php-fpm container as www" @echo " shell Enter php-fpm container as www"
@echo " docs Regenerate API documentation" @echo " docs Regenerate API documentation"
@echo " db Recreate DB"
build: build:
@@ -54,3 +55,7 @@ shell:
docs: docs:
@echo "Regenerating API documentation..." @echo "Regenerating API documentation..."
docker compose exec --user www php-fpm php artisan scribe:generate 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"

View File

@@ -12,19 +12,34 @@ docker compose exec php-fpm bash
# or `make shell` # 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 ```bash
composer global require laravel/installer composer global require laravel/installer && \
export PATH="$HOME/.composer/vendor/bin:$PATH" export PATH="$HOME/.composer/vendor/bin:$PATH"
# Check options via `laravel new -h`
laravel new example-app laravel new example-app
mv example-app/* example-app/.* ./ mv example-app/* example-app/.* ./
rmdir 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 ## Quick Actions
```bash ```bash

View File

@@ -26,6 +26,7 @@ services:
volumes: volumes:
- ./:/var/www - ./:/var/www
mysql: mysql:
image: mysql:8.0 image: mysql:8.0
ports: ports:
@@ -36,7 +37,8 @@ services:
- MYSQL_PASSWORD=${DB_PASSWORD} - MYSQL_PASSWORD=${DB_PASSWORD}
- MYSQL_ROOT_PASSWORD=${DB_ROOT_PASSWORD} - MYSQL_ROOT_PASSWORD=${DB_ROOT_PASSWORD}
volumes: volumes:
- mysql-data:/var/lib/mysql - mysql-data-development:/var/lib/mysql
phpmyadmin: phpmyadmin:
image: phpmyadmin:latest image: phpmyadmin:latest
@@ -52,4 +54,4 @@ services:
condition: service_started condition: service_started
volumes: volumes:
mysql-data: mysql-data-development:

View File

@@ -13,7 +13,6 @@ ARG UID
ARG GID ARG GID
# Create a new user with the specified UID and GID, reusing an existing group if GID exists # 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 \ RUN if getent group ${GID}; then \
group_name=$(getent group ${GID} | cut -d: -f1); \ group_name=$(getent group ${GID} | cut -d: -f1); \
useradd -m -u ${UID} -g ${GID} -s /bin/bash www; \ useradd -m -u ${UID} -g ${GID} -s /bin/bash www; \

View File

@@ -9,10 +9,13 @@ if [ ! -f "artisan" ]; then
exec "$@" exec "$@"
fi 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..." echo ">> composer.json or composer.lock changed, installing dependencies..."
gosu www composer install --optimize-autoloader --no-interaction 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 else
echo ">> Composer dependencies up to date (hash match), skipping install." echo ">> Composer dependencies up to date (hash match), skipping install."
fi fi
@@ -43,10 +46,12 @@ if composer show knuckleswtf/scribe > /dev/null 2>&1; then
# Create combined hash of all .php files in those paths # Create combined hash of all .php files in those paths
CURRENT_HASH=$(find $SCRIBE_SOURCES -type f -name "*.php" -exec sha1sum {} + | sha1sum) 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..." echo ">> Generating API documentation..."
gosu www php artisan scribe:generate --no-interaction || true gosu www php artisan scribe:generate --no-interaction \
echo "$CURRENT_HASH" > .scribe-hash || echo ">> Warning: Scribe generation failed, continuing..."
echo "$CURRENT_HASH" > .hashes/.scribe-hash
chown www: .hashes/.scribe-hash
else else
echo ">> API docs up to date, skipping Scribe generation." echo ">> API docs up to date, skipping Scribe generation."
fi fi