-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_mongo.py
42 lines (33 loc) · 1.27 KB
/
run_mongo.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
#! /usr/bin/python
import os
import sys
import ConfigParser
import pisces.utils.io as io
import pisces_config
def run():
if (len(sys.argv)) > 1 and sys.argv[1] == 'push':
build_and_push_img()
else:
run_mysql_container()
def build_and_push_img():
# os.system('cp /opt/docker/mysql/my.cnf.sample /opt/docker/mysql/my.cnf')
cfg = pisces_config.PiscesConfig.get_instance()
# cp = ConfigParser.SafeConfigParser()
# cp.read('/opt/app.conf')
# docker_registry_url = cp.get('docker-registry', 'url')
docker_registry_url = cfg.get_docker_registry()
build_cmd = 'docker build -t {0}/mongo /opt/docker/mongo'.format(docker_registry_url)
os.system(build_cmd)
push_cmd = 'docker push {0}/mongo'.format(docker_registry_url)
os.system(push_cmd)
def run_mysql_container():
cfg = pisces_config.PiscesConfig.get_instance()
# cp = ConfigParser.SafeConfigParser()
# cp.read('/opt/app.conf')
# docker_registry_url = cp.get('docker-registry', 'url')
docker_registry_url = cfg.get_docker_registry()
os.system('docker stop mongo')
os.system('docker rm mongo')
os.system('docker run --name mongo -it -d -p 27017:27017 -v /opt/data/mongo:/data/db {0}/mongo'.format(docker_registry_url))
if __name__ == '__main__':
run()