+++ fix
This commit is contained in:
@@ -39,11 +39,30 @@ RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
|
|||||||
&& apt-get clean \
|
&& apt-get clean \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
# Set working directory
|
# Build application in staging area
|
||||||
WORKDIR /var/www/html
|
WORKDIR /app-src
|
||||||
|
|
||||||
# Copy application code to staging area
|
# Install PHP dependencies first for better Docker layer caching
|
||||||
COPY . /app-src/
|
COPY composer.json composer.lock ./
|
||||||
|
RUN composer install --no-interaction --prefer-dist --no-progress --no-scripts
|
||||||
|
|
||||||
|
# Install Node dependencies first for better Docker layer caching
|
||||||
|
COPY package.json package-lock.json* ./
|
||||||
|
RUN if [ -f package-lock.json ]; then \
|
||||||
|
npm ci --no-audit --no-fund; \
|
||||||
|
else \
|
||||||
|
npm install --no-audit --no-fund; \
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Copy full source and build frontend assets
|
||||||
|
COPY . .
|
||||||
|
RUN mkdir -p bootstrap/cache storage/framework/cache storage/framework/sessions storage/framework/views storage/logs storage/app
|
||||||
|
RUN if [ ! -f .env ] && [ -f .env.example ]; then cp .env.example .env; fi
|
||||||
|
RUN composer dump-autoload --optimize --no-interaction
|
||||||
|
RUN npm run build
|
||||||
|
|
||||||
|
# Runtime working directory
|
||||||
|
WORKDIR /var/www/html
|
||||||
|
|
||||||
# Copy PHP configuration
|
# Copy PHP configuration
|
||||||
COPY docker/php/php.ini /usr/local/etc/php/conf.d/custom.ini
|
COPY docker/php/php.ini /usr/local/etc/php/conf.d/custom.ini
|
||||||
|
|||||||
@@ -1,10 +1,42 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e
|
set -Eeuo pipefail
|
||||||
|
|
||||||
echo "========================================="
|
echo "========================================="
|
||||||
echo " TerManager2 - Entrypoint"
|
echo " TerManager2 - Entrypoint"
|
||||||
echo "========================================="
|
echo "========================================="
|
||||||
|
|
||||||
|
warn() {
|
||||||
|
echo "[!] $*"
|
||||||
|
}
|
||||||
|
|
||||||
|
retry() {
|
||||||
|
local attempts="$1"
|
||||||
|
local delay="$2"
|
||||||
|
shift 2
|
||||||
|
|
||||||
|
local n=1
|
||||||
|
until "$@"; do
|
||||||
|
if [ "$n" -ge "$attempts" ]; then
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
warn "Command failed (attempt ${n}/${attempts}). Retrying in ${delay}s..."
|
||||||
|
sleep "$delay"
|
||||||
|
n=$((n + 1))
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
upsert_env() {
|
||||||
|
local key="$1"
|
||||||
|
local value="$2"
|
||||||
|
local env_file="$3"
|
||||||
|
|
||||||
|
if grep -q "^${key}=" "$env_file"; then
|
||||||
|
sed -i "s|^${key}=.*|${key}=${value}|" "$env_file"
|
||||||
|
else
|
||||||
|
echo "${key}=${value}" >> "$env_file"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# -----------------------------------------------
|
# -----------------------------------------------
|
||||||
# 0. Sync application code from image to volume
|
# 0. Sync application code from image to volume
|
||||||
# -----------------------------------------------
|
# -----------------------------------------------
|
||||||
@@ -20,6 +52,7 @@ fi
|
|||||||
# -----------------------------------------------
|
# -----------------------------------------------
|
||||||
mkdir -p storage/framework/{cache,sessions,views}
|
mkdir -p storage/framework/{cache,sessions,views}
|
||||||
mkdir -p storage/logs
|
mkdir -p storage/logs
|
||||||
|
mkdir -p storage/app
|
||||||
mkdir -p bootstrap/cache
|
mkdir -p bootstrap/cache
|
||||||
chown -R www-data:www-data storage bootstrap/cache
|
chown -R www-data:www-data storage bootstrap/cache
|
||||||
|
|
||||||
@@ -33,41 +66,51 @@ fi
|
|||||||
|
|
||||||
# Override .env values with Docker environment variables (if set)
|
# Override .env values with Docker environment variables (if set)
|
||||||
# This ensures Dokploy env vars take precedence
|
# This ensures Dokploy env vars take precedence
|
||||||
if [ -n "$APP_KEY" ]; then
|
if [ -n "${APP_KEY:-}" ]; then
|
||||||
sed -i "s|^APP_KEY=.*|APP_KEY=${APP_KEY}|" .env
|
upsert_env "APP_KEY" "${APP_KEY}" .env
|
||||||
fi
|
fi
|
||||||
if [ -n "$APP_URL" ]; then
|
if [ -n "${APP_URL:-}" ]; then
|
||||||
sed -i "s|^APP_URL=.*|APP_URL=${APP_URL}|" .env
|
upsert_env "APP_URL" "${APP_URL}" .env
|
||||||
fi
|
fi
|
||||||
if [ -n "$DB_HOST" ]; then
|
if [ -n "${DB_HOST:-}" ]; then
|
||||||
sed -i "s|^DB_HOST=.*|DB_HOST=${DB_HOST}|" .env
|
upsert_env "DB_HOST" "${DB_HOST}" .env
|
||||||
fi
|
fi
|
||||||
if [ -n "$DB_DATABASE" ]; then
|
if [ -n "${DB_DATABASE:-}" ]; then
|
||||||
sed -i "s|^DB_DATABASE=.*|DB_DATABASE=${DB_DATABASE}|" .env
|
upsert_env "DB_DATABASE" "${DB_DATABASE}" .env
|
||||||
fi
|
fi
|
||||||
if [ -n "$DB_USERNAME" ]; then
|
if [ -n "${DB_USERNAME:-}" ]; then
|
||||||
sed -i "s|^DB_USERNAME=.*|DB_USERNAME=${DB_USERNAME}|" .env
|
upsert_env "DB_USERNAME" "${DB_USERNAME}" .env
|
||||||
fi
|
fi
|
||||||
if [ -n "$DB_PASSWORD" ]; then
|
if [ -n "${DB_PASSWORD:-}" ]; then
|
||||||
sed -i "s|^DB_PASSWORD=.*|DB_PASSWORD=${DB_PASSWORD}|" .env
|
upsert_env "DB_PASSWORD" "${DB_PASSWORD}" .env
|
||||||
fi
|
fi
|
||||||
if [ -n "$REDIS_HOST" ]; then
|
if [ -n "${REDIS_HOST:-}" ]; then
|
||||||
sed -i "s|^REDIS_HOST=.*|REDIS_HOST=${REDIS_HOST}|" .env
|
upsert_env "REDIS_HOST" "${REDIS_HOST}" .env
|
||||||
fi
|
fi
|
||||||
if [ -n "$REDIS_PASSWORD" ]; then
|
if [ -n "${REDIS_PASSWORD:-}" ]; then
|
||||||
sed -i "s|^REDIS_PASSWORD=.*|REDIS_PASSWORD=${REDIS_PASSWORD}|" .env
|
upsert_env "REDIS_PASSWORD" "${REDIS_PASSWORD}" .env
|
||||||
fi
|
fi
|
||||||
echo "[✓] .env file ready."
|
echo "[✓] .env file ready."
|
||||||
|
|
||||||
# -----------------------------------------------
|
# -----------------------------------------------
|
||||||
# 2. Application key (persisted in storage volume)
|
# 2. Composer install (must run before artisan commands)
|
||||||
|
# -----------------------------------------------
|
||||||
|
if [ ! -f vendor/autoload.php ]; then
|
||||||
|
echo "[*] Installing Composer dependencies..."
|
||||||
|
retry 3 5 composer install --no-interaction --prefer-dist --optimize-autoloader --no-progress
|
||||||
|
else
|
||||||
|
echo "[✓] Composer dependencies already installed."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# -----------------------------------------------
|
||||||
|
# 3. Application key (persisted in storage volume)
|
||||||
# -----------------------------------------------
|
# -----------------------------------------------
|
||||||
KEY_FILE="/var/www/html/storage/app/.app_key"
|
KEY_FILE="/var/www/html/storage/app/.app_key"
|
||||||
|
|
||||||
if [ -f "$KEY_FILE" ]; then
|
if [ -f "$KEY_FILE" ]; then
|
||||||
# Restore key from persistent volume
|
# Restore key from persistent volume
|
||||||
STORED_KEY=$(cat "$KEY_FILE")
|
STORED_KEY=$(cat "$KEY_FILE")
|
||||||
sed -i "s|^APP_KEY=.*|APP_KEY=${STORED_KEY}|" .env
|
upsert_env "APP_KEY" "$STORED_KEY" .env
|
||||||
echo "[✓] Application key restored from storage."
|
echo "[✓] Application key restored from storage."
|
||||||
elif grep -q "^APP_KEY=$" .env; then
|
elif grep -q "^APP_KEY=$" .env; then
|
||||||
# No stored key and .env has empty key: generate new one
|
# No stored key and .env has empty key: generate new one
|
||||||
@@ -82,27 +125,21 @@ else
|
|||||||
echo "[✓] Application key already set, saved to persistent storage."
|
echo "[✓] Application key already set, saved to persistent storage."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# -----------------------------------------------
|
|
||||||
# 3. Composer install
|
|
||||||
# -----------------------------------------------
|
|
||||||
if [ ! -f vendor/autoload.php ]; then
|
|
||||||
echo "[*] Installing Composer dependencies..."
|
|
||||||
composer install --no-interaction --optimize-autoloader
|
|
||||||
else
|
|
||||||
echo "[✓] Composer dependencies already installed."
|
|
||||||
fi
|
|
||||||
|
|
||||||
# -----------------------------------------------
|
# -----------------------------------------------
|
||||||
# 4. NPM install & build assets
|
# 4. NPM install & build assets
|
||||||
# -----------------------------------------------
|
# -----------------------------------------------
|
||||||
if [ ! -d node_modules ]; then
|
if [ ! -d node_modules ]; then
|
||||||
echo "[*] Installing NPM dependencies..."
|
echo "[*] Installing NPM dependencies..."
|
||||||
npm ci
|
if [ -f package-lock.json ]; then
|
||||||
|
retry 3 5 npm ci --no-audit --no-fund
|
||||||
|
else
|
||||||
|
retry 3 5 npm install --no-audit --no-fund
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
echo "[✓] NPM dependencies already installed."
|
echo "[✓] NPM dependencies already installed."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -d public/build ]; then
|
if [ ! -f public/build/manifest.json ]; then
|
||||||
echo "[*] Building frontend assets..."
|
echo "[*] Building frontend assets..."
|
||||||
npm run build
|
npm run build
|
||||||
else
|
else
|
||||||
@@ -123,15 +160,15 @@ fi
|
|||||||
# 7. Run migrations
|
# 7. Run migrations
|
||||||
# -----------------------------------------------
|
# -----------------------------------------------
|
||||||
echo "[*] Running database migrations..."
|
echo "[*] Running database migrations..."
|
||||||
php artisan migrate --force
|
retry 10 3 php artisan migrate --force
|
||||||
|
|
||||||
# -----------------------------------------------
|
# -----------------------------------------------
|
||||||
# 8. Cache config/routes/views
|
# 8. Cache config/routes/views
|
||||||
# -----------------------------------------------
|
# -----------------------------------------------
|
||||||
echo "[*] Caching configuration..."
|
echo "[*] Caching configuration..."
|
||||||
php artisan config:cache
|
php artisan config:cache || warn "config:cache failed; continuing startup."
|
||||||
php artisan route:cache
|
php artisan route:cache || warn "route:cache failed; continuing startup."
|
||||||
php artisan view:cache
|
php artisan view:cache || warn "view:cache failed; continuing startup."
|
||||||
|
|
||||||
echo "========================================="
|
echo "========================================="
|
||||||
echo " TerManager2 - Ready!"
|
echo " TerManager2 - Ready!"
|
||||||
|
|||||||
Reference in New Issue
Block a user