-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_mysql.py
42 lines (33 loc) · 1.27 KB
/
run_mysql.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}/mysql /opt/docker/mysql'.format(docker_registry_url)
os.system(build_cmd)
push_cmd = 'docker push {0}/mysql'.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 mysql')
os.system('docker rm mysql')
os.system('docker run --name mysql -it -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root {0}/mysql'.format(docker_registry_url))
if __name__ == '__main__':
run()