docker: run npm ci and vendor asset setup at build time
Build and Deploy (dev) / build (push) Successful in 5m9s
Build and Deploy (dev) / build (push) Successful in 5m9s
- npm ci in a cached layer (package.json/lock only), setup-vendor.js after copying the app - Entrypoint only installs/copies when node_modules/ or public/assets/vendor is missing or empty (e.g. hidden by a volume) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2ddcb1b6b0
commit
66f13a3953
2 files changed
+17
-5
No files matched your search
+9
-1
@@ -56,7 +56,12 @@ RUN composer install \
|
||||
--no-scripts \
|
||||
--no-autoloader
|
||||
|
||||
# Copy app files (npm setup happens at runtime via entrypoint)
|
||||
# Install npm dependencies (cached layer, only rebuilt when package.json/lock change).
|
||||
# The postinstall script is skipped here; the assets are copied after the app code below.
|
||||
COPY package.json package-lock.json ./
|
||||
RUN npm ci --omit=dev --ignore-scripts
|
||||
|
||||
# Copy app files
|
||||
COPY . .
|
||||
|
||||
# Create storage directories
|
||||
@@ -72,6 +77,9 @@ RUN mkdir -p \
|
||||
# Generate the optimized autoloader and run composer scripts (package:discover)
|
||||
RUN composer dump-autoload --no-dev --optimize --no-interaction
|
||||
|
||||
# Copy the npm packages into public/assets/vendor
|
||||
RUN node scripts/setup-vendor.js
|
||||
|
||||
# Copy and set up entrypoint script
|
||||
COPY docker-entrypoint.sh /usr/local/bin/
|
||||
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
|
||||
|
||||
@@ -25,10 +25,14 @@ if [ ! -f vendor/autoload.php ]; then
|
||||
--optimize-autoloader
|
||||
fi
|
||||
|
||||
# Install npm dependencies if package.json has dependencies
|
||||
if grep -q "\"dependencies\"" package.json; then
|
||||
echo "Installing npm packages..."
|
||||
npm ci --omit=dev
|
||||
# npm packages and public/assets/vendor are also built into the image. Only
|
||||
# (re)create them here as a fallback, e.g. when they are hidden by a volume.
|
||||
if [ ! -d node_modules ]; then
|
||||
echo "node_modules/ missing, installing npm packages..."
|
||||
npm ci --omit=dev --ignore-scripts
|
||||
node scripts/setup-vendor.js
|
||||
elif [ -z "$(ls -A public/assets/vendor 2>/dev/null)" ]; then
|
||||
echo "public/assets/vendor is empty, copying npm packages..."
|
||||
node scripts/setup-vendor.js
|
||||
fi
|
||||
|
||||
|
||||
Reference in new issue
Block a user