Browse Source

新增docker-compose的支持,文档说明取消gopm,改用Go Modules主流的代理模式

SliverHorn 4 years ago
parent
commit
7267761c69
7 changed files with 105 additions and 13 deletions
  1. 8 4
      README-zh_CN.md
  2. 14 5
      README.md
  3. 31 0
      docker-compose.yaml
  4. 47 0
      dockerfile_server
  5. 3 3
      server/config.yaml
  6. 1 0
      server/core/server.go
  7. 1 1
      web/.env.production

+ 8 - 4
README-zh_CN.md

@@ -115,14 +115,18 @@ go get -u github.com/swaggo/swag/cmd/swag
 ````
 
 ##### (2)无法翻墙
-由于国内没法安装 go.org/x 包下面的东西,需要先安装`gopm`
+
+由于国内没法安装 go.org/x 包下面的东西,推荐使用 [goproxy.io](https://goproxy.io/zh/)
 
 ```bash
-# 下载gopm包
-go get -v -u github.com/gpmgo/gopm
+如果您使用的 Go 版本是 1.13 及以上(推荐)
+# 启用 Go Modules 功能
+go env -w GO111MODULE=on 
+# 配置 GOPROXY 环境变量
+go env -w GOPROXY=https://goproxy.io,direct
 
 # 执行
-gopm get -g -v github.com/swaggo/swag/cmd/swag
+go get -g -v github.com/swaggo/swag/cmd/swag
 
 # 到GOPATH的/src/github.com/swaggo/swag/cmd/swag路径下执行
 go install

+ 14 - 5
README.md

@@ -116,14 +116,23 @@ go build
 go get -u github.com/swaggo/swag/cmd/swag
 ````
 
-##### (2) In mainland China 
-In mainland China, access to go.org/x is prohibited,we recommend `gopm`
+##### (2) In mainland China
+ 
+In mainland China, access to go.org/x is prohibited,we recommend [goproxy.io](https://goproxy.io/zh/)
+
 ````bash
-# install gopm
-go get -v -u github.com/gpmgo/gopm
+
+If you are using Go version 1.13 and above (recommended)
+# Enable Go Modules function
+go env -w GO111MODULE=on 
+# Configure GOPROXY environment variables
+go env -w GOPROXY=https://goproxy.io,direct
+If you are using Go version 1.12 and below
+go env -w GO111MODULE=on
+go env -w GOPROXY=https://goproxy.io
 
 # get swag
-gopm get -g -v github.com/swaggo/swag/cmd/swag
+go get -g -v github.com/swaggo/swag/cmd/swag
 
 # cd GOPATH/src/github.com/swaggo/swag/cmd/swag
 go install

+ 31 - 0
docker-compose.yaml

@@ -0,0 +1,31 @@
+version: "3.8"
+
+services:
+  server:
+    build:
+      context: ./
+      dockerfile: ./dockerfile_server
+    container_name: gva-server # 容器名
+    restart: always
+    ports:
+      - '8888:8888'
+    depends_on:
+      - mysql
+      - redis
+
+  mysql:
+    image: registry.cn-shanghai.aliyuncs.com/gva/gva-mysql:1.1
+    container_name: gva-mysql
+    command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci #设置utf8字符集
+    restart: always
+    ports:
+      - "3306:3306"  # host物理直接映射端口为6606
+    environment:
+      MYSQL_ROOT_PASSWORD: "Aa@6447985" # root管理员用户密码
+
+  redis:
+    image: redis:6.0.6
+    container_name: gva-redis # 容器名
+    restart: always
+    ports:
+      - '6379:6379'

+ 47 - 0
dockerfile_server

@@ -0,0 +1,47 @@
+FROM node:12.16.1 as gva-web
+
+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 golang:alpine as gva-server
+
+ENV GO111MODULE=on
+ENV GOPROXY=https://goproxy.io,direct
+WORKDIR /go/src/gin-vue-admin
+COPY server/ ./
+RUN go env && go list && go build -o gva-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
+
+
+EXPOSE 8888
+
+ENTRYPOINT ./gva-server
+
+# 根据Dockerfile生成Docker镜像
+
+# docker build -t gva-server:1.0 .
+
+#- 根据Docker镜像启动Docker容器
+#    - 后台运行
+#    - ```
+#    docker run -d -p 8888:8888 --name gva-server-v1 gva-server:1.0
+#      ```
+#    - 以可交互模式运行, Ctrl + p + q
+#    - ```
+#    docker run -it -p 8888:8888 --name gva-server-v1 gva-server:1.0
+#      ```

+ 3 - 3
server/config.yaml

@@ -12,7 +12,7 @@ jwt:
 mysql:
     username: root
     password: 'Aa@6447985'
-    path: '127.0.0.1:3306'
+    path: mysql
     db-name: 'qmPlus'
     config: 'charset=utf8&parseTime=True&loc=Local'
     max-idle-conns: 10
@@ -36,13 +36,13 @@ qiniu:
 
 # redis configuration
 redis:
-    addr: '127.0.0.1:6379'
+    addr: redis:6379
     password: ''
     db: 0
 
 # system configuration
 system:
-    use-multipoint: false
+    use-multipoint: true
     env: 'public'  # Change to "develop" to skip authentication for development mode
     addr: 8888
     db-type: "mysql"  # support mysql/sqlite

+ 1 - 0
server/core/server.go

@@ -18,6 +18,7 @@ func RunWindowsServer() {
 	}
 	Router := initialize.Routers()
 	Router.Static("/form-generator", "./resource/page")
+	Router.Static("/admin", "./resource/dist")
 
 	//InstallPlugs(Router)
 	// end 插件描述

+ 1 - 1
web/.env.production

@@ -1,2 +1,2 @@
 ENV = 'production'
-VUE_APP_BASE_API = '/v1'
+VUE_APP_BASE_API = ''