Fix Docker builds when livewire-tmp is root-owned.
Exclude whole storage trees from the build context, create cache dirs before dump-autoload, and drop Buildx-only cache mounts.
This commit is contained in:
+7
-6
@@ -10,12 +10,13 @@ node_modules
|
|||||||
vendor
|
vendor
|
||||||
public/build
|
public/build
|
||||||
public/hot
|
public/hot
|
||||||
storage/app/private/**
|
# Exclude whole trees (not only /**) so Docker never tries to stat root-owned tmp dirs
|
||||||
storage/app/public/**
|
storage/app/private
|
||||||
storage/logs/**
|
storage/app/public
|
||||||
storage/framework/cache/**
|
storage/logs
|
||||||
storage/framework/sessions/**
|
storage/framework/cache
|
||||||
storage/framework/views/**
|
storage/framework/sessions
|
||||||
|
storage/framework/views
|
||||||
database/*.sqlite*
|
database/*.sqlite*
|
||||||
.env
|
.env
|
||||||
.env.*
|
.env.*
|
||||||
|
|||||||
+7
-8
@@ -9,8 +9,7 @@ WORKDIR /app
|
|||||||
|
|
||||||
COPY composer.json composer.lock ./
|
COPY composer.json composer.lock ./
|
||||||
|
|
||||||
RUN --mount=type=cache,target=/tmp/cache \
|
RUN composer install \
|
||||||
composer install \
|
|
||||||
--no-dev \
|
--no-dev \
|
||||||
--no-scripts \
|
--no-scripts \
|
||||||
--no-autoloader \
|
--no-autoloader \
|
||||||
@@ -18,7 +17,7 @@ RUN --mount=type=cache,target=/tmp/cache \
|
|||||||
--no-interaction
|
--no-interaction
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# npm ci only (parallel with vendor — does not wait on Composer)
|
# npm ci only (parallel with vendor when BuildKit is available)
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
FROM node:22-bookworm AS npm
|
FROM node:22-bookworm AS npm
|
||||||
|
|
||||||
@@ -26,8 +25,7 @@ WORKDIR /app
|
|||||||
|
|
||||||
COPY package.json package-lock.json ./
|
COPY package.json package-lock.json ./
|
||||||
|
|
||||||
RUN --mount=type=cache,target=/root/.npm \
|
RUN npm ci
|
||||||
npm ci
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# Vite production build (needs Flux/Livewire + Laravel pagination views)
|
# Vite production build (needs Flux/Livewire + Laravel pagination views)
|
||||||
@@ -85,14 +83,14 @@ WORKDIR /app
|
|||||||
COPY --from=vendor /app/vendor ./vendor
|
COPY --from=vendor /app/vendor ./vendor
|
||||||
COPY composer.json composer.lock ./
|
COPY composer.json composer.lock ./
|
||||||
|
|
||||||
# Application source (.dockerignore excludes vendor, node_modules, public/build)
|
# Application source (.dockerignore excludes vendor, node_modules, public/build, storage uploads)
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
# Built frontend assets
|
# Built frontend assets
|
||||||
COPY --from=assets /app/public/build ./public/build
|
COPY --from=assets /app/public/build ./public/build
|
||||||
|
|
||||||
RUN composer dump-autoload --optimize --no-dev \
|
# Framework/view cache paths must exist before package:discover runs during dump-autoload
|
||||||
&& mkdir -p \
|
RUN mkdir -p \
|
||||||
storage/app/private \
|
storage/app/private \
|
||||||
storage/app/public \
|
storage/app/public \
|
||||||
storage/framework/cache \
|
storage/framework/cache \
|
||||||
@@ -101,6 +99,7 @@ RUN composer dump-autoload --optimize --no-dev \
|
|||||||
storage/logs \
|
storage/logs \
|
||||||
database \
|
database \
|
||||||
bootstrap/cache \
|
bootstrap/cache \
|
||||||
|
&& composer dump-autoload --optimize --no-dev \
|
||||||
&& chown -R www-data:www-data storage bootstrap/cache database
|
&& chown -R www-data:www-data storage bootstrap/cache database
|
||||||
|
|
||||||
EXPOSE 80
|
EXPOSE 80
|
||||||
|
|||||||
@@ -125,6 +125,14 @@ docker compose up -d
|
|||||||
|
|
||||||
Data under `./database`, `./storage/app`, and `./storage/logs` is kept on the host.
|
Data under `./database`, `./storage/app`, and `./storage/logs` is kept on the host.
|
||||||
|
|
||||||
|
If `docker compose build` fails with `can't stat .../storage/app/private/livewire-tmp`, a container created that directory as root. Fix ownership (or remove it), then rebuild:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo chown -R "$USER:$USER" storage
|
||||||
|
# or: sudo rm -rf storage/app/private/livewire-tmp
|
||||||
|
docker compose up --build -d
|
||||||
|
```
|
||||||
|
|
||||||
### Live reload while developing
|
### Live reload while developing
|
||||||
|
|
||||||
Default Compose uses the built image, so PHP/Blade/CSS/JS changes need a rebuild. For day-to-day work, use the dev overlay (bind-mounts the repo and runs Vite HMR):
|
Default Compose uses the built image, so PHP/Blade/CSS/JS changes need a rebuild. For day-to-day work, use the dev overlay (bind-mounts the repo and runs Vite HMR):
|
||||||
|
|||||||
Reference in New Issue
Block a user