rabin 7 年 前
コミット
b07a5787c0

+ 3 - 0
src/docker/build/base/swarm/Dockerfile

@@ -0,0 +1,3 @@
+FROM library/swarm:latest
+
+MAINTAINER Rabin "https://github.com/shemic"

+ 17 - 7
src/docker/build/office/convert/convert.sh

@@ -1,18 +1,28 @@
 #!/usr/bin/env sh
 set -e
 
-start_nginx()
+start_convert()
 {
-	#exec nginx
-	process_start nginx
+    cd $DEMETER_HOME
+    git reset --hard FETCH_HEAD
+    git pull
+    chmod -R +x $DEMETER_HOME/*.py
+    install.py
+    process_start admin.py
+    process_start front.py
+    process_start cron.py
 }
 
-stop_nginx()
+stop_convert()
 {
-    nginx -s stop
+    process_stop admin.py
+    process_stop front.py
+    process_stop cron.py
 }
 
-monit_nginx()
+monit_convert()
 {
-	process_monit nginx
+	process_monit admin.py
+    process_monit front.py
+    process_monit cron.py
 }

+ 1 - 1
src/docker/build/service/consul/Dockerfile

@@ -6,7 +6,7 @@ MAINTAINER Rabin "https://github.com/shemic"
 ENV CONSUL_VERSION=0.9.2
 
 # install
-RUN apk add --no-cache --update curl unzip && \
+RUN apk add --no-cache --update curl unzip bind-tools && \
 	curl -O https://releases.hashicorp.com/consul/${CONSUL_VERSION}/consul_${CONSUL_VERSION}_linux_amd64.zip && \
 	unzip consul_${CONSUL_VERSION}_linux_amd64.zip && \
 	mv consul /usr/bin/ && \

+ 3 - 1
src/docker/build/service/consul/consul.sh

@@ -5,8 +5,10 @@ start_consul()
 {
 	if [ "$1" == "server" ]; then
 		process_start consul agent -server -bootstrap-expect 1 -data-dir /root/consul/data -config-dir /root/consul/config -client 0.0.0.0
-	else
+	elif [ "$1" == "client" ]; then
 		process_start consul agent -client -config-dir /root/consul/config -join 0.0.0.0
+    else
+        process_start consul agent $@
 	fi
 	#consul members
 }

+ 0 - 1
src/docker/conf/base.conf

@@ -1,6 +1,5 @@
 [base]
 path = {base}
-network = web
 
 [gogs]
 image = gogs

+ 0 - 1
src/docker/conf/buy.conf

@@ -1,6 +1,5 @@
 [base]
 path = {base}
-network = buy
 
 [pgsql]
 image = postgresql

+ 0 - 1
src/docker/conf/chengmao.conf

@@ -1,6 +1,5 @@
 [base]
 path = {base}
-network = cm
 
 [mysql]
 port = 3309:3306

+ 16 - 0
src/docker/conf/cluster.conf

@@ -0,0 +1,16 @@
+[base]
+path = {base}
+default = master
+key = dm_cluster
+
+[master]
+image = consul
+port = 8500,8600
+volumes = {container}conf/service/consul:/root/consul/config
+command = consul -server -bootstrap-expect 3 -data-dir /root/consul/data -config-dir /root/consul/config -client 0.0.0.0 -node={name}
+slave = 2
+slave_command = consul -server -data-dir /root/consul/data -config-dir /root/consul/config -client 0.0.0.0 -node={name} -join={parent}
+
+
+[#manage]
+port = 8088:8088

+ 0 - 1
src/docker/conf/data.conf

@@ -1,6 +1,5 @@
 [base]
 path = {base}
-network = hadoop
 
 [java]
 command = share_java

+ 0 - 18
src/docker/conf/dm.conf

@@ -1,18 +0,0 @@
-[base]
-path = {base}
-network = web
-defalut = manage
-
-[master]
-image = service/consul
-port = 8500:8500
-volumes = {container}conf/service/consul:/root/consul/config
-command = consul server
-
-[slave]
-image = service/consul
-volumes = {container}conf/service/consul:/root/consul/config
-command = consul client
-
-[manage]
-port = 8088:8088

+ 1 - 2
src/docker/conf/elk.conf

@@ -1,6 +1,5 @@
 [base]
-path = {base}
-network = elk
+path = {base} 
 
 [java]
 command = share_java

+ 0 - 1
src/docker/conf/iot.conf

@@ -1,6 +1,5 @@
 [base]
 path = {base}
-network = iot
 
 [emq]
 image = emqtt

+ 0 - 1
src/docker/conf/monit.conf

@@ -1,7 +1,6 @@
 [base]
 ;根目录
 path = {base}
-network = web
 
 [prometheus]
 port = 9090:9090

+ 0 - 1
src/docker/conf/office.conf

@@ -1,6 +1,5 @@
 [base]
 path = {base}
-network = web
 
 [convert]
 port = 8087:8087,8088:8088

+ 0 - 1
src/docker/conf/onepage.conf

@@ -1,6 +1,5 @@
 [base]
 path = {base}
-network = web
 
 [mysql]
 port = 3309:3306

+ 0 - 1
src/docker/conf/py.conf

@@ -1,7 +1,6 @@
 [base]
 ;根目录
 path = {base}
-network = web
 
 [v2]
 image = python

+ 0 - 1
src/docker/conf/server.conf

@@ -1,6 +1,5 @@
 [base]
 path = {base}
-network = web
 
 [memcached]
 environment = MEMCACHED_PORT=11211-11212

+ 0 - 1
src/docker/conf/tool.conf

@@ -1,6 +1,5 @@
 [base]
 path = {base}
-network = hadoop
 
 [zeppelin]
 image = zeppelin_simple

+ 0 - 1
src/docker/conf/vps.conf

@@ -1,6 +1,5 @@
 [base]
 path = {base}
-network = vps
 
 [shadowsocks]
 port = 6443:6443,6500:6500/udp

+ 0 - 1
src/docker/conf/web.conf

@@ -1,6 +1,5 @@
 [base]
 path = {base}
-network = web
 default = mysql,php7,nginx
 
 [mysql]

+ 1 - 0
src/docker/core.conf

@@ -87,6 +87,7 @@ dlib				= learning/dlib
 gogs				= base/gogs
 registry			= base/registry
 redmine				= base/redmine
+swarm               = base/swarm
 
 ;service
 consul				= service/consul

+ 1 - 1
src/shell/container/network

@@ -1,3 +1,3 @@
 #!/usr/bin/env sh
 set -e
-docker network create --driver=bridge $1
+docker network create --driver=overlay $1

+ 4 - 0
src/shell/swarm/init

@@ -0,0 +1,4 @@
+#!/usr/bin/env sh
+set -e
+
+docker swarm init --advertise-addr $1

+ 4 - 0
src/shell/swarm/join

@@ -0,0 +1,4 @@
+#!/usr/bin/env sh
+set -e
+
+docker swarm join --token $1 $2

+ 4 - 0
src/shell/swarm/token

@@ -0,0 +1,4 @@
+#!/usr/bin/env sh
+set -e
+
+docker swarm join-token worker

+ 50 - 4
src/tool/docker.py

@@ -43,6 +43,8 @@ class Docker(object):
 	def config(self):
 		if not self.conf:
 			self.conf = Config.read(self.path)
+			if 'network' not in self.conf['base']:
+				self.conf['base']['network'] = 'dm'
 
 	@classmethod
 	def check(self, name, item):
@@ -56,8 +58,9 @@ class Docker(object):
 			return False
 
 	@classmethod
-	def handle(self, method, config, item, action='run'):
-		self.rely(config, action)
+	def handle(self, method, config, item, action='run', slave=False):
+		if slave == False:
+			self.rely(config, action)
 		if 'num' not in config:
 			config['num'] = 1
 		num = int(config['num'])
@@ -72,6 +75,8 @@ class Docker(object):
 			if action in ('stop', 'restart', 'rm', 'rmb', 'reset', 'run', 'create'):
 				self.slave(method, config, item, action)
 			i = i + 1
+		if slave == False:
+			self.next(config, action)
 
 	@classmethod
 	def name(self, name, i):
@@ -103,6 +108,9 @@ class Docker(object):
 				result = Core.replace('{path}', self.conf['base']['path'], result)
 				result = Core.replace('{container}', self.conf['base']['path'] + 'container/', result)
 				result = Core.replace('{name}', name, result)
+				if 'parent' in self.conf['base']:
+					result = Core.replace('{parent}', self.conf['base']['parent'], result)
+
 				result = self.parse(result)
 				result = Core.replace(',', ' ' + prefix + ' ', result)
 				if item == 'hostname':
@@ -158,6 +166,16 @@ class Docker(object):
 			else:
 				Core.popen('Core ' + action + ' ' + config['rely'], True)
 
+	@classmethod
+	def next(self, config, action):
+		if 'next' in config:
+			if ',' in config['next']:
+				data = config['next'].split(',');
+				for i in data:
+					Core.popen('Core ' + action + ' ' + i, True)
+			else:
+				Core.popen('Core ' + action + ' ' + config['next'], True)
+
 	@classmethod
 	def hook(self, type, config, name):
 		key = 'hook.'+type
@@ -173,7 +191,10 @@ class Docker(object):
 				if k in config:
 					del config[k]
 			config['num'] = num
-			self.handle(method, config, name + '-slave', action)
+			if 'slave_command' in config:
+				config['command'] = config['slave_command']
+			self.conf['base']['parent'] = Args.name + '-' + name
+			self.handle(method, config, name + '-slave', action, True)
 	@classmethod
 	def tar(self, name):
 		path = Core.path + 'data/backup/' + name + '/'
@@ -397,6 +418,22 @@ class Docker_Action(object):
 		else:
 			self.restart(**param)
 
+	@classmethod
+	def init(self, **param):
+		# 启动daemon-master
+		command = 'dm run daemon-master'
+		Core.popen(command, True, bg=False)
+
+		'''
+		ip = Args.name
+		if not ip:
+			ip = Core.ip()
+		token = Cluster.init(ip)
+
+		if token:
+		'''
+		print 'init cluster:yes'
+
 class Container(object):
 	@staticmethod
 	def run(command):
@@ -511,4 +548,13 @@ class Image(object):
 		pull = 'docker pull';
 		command = pull + ' ' + library + key
 		Core.popen(command, True)
-		print 'finished'
+		print 'finished'
+
+class Cluster(object):
+	@staticmethod
+	def init(ip):
+		#result = Core.shell('swarm.init ' + ip)
+		return 1
+	@staticmethod
+	def join(token, ip):
+		Core.shell('swarm.join ' + token + ' ' + ip, bg=True)