Ver Fonte

add Dockerfile

张玉坡 há 7 anos atrás
pai
commit
1cdc5a7503

+ 11 - 8
README.md

@@ -40,18 +40,20 @@ $ docker run -d -e REGISTRY_SERVER="hub.docker.com:5000" -p 80:80 hub.qbangmang.
 
 
 # 可选参数:
-$ -e MYSQL_DATABASE="spug"        	//指定数据库名称
-  -e MYSQL_USER="spuguser"         	//指定数据库用户名
-  -e MYSQL_PASSWORD="spugpwd"    	//指定数据库密码
-  -e REGISTRY_USER="hubuser"    	//指定私有镜像仓库用户名
-  -e REGISTRY_PASSWORD="hubpwd" 	//指定私有镜像仓库密码
+$ -e MYSQL_DATABASE="spug"        	       //指定数据库名称
+  -e MYSQL_USER="spuguser"         	       //指定数据库用户名
+  -e MYSQL_PASSWORD="spugpwd"    	         //指定数据库密码
+  -e REGISTRY_SERVER="hub.docker.com:5000" //指定私有镜像仓库
+  -e REGISTRY_USER="hubuser"    	         //指定私有镜像仓库用户名
+  -e REGISTRY_PASSWORD="hubpwd" 	         //指定私有镜像仓库密码
 ```
 
-更多Dockerfile [Dockerfile](https://github.com/openspug/)
+更多Dockerfile [Dockerfile](https://github.com/openspug/spug/docs/Dockerfile)
 
 
 ### 详细安装步骤
 ----------------------------
+
     [文档](https://github.com/openspug/spug/wiki/)
 
 
@@ -84,14 +86,15 @@ $ -e MYSQL_DATABASE="spug"        	//指定数据库名称
 ### Docs 开发者文档
 ----------------------------
 
+ * [Project structure 项目结构](https://github.com/openspug/spug/docs/project_structure.md)
 
 ### Contributor 贡献者
 ----------------------------
 #### 1.0.1
 - zyupo <张玉坡> 项目发起者
 - Yooke <雷二猛> Spug架构师、熟悉多种开发语言。
-- junun <刘军>
-- yuyc  <于颜川>
+- junun <刘军>   部分功能开发
+- yuyc  <于颜川> 部分功能开发
 
 
 ### 开发者群

+ 18 - 0
docs/Dockerfile/Dockerfile

@@ -0,0 +1,18 @@
+FROM alpine:3.6
+
+RUN echo -e "http://mirrors.aliyun.com/alpine/v3.6/main\nhttp://mirrors.aliyun.com/alpine/v3.6/community" > /etc/apk/repositories
+RUN apk update && apk add --no-cache ca-certificates python3 nginx mariadb nodejs-npm git 
+RUN apk add --no-cache --virtual .build-deps python3-dev gcc musl-dev libffi-dev openssl-dev make \
+    && pip3 install --no-cache-dir -r /spug/spug_api/requirements.txt \
+	&& pip3 install --no-cache-dir gunicorn \	
+    && apk del .build-deps 
+RUN cd /spug/spug_web/ && npm i -d --registry=https://registry.npm.taobao.org \
+    && npm run build \
+	&& mv /var/lib/nginx/html /var/lib/nginx/html.bak && mv /spug/spug_web/dist /var/lib/nginx/html \
+    && rm -f /spug/spug_web
+	
+ADD default.conf /etc/nginx/conf.d/default.conf
+ADD entrypoint.sh /entrypoint.sh
+ADD scripts /scripts
+
+ENTRYPOINT ["sh", "/entrypoint.sh"]

+ 21 - 0
docs/Dockerfile/default.conf

@@ -0,0 +1,21 @@
+server {
+	listen 80 default_server;
+	listen [::]:80 default_server;
+
+	access_log off;
+
+	location /api/ {
+		rewrite ^/api(.*)$ $1 break;
+		proxy_pass http://127.0.0.1:3000;
+	}
+
+	location /apis/ {
+		proxy_pass http://127.0.0.1:3000;
+	}
+
+	location / {
+		root /var/lib/nginx/html;
+	}
+
+	error_page 404 =200 /index.html;
+}

+ 40 - 0
docs/Dockerfile/entrypoint.sh

@@ -0,0 +1,40 @@
+#!/bin/sh
+#
+set -e
+
+REQUIRE_INIT_OPS=false
+
+# env check
+if [ -z $REGISTRY_SERVER ]; then
+    echo 'Please set REGISTRY_SERVER by -e REGISTRY_SERVER=<docker registry server>'
+    exit 1
+fi
+
+# init db
+if [ ! -d /var/lib/mysql/mysql ]; then
+    echo 'Initializing db, please wait ...'
+    REQUIRE_INIT_OPS=true
+    /bin/sh /scripts/init_db.sh
+fi
+
+# init nginx
+if [ ! -d /run/nginx ]; then
+    mkdir -p /run/nginx
+    chown -R nginx.nginx /run/nginx
+fi
+
+# init config
+if [ ! -f /init_config.lock ]; then
+    /bin/sh /scripts/init_config.sh
+    touch /init_config.lock
+fi
+
+
+cd /spug/spug_api
+nginx
+nohup /usr/bin/mysqld_safe --datadir=/var/lib/mysql --user=root &
+sleep 2
+if [ $REQUIRE_INIT_OPS == true ]; then
+    /usr/bin/python3 /scripts/init_spug.py
+fi 
+gunicorn --threads=32 main:app

+ 5 - 0
docs/Dockerfile/scripts/init_config.sh

@@ -0,0 +1,5 @@
+set -e 
+
+echo "SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://${MYSQL_USER:-spuguser}:${MYSQL_PASSWORD:-spugpwd}@localhost/${MYSQL_DATABASE:-spug}'" >> /spug/spug_api/config.py
+echo "DOCKER_REGISTRY_SERVER = '${REGISTRY_SERVER}'" >> /spug/spug_api/config.py
+echo "DOCKER_REGISTRY_AUTH = {'username': '${REGISTRY_USER}', 'password': '${REGISTRY_PASSWORD}'}" >> /spug/spug_api/config.py

+ 14 - 0
docs/Dockerfile/scripts/init_db.sh

@@ -0,0 +1,14 @@
+set -e
+
+if [ ! -d /var/lib/mysql/mysql ]; then
+    mysql_install_db &> /dev/null
+    mkdir -p /run/mysqld
+    tfile=`mktemp`
+    echo "USE mysql;" >> $tfile
+    echo "FLUSH PRIVILEGES;" >> $tfile
+    echo "CREATE DATABASE IF NOT EXISTS \`${MYSQL_DATABASE:-spug}\` CHARACTER SET utf8 COLLATE utf8_general_ci;" >> $tfile
+    echo "GRANT ALL ON \`${MYSQL_DATABASE:-spug}\`.* to '${MYSQL_USER:-spuguser}'@'localhost' IDENTIFIED BY '${MYSQL_PASSWORD:-spugpwd}';" >> $tfile
+    echo "FLUSH PRIVILEGES;" >> $tfile
+    exec /usr/bin/mysqld --user=root --bootstrap < $tfile &> /dev/null
+    rm -f $tfile
+fi 

+ 36 - 0
docs/Dockerfile/scripts/init_spug.py

@@ -0,0 +1,36 @@
+import sys
+import os
+sys.path.append('/ops_api')
+import random
+import string
+from public import db
+from config import BASE_DIR
+from apps.account.models import User
+import apps.configuration.models
+import apps.deploy.models
+import apps.assets.models
+import apps.schedule.models
+import apps.setting.models
+
+
+# init database
+db.drop_all()
+db.create_all()
+with open(os.path.join(BASE_DIR, 'libs', 'sql', 'permissions.sql'), 'r') as f:
+    line = f.readline()
+    while line:
+        if line.startswith('INSERT INTO'):
+            db.engine.execute(line.strip())
+        line = f.readline()
+
+# create default admin
+username = 'admin'
+password = ''.join(random.sample(string.ascii_letters + string.digits, 8))
+User(username=username, password=password, nickname='Administrator', is_supper=True).save()
+
+print('*' * 80)
+print('Database name: ' + (os.getenv('MYSQL_DATABASE') or 'spug'))
+print('Database username: ' + (os.getenv('MYSQL_USER') or 'spuguser'))
+print('Database password: ' + (os.getenv('MYSQL_PASSWORD') or 'spugpwd'))
+print('Login web site account: %s  %s' % (username, password))
+print('*' * 80)

+ 150 - 0
docs/project_structure.md

@@ -0,0 +1,150 @@
+## 项目结构
+
+
+```
+├── docs                         	 // 文档相关目录
+├── spug_api                         // 后端接口目录
+│   └── apps                         // 后端子模块目录
+│   │   ├── account                  // 用户管理模块
+│   │   │   └── __init__.py          // 用户模块蓝图路由
+│   │   │   └── models.py			 // 用户模块数据模型
+│   │   │   └── role.py				 // 用户权限操作相关方法
+│   │   │   └── user.py				 // 用户操作相关方法
+│   │   ├── apis                  	 // 公用接口模块
+│   │   │   └── __init__.py          // 定义接口相关蓝图路由
+│   │   │   └── config.py			 // 客户端获取配置文件相关方法
+│   │   │   └── files.py		     // 文件上传相关方法
+│   │   │   └── utils.py			 //
+│   │   ├── assets                   // 资产管理模块
+│   │   │   └── __init__.py          // 资产模块蓝图路由
+│   │   │   └── host.py			     // 主机管理相关方法
+│   │   │   └── host_exec.py	     // 主机批量执行相关方法
+│   │   │   └── models.py	     	 // 资产模块数据模型
+│   │   │   └── utils.py			 //
+│   │   ├── common                   // 公用队列模块
+│   │   │   └── __init__.py          // 公用队列模块蓝图路由
+│   │   │   └── queue.py			 // 公用队列方法
+│   │   ├── configuration            // 配置管理模块
+│   │   │   └── __init__.py          // 配置管理模块蓝图路由
+│   │   │   └── app.py			     // 主机管理相关方法
+│   │   │   └── config.py	     	 // 
+│   │   │   └── environment.py	     // 环境配置相关方法
+│   │   │   └── models.py	     	 // 配置管理数据模型
+│   │   │   └── service.py			 // 配置管理-服务配置相关方法
+│   │   ├── deploy            		 // 应用发布模块
+│   │   │   └── __init__.py          // 应用发布模块蓝图路由
+│   │   │   └── app.py			     // 
+│   │   │   └── config.py	     	 // 
+│   │   │   └── container.py	     // 
+│   │   │   └── exec.py	     		 // 应用发布-执行发布相关方法
+│   │   │   └── field.py	     	 // 应用发布-字段管理相关方法
+│   │   │   └── host.py	     		 // 
+│   │   │   └── image.py	     	 // 应用发布-镜像管理相关方法
+│   │   │   └── menu.py	     		 // 应用发布-菜单管理相关组件
+│   │   │   └── models.py	     	 // 应用发布数据模型
+│   │   │   └── publish.py			 // 应用发布-发布相关方法
+│   │   │   └── utils.py			 // 
+│   │   ├── home            		 // 首页模块
+│   │   │   └── __init__.py          // 首页蓝图路由
+│   │   │   └── homes.py			 // 首页展示数据方法
+│   │   ├── schedule              	 // 任务管理模块
+│   │   │   └── __init__.py          // 任务管理蓝图路由
+│   │   │   └── agent.py			 // 任务管理-执行对象相关方法
+│   │   │   └── history.py	     	 // 任务管理-任务历史
+│   │   │   └── job.py	     		 // 任务管理-任务列表相关
+│   │   │   └── models.py	     	 // 任务管理数据模型
+│   │   │   └── scheduler.py	     // 任务管理方法
+│   │   ├── setting              	 // 
+│   │   │   └── __init__.py          // 
+│   │   │   └── models.py			 // 
+│   │   │   └── utils.py	     	 // 
+│   │   ├── __init__.py              // 
+│   │   │ 
+│   └── libs                         // 系统公用库目录
+│   │   ├── scripts                  // 公用脚本目录
+│   │   │   └── entrypoint.sh        // 容器启动脚本
+│   │   ├── sql                  	 // sql目录
+│   │   │   └── permissions.sql      // 系统权限SQL文件
+│   │   ├── ssh                   	 // ssh管理目录
+│   │   │   └── __init__.py          // 公用ssh相关方法
+│   │   ├── template                 // 系统模板目录
+│   │   │   └── host.xls         	 // 主机管理-主机导入-模板
+│   │   ├── __init__.py              // 
+│   │   ├── decorators.py            // 公用检查权限文件
+│   │   ├── middleware.py            // 系统公共设置文件
+│   │   ├── model.py                 // 系统公用类
+│   │   ├── tool.py                  // 系统公用工具文件
+│   │   ├── utils.py                 // 
+│   └── storage                      // 系统公用目录
+│   │   ├── exec_tmp                 // 执行目录
+│   │   ├── images                   // 镜像目录
+│   │   ├── publish_tmp              // 发布目录
+│   └── config.py.example            // 后端配置文件模板
+│   └── main.py            			 // 后端入口文件,加载所有模块
+│   └── manage.py            		 // 系统管理文件
+│   └── public.py            		 // 系统公用
+│   └── requirements.txt             // 后端依赖包文件
+│  
+│
+├── spug_web                         // 前端目录
+│   └── dist                         // 项目编译后的静态资源目录
+│   └── src                          // 前端项目源码目录
+│   │   ├── assets                   // 静态资源目录
+│   │   ├── components               // 前端子模块UI组件目录
+│   │   │   ├── account              // 用户管理目录
+│   │   │   │   └── Permission.vue   // 权限管理组件
+│   │   │   │   └── PublishPermission.vue // 角色权限-发布权限组件
+│   │   │   │   └── Role.vue		 // 角色权限组件
+│   │   │   │   └── routes.js        // 用户管理路由
+│   │   │   │   └── TagTd.vue		 // 权限管理标签
+│   │   │   │   └── User.vue		 // 用户列表组件
+│   │   │   ├── assets               // 主机管理目录
+│   │   │   │   └── Host.vue	 	 // 主机列表组件
+│   │   │   │   └── HostExec.vue	 // 批量执行组件
+│   │   │   │   └── route.js		 // 主机管理路由
+│   │   │   ├── configuration        // 配置管理目录
+│   │   │   │   └── App.vue			 // 应用配置列表组件
+│   │   │   │   └── AppConfig.vue	 // 应用配置-配置组件
+│   │   │   │   └── AppRel.vue	     // 应用配置-关系配置组件
+│   │   │   │   └── ConfigEdie.vue	 // 
+│   │   │   │   └── Environment.vue	 // 环境配置组件
+│   │   │   │   └── route.js		 // 配置管理路由
+│   │   │   │   └── Service.vue	 	 // 服务管理组件
+│   │   │   │   └── ServiceConfig.vue// 服务配置-配置组件
+│   │   │   ├── publish            	 // 应用发布目录
+│   │   │   │   └── App.vue			 // 应用列表组件
+│   │   │   │   └── AppConfig.vue	 // 应用列表-应用设置组件
+│   │   │   │   └── AppMenu.vue	     // 
+│   │   │   │   └── AppSetting.vue	 // 应用列表-容器设置组件
+│   │   │   │   └── ColorInput.vue	 // 发布执行命令行组件
+│   │   │   │   └── Deploy.vue		 // 应用发布-部署组件 
+│   │   │   │   └── Field.vue	  	 // 应用发布-字段管理组件
+│   │   │   │   └── Image.vue		 // 应用发布-镜像管理组件
+│   │   │   │   └── Menu.vue	 	 // 应用发布-菜单管理组件
+│   │   │   │   └── MenuExec.vue	 //
+│   │   │   │   └── route.js		 // 应用发布路由
+│   │   │   ├── schedule             // 任务管理目录
+│   │   │   │   └── Job.vue	     	 // 任务列表组件
+│   │   │   │   └── JobSetting.vue	 // 任务管理-设置触发器组件
+│   │   │   ├── Deny.vue 			 // 全局权限拒绝组件
+│   │   │   ├── Home.vue   			 // 系统Home组件
+│   │   │   ├── Layout.vue 			 // 菜单生成组件
+│   │   │   ├── Login.vue 			 // 系统登录组件
+│   │   ├── config               	 // 配置目录
+│   │   │   ├── env.js               // 项目常规配置
+│   │   │   ├── menu.js              // 菜单及面包屑配置
+│   │   ├── plugins               	 // 项目扩展目录
+│   │   │   ├── globalTools.js       // 全局变量
+│   │   ├── App.vue               	 // 
+│   │   ├── index.html               // 首页文件
+│   │   ├── main.js               	 // 入口文件,加载各种公共组件
+│   │   ├── router.js                // 公共路由
+│   └── .babelrc                     // ES6语法编译配置
+│   └── Makefile                     // 
+│   └── package.json                 // 项目及工具的依赖配置文件
+│   └── postcss.config.js            // 
+│   └── ReadME.md                    // 前端README
+│   └── webpack.config.js            // 
+
+
+```

+ 35 - 0
spug_api/requirements.txt

@@ -0,0 +1,35 @@
+APScheduler==3.3.1
+asn1crypto==0.22.0
+backports.ssl-match-hostname==3.5.0.1
+bcrypt==3.1.3
+certifi==2017.7.27.1
+cffi==1.10.0
+chardet==3.0.4
+click==6.7
+cryptography==2.0.3
+docker==2.5.1
+docker-pycreds==0.2.1
+Flask==0.12.2
+Flask-Excel==0.0.7
+Flask-SQLAlchemy==2.2
+idna==2.6
+itsdangerous==0.24
+Jinja2==2.9.6
+lml==0.0.1
+MarkupSafe==1.0
+paramiko==2.2.1
+pyasn1==0.3.4
+pycparser==2.18
+pyexcel==0.5.3
+pyexcel-io==0.5.1
+pyexcel-webio==0.1.2
+PyMySQL==0.7.11
+PyNaCl==1.1.2
+pytz==2017.2
+requests==2.18.4
+six==1.10.0
+SQLAlchemy==1.1.14
+texttable==0.9.1
+tzlocal==1.4
+urllib3==1.22
+Werkzeug==0.12.2

+ 0 - 1
spug_web/src/plugins/globalTools.js

@@ -3,7 +3,6 @@
  */
 // import Vue from 'vue'
 import axios from 'axios'
-import io from 'socket.io-client'
 import envs from '../config/env';