Преглед на файлове

优化docker-compose的前端项目不依赖于Gin,使用nginx

SliverHorn преди 4 години
родител
ревизия
59a138f032
променени са 8 файла, в които са добавени 157 реда и са изтрити 91 реда
  1. 26 0
      .docker-compose/nginx/conf.d/my.conf
  2. 9 43
      .docker-compose/shell/server-handle.sh
  3. 0 10
      .docker-compose/shell/web-handle.sh
  4. 76 4
      README.md
  5. 17 3
      docker-compose.yaml
  6. 0 0
      docker/docker-start.sh
  7. 9 31
      dockerfile_server
  8. 20 0
      dockerfile_web

+ 26 - 0
.docker-compose/nginx/conf.d/my.conf

@@ -0,0 +1,26 @@
+server {
+    listen       8000;
+    server_name localhost;
+
+    #charset koi8-r;
+    #access_log  logs/host.access.log  main;
+
+    location / {
+        root /usr/share/nginx/html;
+        add_header Cache-Control 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
+        try_files $uri $uri/ /index.html;
+    }
+
+    location /api {
+        proxy_set_header Host $http_host;
+        proxy_set_header  X-Real-IP $remote_addr;
+        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+        proxy_set_header X-Forwarded-Proto $scheme;
+        rewrite ^/api/(.*)$ /$1 break;  #重写
+        proxy_pass http://172.25.0.4:8888; # 设置代理服务器的协议和地址
+     }
+
+    location /api/swagger/index.html {
+        proxy_pass http://127.0.0.1:8888/swagger/index.html;
+     }
+ }

+ 9 - 43
.docker-compose/shell/server-handle.sh

@@ -1,48 +1,5 @@
 #! /bin/bash
 
-rm -f ./core/server.go
-# 生成server.go文件, 添加Router.Static("/admin", "./resource/dist")这个代码
-touch ./core/server.go
-filename="./core/server.go"
-cat>"${filename}"<<EOF
-package core
-
-import (
-	"fmt"
-	"gin-vue-admin/global"
-	"gin-vue-admin/initialize"
-	"go.uber.org/zap"
-	"time"
-)
-
-type server interface {
-	ListenAndServe() error
-}
-
-func RunWindowsServer() {
-	if global.GVA_CONFIG.System.UseMultipoint {
-		// 初始化redis服务
-		initialize.Redis()
-	}
-	Router := initialize.Routers()
-	Router.Static("/form-generator", "./resource/page")
-	Router.Static("/admin", "./resource/dist")
-
-	//InstallPlugs(Router)
-	// end 插件描述
-
-	address := fmt.Sprintf(":%d", global.GVA_CONFIG.System.Addr)
-	s := initServer(address, Router)
-	// 保证文本顺序输出
-	// In order to ensure that the text order output can be deleted
-	time.Sleep(10 * time.Microsecond)
-	global.GVA_LOG.Debug("server run success on ", zap.String("address", address))
-
-	fmt.Printf("欢迎使用 Gin-Vue-Admin默认自动化文档地址:http://127.0.0.1%s/swagger/index.html\n 默认前端文件运行地址:http://127.0.0.1:8888/admin\n", address)
-	global.GVA_LOG.Error(s.ListenAndServe().Error())
-}
-EOF
-
 rm -f ./config.yaml
 # 生成config.yaml文件, 用于docker-compose的使用
 touch ./config.yaml
@@ -123,5 +80,14 @@ zap:
   encode_level: 'LowercaseColorLevelEncoder'
   stacktrace_key: 'stacktrace'
   log_in_console: true
+
+email:
+  email_from: '[email protected]'
+  email_nick_name: 'test'
+  email_secret: 'xxx'
+  email_to: '[email protected]'
+  email_host: 'smtp.163.com'
+  email_port: 465
+  email_isSSL: true
 EOF
 

+ 0 - 10
.docker-compose/shell/web-handle.sh

@@ -1,10 +0,0 @@
-#! /bin/bash
-
-rm -f .env.production
-touch .env.production
-filename="./.env.production"
-cat>"${filename}"<<EOF
-ENV = 'production'
-VUE_APP_BASE_API = ''
-EOF
-

+ 76 - 4
README.md

@@ -109,11 +109,83 @@ Gin-vue-admin 的成长离不开大家的支持,如果你愿意为 gin-vue-adm
       docker-compose up -d
       ```
 
-    - web项目预览 [http://127.0.0.1:8888/admin](http://127.0.0.1:8888/admin)
+    - web项目预览 [http://127.0.0.1:8000](http://127.0.0.1:8000)
 
     - swagger文档 [http://127.0.0.1:8888/swagger/index.html](http://127.0.0.1:8888/swagger/index.html)
 
-
+- 打开http://127.0.0.1:8000,验证码无法显示的话
+
+	- ```shell
+		# 终端输入以下命令查找
+		docker network inspect gin-vue-admin_default
+		
+		[
+		    {
+		        "Name": "gin-vue-admin_default",
+		        "Id": "dd65598bd3fcce9916a88161f26268f4e08a6d5bd1c619d07e69abc93c69bba3",
+		        "Created": "2020-09-10T10:36:37.868984015Z",
+		        "Scope": "local",
+		        "Driver": "bridge",
+		        "EnableIPv6": false,
+		        "IPAM": {
+		            "Driver": "default",
+		            "Options": null,
+		            "Config": [
+		                {
+		                    "Subnet": "172.29.0.0/16",
+		                    "Gateway": "172.29.0.1"
+		                }
+		            ]
+		        },
+		        "Internal": false,
+		        "Attachable": true,
+		        "Ingress": false,
+		        "ConfigFrom": {
+		            "Network": ""
+		        },
+		        "ConfigOnly": false,
+		        "Containers": {
+		            "1e246725c7ab689608c9f451c57a892e070fd63ec971d1749ede8dfbdaf704e1": {
+		                "Name": "gva-redis",
+		                "EndpointID": "d457e4babd5676e289bdf4f4c5ef0ce30c2acd87d437bfd7ea8809467a9304ef",
+		                "MacAddress": "02:42:ac:1d:00:02",
+		                "IPv4Address": "172.29.0.2/16",
+		                "IPv6Address": ""
+		            },
+		            "7228d1c37654173e78a5ae82047b3a3b771feeea855dcc1e88e8e29e262bf789": {
+		                "Name": "gva-web",
+		                "EndpointID": "ffc9c29b9aa1e4c7a56b9e8060fff455295813298df585df51b802548c477969",
+		                "MacAddress": "02:42:ac:1d:00:05",
+		                "IPv4Address": "172.29.0.5/16",
+		                "IPv6Address": ""
+		            },
+		            "99b6063801049d659a329cada5ad0d418c02a9956794b9bcbc07327fff3a1e58": {
+		                "Name": "gva-server",
+		                "EndpointID": "9a04629997d8b9aa6d75cc396d5dbb54bc5d239017a1010bacb53f73e2d46199",
+		                "MacAddress": "02:42:ac:1d:00:04",
+		                "IPv4Address": "172.29.0.4/16",
+		                "IPv6Address": ""
+		            },
+		            "af60bee9ddca855beaf6bd6c6612516970f1336215af622d560f982276d9e4c6": {
+		                "Name": "gva-mysql",
+		                "EndpointID": "998a67b2b2ca9a12c916e97bf30f6b5879ee610c52d5ab329253192acd686cd8",
+		                "MacAddress": "02:42:ac:1d:00:03",
+		                "IPv4Address": "172.29.0.3/16",
+		                "IPv6Address": ""
+		            }
+		        },
+		        "Options": {},
+		        "Labels": {
+		            "com.docker.compose.network": "default",
+		            "com.docker.compose.project": "gin-vue-admin",
+		            "com.docker.compose.version": "1.26.2"
+		        }
+		    }
+		]
+		# Name为"gva-server"的IPv4Address,把172.29.0.3放到.docker-compose/nginx/conf.d/my.conf的第20行
+		```
+
+	- 
 
 ### 2.1 web端
 
@@ -270,7 +342,7 @@ swag init
 
 (1)环境搭建
 > Bilibili:https://www.bilibili.com/video/BV1Fg4y187Bw/ (v1.0版本视频,v2.0操作相同目录不同)
-    
+
 (2)模板使用
 > Bilibili:https://www.bilibili.com/video/BV16K4y1r7BD/ (v1.0版本视频,v2.0操作相同目录不同)
 
@@ -286,7 +358,7 @@ swag init
 
 ### QQ交流群:622360840
 | QQ 群(满) |
-|  :---:  |   
+|  :---:  |
 | <img src="http://qmplusimg.henrongyi.top/qq.jpg" width="180"/> |
 
 ### 微信交流群

+ 17 - 3
docker-compose.yaml

@@ -1,11 +1,25 @@
 version: "3.8"
 
 services:
+  web:
+    build:
+      context: ./
+      dockerfile: ./Dockerfile
+    container_name: gva-web
+    restart: always
+    ports:
+      - '8000:8000'
+    links:
+      - server
+    depends_on:
+      - server
+    command: ['nginx-debug', '-g', 'daemon off;']
+
   server:
     build:
       context: ./
-      dockerfile: ./dockerfile_server
-    container_name: gva-server # 容器名
+      dockerfile: ./DockerfileServer
+    container_name: gva-server
     restart: always
     ports:
       - '8888:8888'
@@ -19,7 +33,7 @@ services:
     command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci #设置utf8字符集
     restart: always
     ports:
-      - "13306:3306"  # host物理直接映射端口为6606
+      - "13306:3306"  # host物理直接映射端口为13306
     environment:
       MYSQL_DATABASE: 'qmPlus' # 初始化启动时要创建的数据库的名称
       MYSQL_ROOT_PASSWORD: 'Aa@6447985' # root管理员用户密码

+ 0 - 0
docker/docker-start.sh


+ 9 - 31
dockerfile_server

@@ -1,20 +1,4 @@
-FROM node:12.16.1 as gva-web
-
-WORKDIR /gva_web/
-COPY web/ .
-
-RUN cat .env.production
-COPY .docker-compose/shell/web-handle.sh .
-RUN ls -al
-RUN sh ./web-handle.sh
-RUN cat .env.production
-RUN rm -f web-handle.sh
-
-RUN npm install -g cnpm --registry=https://registry.npm.taobao.org
-RUN cnpm install || npm install
-RUN npm run build
-
-FROM golang:alpine as gva-server
+FROM golang:alpine
 
 ENV GO111MODULE=on
 ENV GOPROXY=https://goproxy.io,direct
@@ -30,25 +14,19 @@ RUN rm -f server-handle.sh
 RUN cat ./core/server.go
 RUN cat ./config.yaml
 
-RUN go env && go list && go build -o gva-server .
-
+RUN go env && go build -o server .
 
-FROM nginx:alpine
-LABEL MAINTAINER="SliverHorn"
 
-WORKDIR gva/
-
-# copy web
-COPY --from=gva-web /gva_web/dist ./resource/dist
-# copy server
-COPY --from=gva-server /go/src/gin-vue-admin/gva-server ./
-COPY --from=gva-server /go/src/gin-vue-admin/config.yaml ./
-COPY --from=gva-server /go/src/gin-vue-admin/resource ./resource
+FROM alpine:latest
+LABEL MAINTAINER="SliverHorn@[email protected]"
 
+WORKDIR /go/src/gin-vue-admin
 
-EXPOSE 8888
+COPY --from=0 /go/src/gin-vue-admin/server ./
+COPY --from=0 /go/src/gin-vue-admin/config.yaml ./
+COPY --from=0 /go/src/gin-vue-admin/resource ./resource
 
-ENTRYPOINT ./gva-server
+ENTRYPOINT ./server
 
 # 根据Dockerfile生成Docker镜像
 

+ 20 - 0
dockerfile_web

@@ -0,0 +1,20 @@
+FROM node:12.16.1
+
+WORKDIR /gva_web/
+COPY web/ .
+
+RUN npm install -g cnpm --registry=https://registry.npm.taobao.org
+RUN cnpm install || npm install
+RUN npm run build
+
+FROM nginx:alpine
+LABEL MAINTAINER="SliverHorn@[email protected]"
+
+COPY .docker-compose/nginx/conf.d/my.conf /etc/nginx/conf.d/my.conf
+COPY --from=0 /gva_web/dist /usr/share/nginx/html
+RUN cat /etc/nginx/nginx.conf
+RUN cat /etc/nginx/conf.d/my.conf
+RUN ls -al /usr/share/nginx/html
+CMD ls -al /usr/share/nginx/html
+
+CMD ['nginx-debug', '-g', 'daemon off;']