-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathupdate_docker_compose.py
executable file
·51 lines (45 loc) · 1.47 KB
/
update_docker_compose.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python3
# update docker-compose.yaml with release version or dev version.
import json
import sys
import urllib.request
from collections import OrderedDict
import ruamel.yaml
VERSION_FILE = '../main.go'
DOCKER_COMPOSE = '../docker-compose.yml'
with open(VERSION_FILE, 'r') as f:
for line in f:
if line.startswith('\tversion = '):
RELEASE_VER = line.split('"')[1]
DEV = RELEASE_VER.endswith('.dev')
# For dev versions, add this config.
DEV_SERVICE_OVERRIDE = {
'plugin': {'build': {'context': '.'}},
}
# For non-dev versions, delete this config.
NON_DEV_SERVICE_DELETE = {
'plugin': ['build'],
}
# Broadly preserves formatting.
yaml = ruamel.yaml.YAML()
assert not yaml.preserve_quotes
yaml.preserve_quotes = True
yaml.indent(mapping=2, sequence=2, offset=2)
dc = yaml.load(
open(DOCKER_COMPOSE).read())
for service, service_config in dc['services'].items():
image, _ = service_config['image'].split(':')
if DEV:
version = 'latest'
if service in DEV_SERVICE_OVERRIDE:
service_config.update(DEV_SERVICE_OVERRIDE[service])
else:
version = 'v' + RELEASE_VER
del_keys = NON_DEV_SERVICE_DELETE.get(service, None)
if del_keys:
for del_key in del_keys:
if del_key in service_config:
del service_config[del_key]
if service == 'plugin':
service_config['image'] = ':'.join((image, version))
yaml.dump(dc, open(DOCKER_COMPOSE, 'w'))