From 1cdc5a75038e40c8546e7681f186a3962e477e22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E7=8E=89=E5=9D=A1?= Date: Tue, 27 Feb 2018 17:17:53 +0800 Subject: [PATCH] add Dockerfile --- README.md | 19 ++-- docs/Dockerfile/Dockerfile | 18 +++ docs/Dockerfile/default.conf | 21 ++++ docs/Dockerfile/entrypoint.sh | 40 +++++++ docs/Dockerfile/scripts/init_config.sh | 5 + docs/Dockerfile/scripts/init_db.sh | 14 +++ docs/Dockerfile/scripts/init_spug.py | 36 ++++++ docs/project_structure.md | 150 +++++++++++++++++++++++++ spug_api/requirements.txt | 35 ++++++ spug_web/src/plugins/globalTools.js | 1 - 10 files changed, 330 insertions(+), 9 deletions(-) create mode 100644 docs/Dockerfile/Dockerfile create mode 100644 docs/Dockerfile/default.conf create mode 100644 docs/Dockerfile/entrypoint.sh create mode 100644 docs/Dockerfile/scripts/init_config.sh create mode 100644 docs/Dockerfile/scripts/init_db.sh create mode 100644 docs/Dockerfile/scripts/init_spug.py create mode 100644 docs/project_structure.md create mode 100644 spug_api/requirements.txt diff --git a/README.md b/README.md index a947c13..0eabe90 100644 --- a/README.md +++ b/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 <于颜川> 部分功能开发 ### 开发者群 diff --git a/docs/Dockerfile/Dockerfile b/docs/Dockerfile/Dockerfile new file mode 100644 index 0000000..6b4fc26 --- /dev/null +++ b/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"] \ No newline at end of file diff --git a/docs/Dockerfile/default.conf b/docs/Dockerfile/default.conf new file mode 100644 index 0000000..da5b688 --- /dev/null +++ b/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; +} diff --git a/docs/Dockerfile/entrypoint.sh b/docs/Dockerfile/entrypoint.sh new file mode 100644 index 0000000..6ae1a0b --- /dev/null +++ b/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=' + 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 diff --git a/docs/Dockerfile/scripts/init_config.sh b/docs/Dockerfile/scripts/init_config.sh new file mode 100644 index 0000000..aede3a8 --- /dev/null +++ b/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 diff --git a/docs/Dockerfile/scripts/init_db.sh b/docs/Dockerfile/scripts/init_db.sh new file mode 100644 index 0000000..f612c5e --- /dev/null +++ b/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 diff --git a/docs/Dockerfile/scripts/init_spug.py b/docs/Dockerfile/scripts/init_spug.py new file mode 100644 index 0000000..2aac567 --- /dev/null +++ b/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) diff --git a/docs/project_structure.md b/docs/project_structure.md new file mode 100644 index 0000000..7db2350 --- /dev/null +++ b/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 // + + +``` \ No newline at end of file diff --git a/spug_api/requirements.txt b/spug_api/requirements.txt new file mode 100644 index 0000000..8ff423c --- /dev/null +++ b/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 diff --git a/spug_web/src/plugins/globalTools.js b/spug_web/src/plugins/globalTools.js index eb56668..190b2ad 100644 --- a/spug_web/src/plugins/globalTools.js +++ b/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';