Skip to content

Commit b63d2d7

Browse files
committed
Fix couple of sail permissions related issues
1 parent 90d857a commit b63d2d7

3 files changed

Lines changed: 51 additions & 16 deletions

File tree

DOCKER.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,17 @@ Run `make` or `make help` to see all targets, grouped by section.
8383
| `make migrate` | Run pending migrations |
8484
| `make migrate-fresh`| Drop all tables and re-migrate (DATA LOSS) |
8585
| `make seed` | Run database seeders |
86-
| `make cache-clear` | Clear config / route / view / app caches |
87-
| `make optimize` | Cache config / routes / views + spatie/laravel-data |
86+
| `make cache-clear` | Clear config / route / view / app caches (and stale `bootstrap/cache` files) |
87+
| `make optimize` | Dev-safe: warm view cache + spatie/laravel-data |
88+
| `make optimize-deploy` | Production: also caches config/routes (bakes absolute paths) |
8889
| `make queue-work` | Foreground queue worker |
8990
| `make queue-restart`| Signal queue workers to restart |
9091
| `make tmux-start` | Start the NNTmux tmux processing engine |
9192
| `make tmux-stop` | Stop the tmux processing engine |
9293
| `make tmux-attach` | Attach to the running tmux session |
9394
| `make horizon` | Show Horizon queue status |
95+
| `make fix-permissions` | Chown project to host UID + register git `safe.directory` |
96+
| `make fix-permissions` | Chown project to `sail` + register git safe.directory |
9497

9598
### Testing & Quality
9699

@@ -235,7 +238,12 @@ docker compose up -d
235238

236239
| Problem | Solution |
237240
|---------------------------------|-----------------------------------------------------------------------|
238-
| Permission errors on storage/ | `make root-shell` then `chown -R sail:sail storage bootstrap/cache` |
241+
| Permission errors on storage/ | `make fix-permissions` (chowns project to your host UID) |
242+
| `composer install` permission denied | `make fix-permissions`, then re-run `make composer-install` |
243+
| `npm`/`ncu` EACCES on host (`package.json`) | `make fix-permissions` chowns to host UID, not container `sail` |
244+
| `fatal: detected dubious ownership` (git) | `make fix-permissions` registers `safe.directory` in the container |
245+
| Container `sail` UID ≠ host UID | Set `WWWUSER=$(id -u)` / `WWWGROUP=$(id -g)` in `.env`, then `make rebuild` |
246+
| Host artisan/npm fails with `/var/www/html/...` paths | Stale `bootstrap/cache/config.php` from a container `config:cache`. Run `make cache-clear` and prefer `make optimize` (dev-safe) over `optimize-deploy` in development |
239247
| Port already in use | Change `APP_PORT`, `FORWARD_DB_PORT`, etc. in `.env` |
240248
| Containers won't start | `make logs` to inspect, or `make rebuild` to start fresh |
241249
| Stale images after upgrade | `make update` (pulls base images + rebuild + restart) |

Makefile

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ update: check-env pull ## Infra-only: pull base images, rebuild with --pull, res
8282
@$(SAIL) up -d --remove-orphans
8383
@echo "$(GREEN)✔ Infra updated.$(RESET)"
8484
.PHONY: upgrade
85-
upgrade: update composer-install npm-build ## Full app upgrade: update + composer + npm + migrate + caches
85+
upgrade: update fix-permissions composer-install npm-build ## Full app upgrade: update + perms + composer + npm + migrate + caches
8686
@if [ "$(MAINTENANCE)" = "1" ]; then $(SAIL) artisan down; fi
8787
@$(SAIL) artisan migrate --force
8888
@if [ "$(MAINTENANCE)" = "1" ]; then $(SAIL) artisan up; fi
@@ -122,19 +122,26 @@ migrate-fresh: ## Drop all tables and re-run migrations (DATA LOSS!)
122122
seed: ## Run database seeders
123123
@$(SAIL) artisan db:seed --force
124124
.PHONY: cache-clear
125-
cache-clear: ## Clear config / route / view / application caches
125+
cache-clear: ## Clear config / route / view / application caches (and stale bootstrap/cache files)
126126
@$(SAIL) artisan config:clear
127127
@$(SAIL) artisan route:clear
128128
@$(SAIL) artisan view:clear
129129
@$(SAIL) artisan cache:clear
130+
@rm -f bootstrap/cache/config.php bootstrap/cache/routes-v7.php bootstrap/cache/services.php bootstrap/cache/packages.php
130131
@echo "$(GREEN)✔ Caches cleared.$(RESET)"
131132
.PHONY: optimize
132-
optimize: ## Cache config / routes / views and warm spatie/laravel-data
133+
optimize: ## Dev-safe optimize: warm data structures + view cache only (no config/route cache)
134+
@$(SAIL) artisan view:cache
135+
@$(SAIL) artisan data:cache-structures
136+
@echo "$(GREEN)✔ Optimized (dev-safe).$(RESET)"
137+
.PHONY: optimize-deploy
138+
optimize-deploy: ## Production optimize: cache config / routes / views + data structures (bakes absolute paths!)
139+
@echo "$(YELLOW)⚠ This caches absolute paths from inside the container — only run on the deploy host.$(RESET)"
133140
@$(SAIL) artisan config:cache
134141
@$(SAIL) artisan route:cache
135142
@$(SAIL) artisan view:cache
136143
@$(SAIL) artisan data:cache-structures
137-
@echo "$(GREEN)✔ Optimized.$(RESET)"
144+
@echo "$(GREEN)✔ Optimized for deploy.$(RESET)"
138145
.PHONY: queue-work
139146
queue-work: ## Run a foreground queue worker (Ctrl-C to stop)
140147
@$(SAIL) artisan queue:work
@@ -205,6 +212,26 @@ db: ## Open a MariaDB CLI session
205212
.PHONY: redis-cli
206213
redis-cli: ## Open a Redis CLI session
207214
@$(SAIL) redis
215+
# Host UID/GID — used by fix-permissions so files stay writable from BOTH
216+
# the host and the in-container sail user (whose UID should match WWWUSER).
217+
HOST_UID ?= $(shell id -u)
218+
HOST_GID ?= $(shell id -g)
219+
.PHONY: fix-permissions
220+
fix-permissions: ## Align UIDs: remap sail to host UID, chown project, register git safe.directory
221+
@echo "$(YELLOW)→ Remapping container 'sail' user to UID $(HOST_UID) and chowning /var/www/html…$(RESET)"
222+
@$(DOCKER_COMPOSE) exec -u root laravel.test usermod -u $(HOST_UID) -o sail >/dev/null 2>&1 || true
223+
@$(DOCKER_COMPOSE) exec -u root laravel.test groupmod -g $(HOST_GID) -o sail >/dev/null 2>&1 || true
224+
@$(DOCKER_COMPOSE) exec -u root laravel.test chown -R $(HOST_UID):$(HOST_GID) /var/www/html
225+
@$(DOCKER_COMPOSE) exec -u root laravel.test git config --system --add safe.directory /var/www/html
226+
@echo "$(GREEN)✔ Permissions fixed.$(RESET)"
227+
@if [ "$(WWWUSER)" != "$(HOST_UID)" ] || [ -z "$(WWWUSER)" ]; then echo "$(YELLOW)⚠ WWWUSER ($(WWWUSER)) ≠ host UID ($(HOST_UID)). Set WWWUSER=$(HOST_UID) and WWWGROUP=$(HOST_GID) in .env, then run 'make rebuild' to align the container's sail user.$(RESET)"; fi
228+
.PHONY: fix-perms
229+
fix-perms: fix-permissions ## Alias for 'fix-permissions'
230+
231+
.PHONY: git-safe-directory
232+
git-safe-directory: ## Register /var/www/html as a git safe.directory inside the container
233+
@$(DOCKER_COMPOSE) exec -u root laravel.test git config --system --add safe.directory /var/www/html >/dev/null 2>&1 || true
234+
@$(DOCKER_COMPOSE) exec laravel.test git config --global --add safe.directory /var/www/html >/dev/null 2>&1 || true
208235
# ── Logs & Status ────────────────────────────────────────────
209236
.PHONY: logs
210237
logs: ## Tail logs (usage: make logs [SERVICE=mariadb])

package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@
1010
},
1111
"devDependencies": {
1212
"@tailwindcss/forms": "^0.5.11",
13-
"@tailwindcss/vite": "^4.2.2",
14-
"axios": "1.14.0",
13+
"@tailwindcss/vite": "^4.2.4",
14+
"axios": "1.15.2",
1515
"lodash": "^4.18.1",
16-
"npm-check-updates": "^20.0.0",
17-
"prettier": "3.8.1",
18-
"prettier-plugin-blade": "3.1.4",
16+
"npm-check-updates": "^22.0.1",
17+
"prettier": "3.8.3",
18+
"prettier-plugin-blade": "3.1.6",
1919
"prettier-plugin-tailwindcss": "^0.7.2",
20-
"tailwindcss": "^4.2.2",
20+
"tailwindcss": "^4.2.4",
2121
"vite": "^8.0",
22-
"vue": "^3.5.32"
22+
"vue": "^3.5.33"
2323
},
2424
"dependencies": {
2525
"@alpinejs/csp": "^3.15.11",
@@ -30,8 +30,8 @@
3030
"chart.js": "^4.5.1",
3131
"date-fns": "^4.1.0",
3232
"feather-icons": "^4.29.2",
33-
"laravel-echo": "^2.3.3",
34-
"laravel-vite-plugin": "^3.0",
33+
"laravel-echo": "^2.3.4",
34+
"laravel-vite-plugin": "^3.1",
3535
"nested-sort": "^5.2.0",
3636
"vuedraggable": "^4.1.0"
3737
}

0 commit comments

Comments
 (0)