mirror of
https://github.com/mempool/mempool.git
synced 2026-08-13 12:33:11 +02:00
Reuse example docker-compose file
This commit is contained in:
parent
893d0deb10
commit
f7a27174f8
1 changed files with 63 additions and 56 deletions
119
.github/workflows/docker.yml
vendored
119
.github/workflows/docker.yml
vendored
|
|
@ -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 <<EOF
|
||||
version: "3.7"
|
||||
|
||||
services:
|
||||
web:
|
||||
environment:
|
||||
FRONTEND_HTTP_PORT: "8080"
|
||||
BACKEND_MAINNET_HTTP_HOST: "api"
|
||||
image: test-frontend:$TAG
|
||||
user: "1000:1000"
|
||||
restart: on-failure
|
||||
stop_grace_period: 1m
|
||||
command: "./wait-for db:3306 --timeout=720 -- nginx -g 'daemon off;'"
|
||||
ports:
|
||||
- "8080:8080"
|
||||
depends_on:
|
||||
- api
|
||||
- db
|
||||
api:
|
||||
environment:
|
||||
MEMPOOL_BACKEND: "none"
|
||||
CORE_RPC_HOST: "172.27.0.1"
|
||||
CORE_RPC_PORT: "8332"
|
||||
CORE_RPC_USERNAME: "mempool"
|
||||
CORE_RPC_PASSWORD: "mempool"
|
||||
DATABASE_ENABLED: "true"
|
||||
DATABASE_HOST: "db"
|
||||
DATABASE_DATABASE: "mempool"
|
||||
DATABASE_USERNAME: "mempool"
|
||||
DATABASE_PASSWORD: "mempool"
|
||||
STATISTICS_ENABLED: "true"
|
||||
image: test-backend:$TAG
|
||||
user: "1000:1000"
|
||||
restart: on-failure
|
||||
stop_grace_period: 1m
|
||||
command: "./wait-for-it.sh db:3306 --timeout=720 --strict -- ./start.sh"
|
||||
depends_on:
|
||||
- db
|
||||
db:
|
||||
environment:
|
||||
MYSQL_DATABASE: "mempool"
|
||||
MYSQL_USER: "mempool"
|
||||
MYSQL_PASSWORD: "mempool"
|
||||
MYSQL_ROOT_PASSWORD: "admin"
|
||||
image: mariadb:10.5.21
|
||||
restart: on-failure
|
||||
stop_grace_period: 1m
|
||||
tmpfs:
|
||||
- /var/lib/mysql
|
||||
healthcheck:
|
||||
test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "mempool", "-pmempool"]
|
||||
interval: 5s
|
||||
timeout: 5s
|
||||
retries: 10
|
||||
EOF
|
||||
cat > /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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue