From f7a27174f8608c221cc37718b9ef60a55467dd26 Mon Sep 17 00:00:00 2001 From: Felipe Knorr Kuhn Date: Sat, 29 Nov 2025 18:42:37 -0800 Subject: [PATCH] Reuse example docker-compose file --- .github/workflows/docker.yml | 119 ++++++++++++++++++----------------- 1 file changed, 63 insertions(+), 56 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 18f95b340..c1aeb6d3c 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -238,63 +238,70 @@ jobs: --platform linux/amd64 \ ./backend/ - - name: Generate docker-compose test file + - name: Prepare docker-compose test file run: | - cat > docker-compose.test.yml < /tmp/modify_compose.py << 'SCRIPT_END' + import re + import os + import sys + + # Read the base docker-compose file + with open('docker/docker-compose.yml', 'r') as f: + content = f.read() + + # Get TAG from environment + tag = os.environ.get('TAG', '') + + # Replace image names with locally built test images + content = content.replace('image: mempool/frontend:latest', f'image: test-frontend:{tag}') + content = content.replace('image: mempool/backend:latest', f'image: test-backend:{tag}') + + # Change web port mapping from 80:8080 to 8080:8080 + content = content.replace('- 80:8080', '- 8080:8080') + + # Remove volumes from api service + content = re.sub(r' volumes:\n - \.\/data:\/backend\/cache\n', '', content) + + # For db service: remove user and volumes, add tmpfs and healthcheck + # Remove user line from db service (only the one in db service) + lines = content.split('\n') + in_db_service = False + new_lines = [] + for i, line in enumerate(lines): + if line.strip().startswith('db:'): + in_db_service = True + elif line.strip() and not line.startswith(' ') and not line.startswith('\t'): + in_db_service = False + if in_db_service and line.strip() == 'user: "1000:1000"': + continue + new_lines.append(line) + content = '\n'.join(new_lines) + + # Remove volumes section from db service + content = re.sub(r' volumes:\n - \.\/mysql\/data:\/var\/lib\/mysql\n', '', content) + + # Add tmpfs and healthcheck after stop_grace_period in db service + db_stop_grace = ' stop_grace_period: 1m' + db_additions = ' stop_grace_period: 1m\n tmpfs:\n - /var/lib/mysql\n healthcheck:\n test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "mempool", "-pmempool"]\n interval: 5s\n timeout: 5s\n retries: 10' + content = content.replace(db_stop_grace, db_additions, 1) + + # Add depends_on to web service after ports + web_ports = ' ports:\n - 8080:8080' + web_with_depends = ' ports:\n - 8080:8080\n depends_on:\n - api\n - db' + content = content.replace(web_ports, web_with_depends, 1) + + # Add depends_on to api service after command + api_command = ' command: "./wait-for-it.sh db:3306 --timeout=720 --strict -- ./start.sh"' + api_with_depends = ' command: "./wait-for-it.sh db:3306 --timeout=720 --strict -- ./start.sh"\n depends_on:\n - db' + content = content.replace(api_command, api_with_depends, 1) + + # Write the modified content + with open('docker-compose.test.yml', 'w') as f: + f.write(content) + + print("Generated docker-compose.test.yml") + SCRIPT_END + python3 /tmp/modify_compose.py cat docker-compose.test.yml - name: Start containers