feat: Shared code volume for nginx and app containers
- Add app-code volume to both nginx and app containers - App container clones code once into shared volume - Nginx container uses shared volume (read-only) and waits for code - Update entrypoint.sh to handle storage-preserving git clone - Fix nginx configuration to use app:9000 for PHP-FPM This eliminates duplicate code cloning and ensures both containers always use the same code version from the shared volume.
This commit is contained in:
@@ -13,6 +13,7 @@ services:
|
|||||||
- APP_ENV=${APP_ENV:-production}
|
- APP_ENV=${APP_ENV:-production}
|
||||||
- APP_DEBUG=${APP_DEBUG:-false}
|
- APP_DEBUG=${APP_DEBUG:-false}
|
||||||
- APP_URL=${APP_URL:-https://michaelschiemer.de}
|
- APP_URL=${APP_URL:-https://michaelschiemer.de}
|
||||||
|
- APP_KEY=${APP_KEY:-}
|
||||||
# Git Repository (optional - if set, container will clone/pull code on start)
|
# Git Repository (optional - if set, container will clone/pull code on start)
|
||||||
- GIT_REPOSITORY_URL=${GIT_REPOSITORY_URL:-}
|
- GIT_REPOSITORY_URL=${GIT_REPOSITORY_URL:-}
|
||||||
- GIT_BRANCH=${GIT_BRANCH:-main}
|
- GIT_BRANCH=${GIT_BRANCH:-main}
|
||||||
@@ -39,6 +40,7 @@ services:
|
|||||||
- QUEUE_DRIVER=redis
|
- QUEUE_DRIVER=redis
|
||||||
- QUEUE_CONNECTION=default
|
- QUEUE_CONNECTION=default
|
||||||
volumes:
|
volumes:
|
||||||
|
- app-code:/var/www/html
|
||||||
- app-storage:/var/www/html/storage
|
- app-storage:/var/www/html/storage
|
||||||
- app-logs:/var/www/html/storage/logs
|
- app-logs:/var/www/html/storage/logs
|
||||||
- /etc/timezone:/etc/timezone:ro
|
- /etc/timezone:/etc/timezone:ro
|
||||||
|
|||||||
@@ -49,15 +49,26 @@ if [ -n "$GIT_REPOSITORY_URL" ]; then
|
|||||||
echo "📥 Cloning repository from $GIT_REPOSITORY_URL (branch: $GIT_BRANCH)..."
|
echo "📥 Cloning repository from $GIT_REPOSITORY_URL (branch: $GIT_BRANCH)..."
|
||||||
|
|
||||||
# Remove existing files if they exist (from image build)
|
# Remove existing files if they exist (from image build)
|
||||||
|
# But preserve storage directory if it's a volume mount
|
||||||
if [ "$(ls -A $GIT_TARGET_DIR 2>/dev/null)" ]; then
|
if [ "$(ls -A $GIT_TARGET_DIR 2>/dev/null)" ]; then
|
||||||
echo "🗑️ Cleaning existing files..."
|
echo "🗑️ Cleaning existing files (preserving storage)..."
|
||||||
rm -rf "$GIT_TARGET_DIR"/* "$GIT_TARGET_DIR"/.* 2>/dev/null || true
|
find "$GIT_TARGET_DIR" -mindepth 1 -maxdepth 1 ! -name "storage" -exec rm -rf {} \; 2>/dev/null || true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Clone repository
|
# Clone into temporary directory first, then move contents (preserving storage)
|
||||||
git clone --branch "$GIT_BRANCH" --depth 1 "$GIT_URL_WITH_AUTH" "$GIT_TARGET_DIR" || {
|
TEMP_CLONE="${GIT_TARGET_DIR}.tmp"
|
||||||
|
rm -rf "$TEMP_CLONE" 2>/dev/null || true
|
||||||
|
if git clone --branch "$GIT_BRANCH" --depth 1 "$GIT_URL_WITH_AUTH" "$TEMP_CLONE"; then
|
||||||
|
# Remove only files/dirs that are not storage (which might be a volume mount)
|
||||||
|
find "$GIT_TARGET_DIR" -mindepth 1 -maxdepth 1 ! -name "storage" -exec rm -rf {} \; 2>/dev/null || true
|
||||||
|
# Move contents from temp directory to target (preserving storage)
|
||||||
|
find "$TEMP_CLONE" -mindepth 1 -maxdepth 1 ! -name "." ! -name ".." -exec mv {} "$GIT_TARGET_DIR/" \; 2>/dev/null || true
|
||||||
|
rm -rf "$TEMP_CLONE" 2>/dev/null || true
|
||||||
|
echo "✅ Repository cloned successfully"
|
||||||
|
else
|
||||||
echo "❌ Git clone failed. Falling back to image contents."
|
echo "❌ Git clone failed. Falling back to image contents."
|
||||||
}
|
rm -rf "$TEMP_CLONE" 2>/dev/null || true
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
echo "🔄 Pulling latest changes from $GIT_BRANCH..."
|
echo "🔄 Pulling latest changes from $GIT_BRANCH..."
|
||||||
cd "$GIT_TARGET_DIR"
|
cd "$GIT_TARGET_DIR"
|
||||||
|
|||||||
Reference in New Issue
Block a user