Fix docker-compose processing: use awk instead of Python for multi-line regex
This commit is contained in:
76
default.nix
76
default.nix
@@ -104,56 +104,32 @@ let
|
||||
|
||||
# Process docker-compose.yml - replace paths, hostnames, and configure SDK from Nix
|
||||
if [ -f $src/docker-compose.yml ]; then
|
||||
# Use Python for multi-line block removal
|
||||
${pkgs.python3}/bin/python3 <<PYTHON_SCRIPT > $TMPDIR/docker-compose.yml
|
||||
import re
|
||||
|
||||
with open('$src/docker-compose.yml', 'r') as f:
|
||||
content = f.read()
|
||||
|
||||
# Replace paths and hostnames
|
||||
replacements = [
|
||||
(r'env_file:.*management-dashboard-web-app/\\.env', 'env_file: /var/lib/usda-vision/.env'),
|
||||
(r'\\./management-dashboard-web-app/\\.env', '/var/lib/usda-vision/.env'),
|
||||
(r'\\./management-dashboard-web-app', '/var/lib/usda-vision/management-dashboard-web-app'),
|
||||
(r'\\./media-api', '/var/lib/usda-vision/media-api'),
|
||||
(r'\\./video-remote', '/var/lib/usda-vision/video-remote'),
|
||||
(r'\\./scheduling-remote', '/var/lib/usda-vision/scheduling-remote'),
|
||||
(r'\\./vision-system-remote', '/var/lib/usda-vision/vision-system-remote'),
|
||||
(r'\\./camera-management-api', '/var/lib/usda-vision/camera-management-api'),
|
||||
('exp-dash', '192.168.1.156'),
|
||||
('localhost', '192.168.1.156'),
|
||||
('LD_LIBRARY_PATH=/usr/local/lib:/lib:/usr/lib', 'LD_LIBRARY_PATH=/lib/camera-sdk:/usr/local/lib:/lib:/usr/lib'),
|
||||
]
|
||||
|
||||
for pattern, replacement in replacements:
|
||||
content = re.sub(pattern, replacement, content)
|
||||
|
||||
# Add SDK volume mount after timezone mount
|
||||
content = re.sub(
|
||||
r'( - /etc/timezone:/etc/timezone:ro)',
|
||||
r'\\1\\n - \${camera-sdk}/lib:/lib/camera-sdk:ro',
|
||||
content
|
||||
)
|
||||
|
||||
# Remove SDK installation blocks (first block)
|
||||
content = re.sub(
|
||||
r' # Only install system packages if not already installed.*?else\\n.*?echo.*?System dependencies already installed.*?fi\\n',
|
||||
'',
|
||||
content,
|
||||
flags=re.DOTALL
|
||||
)
|
||||
|
||||
# Remove SDK installation blocks (second block)
|
||||
content = re.sub(
|
||||
r' # Install camera SDK if not already installed.*?fi;\\n',
|
||||
'',
|
||||
content,
|
||||
flags=re.DOTALL
|
||||
)
|
||||
|
||||
print(content, end='')
|
||||
PYTHON_SCRIPT
|
||||
# Basic path and hostname replacements with sed
|
||||
${pkgs.gnused}/bin/sed \
|
||||
-e 's|env_file:.*management-dashboard-web-app/\.env|env_file: /var/lib/usda-vision/.env|g' \
|
||||
-e 's|\./management-dashboard-web-app/\.env|/var/lib/usda-vision/.env|g' \
|
||||
-e 's|\./management-dashboard-web-app|/var/lib/usda-vision/management-dashboard-web-app|g' \
|
||||
-e 's|\./media-api|/var/lib/usda-vision/media-api|g' \
|
||||
-e 's|\./video-remote|/var/lib/usda-vision/video-remote|g' \
|
||||
-e 's|\./scheduling-remote|/var/lib/usda-vision/scheduling-remote|g' \
|
||||
-e 's|\./vision-system-remote|/var/lib/usda-vision/vision-system-remote|g' \
|
||||
-e 's|\./camera-management-api|/var/lib/usda-vision/camera-management-api|g' \
|
||||
-e 's|exp-dash|192.168.1.156|g' \
|
||||
-e 's|localhost|192.168.1.156|g' \
|
||||
-e '/^ - \/etc\/timezone:\/etc\/timezone:ro$/a\ - ${camera-sdk}/lib:/lib/camera-sdk:ro' \
|
||||
-e 's|LD_LIBRARY_PATH=/usr/local/lib:/lib:/usr/lib|LD_LIBRARY_PATH=/lib/camera-sdk:/usr/local/lib:/lib:/usr/lib|' \
|
||||
$src/docker-compose.yml > $TMPDIR/docker-compose-step1.yml
|
||||
|
||||
# Remove SDK installation blocks using awk for better multi-line handling
|
||||
${pkgs.gawk}/bin/awk '
|
||||
/# Only install system packages if not already installed/ { skip=1 }
|
||||
skip && /^ fi$/ { skip=0; next }
|
||||
/# Install camera SDK if not already installed/ { skip_sdk=1 }
|
||||
skip_sdk && /^ fi;$/ { skip_sdk=0; next }
|
||||
!skip && !skip_sdk { print }
|
||||
' $TMPDIR/docker-compose-step1.yml > $TMPDIR/docker-compose.yml
|
||||
|
||||
rm -f $TMPDIR/docker-compose-step1.yml
|
||||
fi
|
||||
|
||||
# Copy all application files using rsync with chmod, excluding files we'll provide separately
|
||||
|
||||
Reference in New Issue
Block a user