feat: 적용 무중단 배포 시스템 (Blue-Green Deployment)
Some checks failed
Deploy to OCIWP / deploy (push) Failing after 51s
Some checks failed
Deploy to OCIWP / deploy (push) Failing after 51s
This commit is contained in:
66
scratch_rewrite.py
Normal file
66
scratch_rewrite.py
Normal file
@@ -0,0 +1,66 @@
|
||||
import yaml
|
||||
import copy
|
||||
|
||||
with open('docker-compose.yml', 'r') as f:
|
||||
compose = yaml.safe_load(f)
|
||||
|
||||
services = compose['services']
|
||||
new_services = {}
|
||||
|
||||
# Services to duplicate
|
||||
app_services = ['gateway', 'tool-sms', 'tool-email', 'tool-other', 'tool-payment']
|
||||
|
||||
for name, svc in services.items():
|
||||
if name in app_services:
|
||||
# Create blue
|
||||
blue_svc = copy.deepcopy(svc)
|
||||
if 'ports' in blue_svc:
|
||||
del blue_svc['ports'] # Nginx will handle ports
|
||||
|
||||
# Update AXHUB_GATEWAY_URL and AXHUB_TOOL_URL to point to blue if they refer to the base name
|
||||
if 'environment' in blue_svc:
|
||||
env = blue_svc['environment']
|
||||
for i, e in enumerate(env):
|
||||
if isinstance(e, str):
|
||||
env[i] = e.replace('http://gateway:8081', 'http://gateway-blue:8081')
|
||||
env[i] = env[i].replace(f'http://{name}:', f'http://{name}-blue:')
|
||||
|
||||
new_services[f'{name}-blue'] = blue_svc
|
||||
|
||||
# Create green
|
||||
green_svc = copy.deepcopy(svc)
|
||||
if 'ports' in green_svc:
|
||||
del green_svc['ports']
|
||||
|
||||
if 'environment' in green_svc:
|
||||
env = green_svc['environment']
|
||||
for i, e in enumerate(env):
|
||||
if isinstance(e, str):
|
||||
env[i] = e.replace('http://gateway-blue:8081', 'http://gateway-green:8081') # replace from previous
|
||||
env[i] = e.replace('http://gateway:8081', 'http://gateway-green:8081')
|
||||
env[i] = env[i].replace(f'http://{name}:', f'http://{name}-green:')
|
||||
|
||||
new_services[f'{name}-green'] = green_svc
|
||||
else:
|
||||
new_services[name] = svc
|
||||
|
||||
# Add nginx
|
||||
new_services['nginx'] = {
|
||||
'image': 'nginx:latest',
|
||||
'ports': [
|
||||
'8281:8281',
|
||||
'8282:8282',
|
||||
'8283:8283',
|
||||
'8284:8284',
|
||||
'8285:8285'
|
||||
],
|
||||
'volumes': [
|
||||
'./nginx/conf.d:/etc/nginx/conf.d'
|
||||
],
|
||||
'depends_on': ['redis']
|
||||
}
|
||||
|
||||
compose['services'] = new_services
|
||||
|
||||
with open('docker-compose.yml', 'w') as f:
|
||||
yaml.dump(compose, f, sort_keys=False, default_flow_style=False)
|
||||
Reference in New Issue
Block a user