浏览代码

加入gateway

owen-carter 6 年之前
父节点
当前提交
49390be82e
共有 7 个文件被更改,包括 97 次插入19 次删除
  1. 7 3
      .dockerignore
  2. 9 6
      Dockerfile
  3. 16 8
      docker-compose.yml
  4. 39 0
      gateway/nginx/default.conf
  5. 0 0
      gateway/nginx/ssl/.gitignore
  6. 23 0
      gunicorn.conf
  7. 3 2
      walle/config/settings_prod.py

+ 7 - 3
.dockerignore

@@ -1,16 +1,20 @@
 Dockerfile*
 docker-compose*
 
-.dockerignore
 .git
 .github
 .gitignore
 .vscode
+.dockerignore
+.editorconfig
+.idea/
+.travis.yml
+
+admin.sh
 
 test
 screenshot
 migrations
-requirements
 
 README.md
-LICENSE
+LICENSE

+ 9 - 6
Dockerfile

@@ -1,10 +1,13 @@
-FROM python:2.7.1
+FROM python:2.7
 
-WORKDIR /usr/app
-COPY ./requirements/prod.txt ./requirements.txt
-RUN pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple
+WORKDIR /usr/app/
+
+COPY ./requirements/prod.txt .
+RUN pip install futures
+
+RUN pip install -r prod.txt -i https://mirrors.aliyun.com/pypi/simple
 
 COPY . .
-RUN sh admin.sh migration
+#RUN python waller.py db upgrade
 
-CMD python waller.py
+CMD python waller.py start

+ 16 - 8
docker-compose.yml

@@ -4,25 +4,33 @@ services:
 
   mysql:
     image: mysql
-    container_name: inspector-mysql
     ports:
       - 3306:3306
     environment:
       MYSQL_ROOT_PASSWORD: walle
+
       MYSQL_DATABASE: walle
-      MYSQL_USER: user
-      MYSQL_PASSWORD: password
+      MYSQL_USER: walle
+      MYSQL_PASSWORD: walle
     volumes:
       - ${HOME}/.walle/mysql:/var/lib/mysql
-    network_mode: host
     restart: always
 
   web:
-    build: .
-    depends_on:
+    build: ./
+    links:
       - mysql
     ports:
-      - 0.0.0.0:5000:5000
-    network_mode: host
+      - 0.0.0.0:8000:5000
+    environment:
+      - WALLE_SECRET="guess me out"
     restart: always
 
+  gateway:
+    image: nginx
+    ports:
+      - 0.0.0.0:80:80
+    volumes:
+      - ./fe/:/data/web/:ro
+      - ./gateway/nginx/default.conf:/etc/nginx/conf.d/default.conf:ro
+    restart: always

+ 39 - 0
gateway/nginx/default.conf

@@ -0,0 +1,39 @@
+upstream webservers {
+    server web:5000 weight=1;
+}
+
+server {
+    listen       80;
+
+    location / {
+        root /data/web/; # 前端代码
+        try_files $uri $uri/ /index.html;
+        add_header access-control-allow-origin *;
+    }
+
+    location ^~ /api/ {
+        add_header        access-control-allow-origin *;
+        proxy_pass        http://webservers;
+        proxy_set_header  X-Forwarded-Host $host:$server_port;
+        proxy_set_header  X-Real-IP  $remote_addr;
+        proxy_set_header  Origin        $host:$server_port;
+        proxy_set_header  Referer       $host:$server_port;
+    }
+
+    location ^~ /socket.io/ {
+        add_header        access-control-allow-origin *;
+        proxy_pass        http://webservers;
+        proxy_set_header  X-Forwarded-Host $host:$server_port;
+        proxy_set_header  X-Real-IP  $remote_addr;
+        proxy_set_header  Origin        $host:$server_port;
+        proxy_set_header  Referer       $host:$server_port;
+        proxy_set_header  Host $http_host;
+        proxy_set_header  X-NginX-Proxy true;
+
+        # WebScoket Support
+        proxy_http_version 1.1;
+        proxy_set_header   Upgrade $http_upgrade;
+        proxy_set_header   Connection "upgrade";
+    }
+
+}

+ 0 - 0
gateway/nginx/ssl/.gitignore


+ 23 - 0
gunicorn.conf

@@ -0,0 +1,23 @@
+# -*- coding: utf-8 -*-
+
+# 并行工作进程数
+workers = 4
+
+# 指定每个工作者的线程数
+threads = 2
+
+# 设置守护进程【关闭连接时,程序仍在运行】
+daemon = True
+
+# 设置超时时间120s,默认为30s。按自己的需求进行设置
+timeout = 120
+
+# 监听内网端口5000
+bind = '0.0.0.0:8000'
+
+# 设置日志记录水平
+loglevel = 'warning'
+
+# 设置访问日志和错误信息日志路径
+accesslog = './logs/acess.log'
+errorlog = './logs/error.log'

+ 3 - 2
walle/config/settings_prod.py

@@ -20,7 +20,8 @@ class ProdConfig(Config):
 
     # 服务启动 @TODO
     # 跟hosts, nginx配置一致
-    HOST = 'admin.walle-web.io'
+    # 这里设置成域名模式没有什么大的作用,反倒很麻烦
+    HOST = '0.0.0.0'
     PORT = 5000
 
     ENV = 'prod'
@@ -31,7 +32,7 @@ class ProdConfig(Config):
     CACHE_TYPE = 'simple'
 
     # 数据库设置 @TODO
-    SQLALCHEMY_DATABASE_URI = 'mysql://user:password@localhost/walle'
+    SQLALCHEMY_DATABASE_URI = 'mysql://walle:walle@localhost/walle'
 
     # 设置session的保存时间。
     PERMANENT_SESSION_LIFETIME = timedelta(days=1)