forked from fossasia/open-event-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker.py
More file actions
54 lines (39 loc) · 1.36 KB
/
docker.py
File metadata and controls
54 lines (39 loc) · 1.36 KB
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
52
53
54
import logging
from command import execute
logger = logging.getLogger(__name__)
class DockerComposeError(Exception):
def __init__(self, message, errors):
super().__init__(message)
self.message = message
self.errors = errors
def __str__(self):
return '{}:\n {}'.format(self.message, self.errors)
def _docker_compose(cwd, *cmd):
retcode, out, err = execute(cwd, '/usr/bin/docker-compose', *cmd)
if retcode == 0:
return out
logger.error('docker-compose failed: %s', cwd)
raise DockerComposeError('docker-compose exited with a non-zero exit code', err)
class DockerCompose:
def __init__(self, cwd):
self.cwd = cwd
def ps(self):
return _docker_compose(self.cwd, 'ps')
def start(self):
logger.info('starting up...')
res = _docker_compose(self.cwd, 'up', '-d')
logger.info('started')
return res
def stop(self):
logger.info('stopping...')
res = _docker_compose(self.cwd, 'stop')
logger.info('stopped')
return res
def update(self):
logger.info('updating containers...')
res = _docker_compose(self.cwd, 'up', '-d', '--build')
logger.info('updated')
return res
def exec(self, container, command):
res = _docker_compose(self.cwd, 'exec', container, command)
return res