-
-
Notifications
You must be signed in to change notification settings - Fork 265
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use consul to do service discover and get configuration
feat: dockerfile feat: consul doc
- Loading branch information
Showing
23 changed files
with
634 additions
and
283 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
FROM golang:1.19.1-alpine3.16 as builder | ||
|
||
WORKDIR /home | ||
COPY . . | ||
|
||
RUN go env -w GO111MODULE=on \ | ||
&& go env -w GOPROXY=https://goproxy.cn,direct \ | ||
&& go env -w CGO_ENABLED=0 \ | ||
&& go env \ | ||
&& go mod tidy \ | ||
&& cd api \ | ||
&& go build -o /home/api/core_api core.go | ||
|
||
FROM alpine:latest | ||
|
||
LABEL MAINTAINER="RyanSU@yuansu.china.work@gmail.com" | ||
|
||
WORKDIR /home | ||
|
||
COPY --from=builder /home/api/core_api ./ | ||
COPY --from=builder /home/api/etc/core.yaml ./ | ||
|
||
EXPOSE 9100 | ||
ENTRYPOINT ./core_api -f core.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
FROM golang:1.19.1-alpine3.16 as builder | ||
|
||
WORKDIR /home | ||
COPY . . | ||
|
||
RUN go env -w GO111MODULE=on \ | ||
&& go env -w GOPROXY=https://goproxy.cn,direct \ | ||
&& go env -w CGO_ENABLED=0 \ | ||
&& go env \ | ||
&& go mod tidy \ | ||
&& cd rpc \ | ||
&& go build -o /home/rpc/core_rpc core.go | ||
|
||
FROM alpine:latest | ||
|
||
LABEL MAINTAINER="RyanSU@yuansu.china.work@gmail.com" | ||
|
||
WORKDIR /home | ||
|
||
COPY --from=builder /home/rpc/core_rpc ./ | ||
COPY --from=builder /home/rpc/etc/core.yaml ./ | ||
|
||
EXPOSE 9101 | ||
ENTRYPOINT ./core_rpc -f core.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,10 @@ | ||
Name: core.api | ||
Host: 0.0.0.0 | ||
Port: 8500 | ||
Auth: | ||
AccessSecret: | ||
AccessExpire: # Seconds | ||
LogConf: | ||
ServiceName: coreApiLogger | ||
Mode: file | ||
Path: /data/logs/api | ||
Level: info | ||
Compress: false | ||
KeepDays: 7 | ||
StackCooldownMillis: 100 | ||
RedisConf: | ||
Host: 127.0.0.1:6379 | ||
Type: node | ||
CoreRpc: | ||
Etcd: | ||
Hosts: | ||
- 127.0.0.1:2379 | ||
Key: core.rpc | ||
Captcha: | ||
KeyLong: 5 | ||
ImgWidth: 240 | ||
ImgHeight: 80 | ||
DatabaseConf: | ||
Type: mysql | ||
Path: 127.0.0.1 | ||
Port: 3306 | ||
Config: charset=utf8mb4&parseTime=True&loc=Local | ||
DBName: simple_admin | ||
Username: | ||
Password: | ||
MaxIdleConn: 10 | ||
MaxOpenConn: 100 | ||
LogMode: error | ||
LogZap: false | ||
Consul: | ||
Host: 127.0.0.1:8500 # consul endpoint | ||
ListenOn: 127.0.0.1:9100 | ||
#Token: 'f0512db6-76d6-f25e-f344-a98cc3484d42' # consul ACL token (optional) | ||
Key: core.api | ||
Meta: | ||
Protocol: grpc | ||
Tag: | ||
- core | ||
- api |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,33 @@ | ||
package config | ||
|
||
import ( | ||
"github.com/zeromicro/go-zero/core/logx" | ||
"github.com/suyuan32/simple-admin-tools/plugins/registry/consul" | ||
"github.com/zeromicro/go-zero/core/stores/gormsql" | ||
"github.com/zeromicro/go-zero/core/stores/redis" | ||
"github.com/zeromicro/go-zero/rest" | ||
"github.com/zeromicro/go-zero/zrpc" | ||
) | ||
|
||
type Config struct { | ||
rest.RestConf | ||
Auth struct { | ||
AccessSecret string | ||
AccessExpire int64 | ||
} | ||
LogConf logx.LogConf `json:"LogConf" yaml:"LogConf"` | ||
RedisConf redis.RedisConf `json:"RedisConf" yaml:"RedisConf"` | ||
CoreRpc zrpc.RpcClientConf `json:"CoreRpc" yaml:"CoreRpc"` | ||
Captcha Captcha `json:"Captcha" yaml:"Captcha"` | ||
DB gormsql.GORMConf `json:"DatabaseConf" yaml:"DatabaseConf"` | ||
rest.RestConf `yaml:",inline"` | ||
Auth Auth `json:"auth" yaml:"Auth"` | ||
RedisConf redis.RedisConf `json:"redisConf" yaml:"RedisConf"` | ||
CoreRpc zrpc.RpcClientConf `json:"coreRpc" yaml:"CoreRpc"` | ||
Captcha Captcha `json:"captcha" yaml:"Captcha"` | ||
DB gormsql.GORMConf `json:"databaseConf" yaml:"DatabaseConf"` | ||
} | ||
|
||
type Captcha struct { | ||
KeyLong int `json:"KeyLong" yaml:"KeyLong"` // captcha length | ||
ImgWidth int `json:"ImgWidth" yaml:"ImgWidth"` // captcha width | ||
ImgHeight int `json:"ImgHeight" yaml:"ImgHeight"` // captcha height | ||
KeyLong int `json:"keyLong" yaml:"KeyLong"` // captcha length | ||
ImgWidth int `json:"imgWidth" yaml:"ImgWidth"` // captcha width | ||
ImgHeight int `json:"imgHeight" yaml:"ImgHeight"` // captcha height | ||
} | ||
|
||
type Auth struct { | ||
AccessSecret string `json:"accessSecret" yaml:"AccessSecret"` | ||
AccessExpire int64 `json:"accessExpire" yaml:"AccessExpire"` | ||
} | ||
|
||
type ConsulConfig struct { | ||
Consul consul.Conf | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
version: "3" | ||
|
||
networks: | ||
network: | ||
ipam: | ||
driver: default | ||
config: | ||
- subnet: '177.7.0.0/16' | ||
|
||
# 设置mysql,redis持久化保存 | ||
volumes: | ||
mysql: | ||
redis: | ||
|
||
services: | ||
api: | ||
build: | ||
context: ../../api | ||
dockerfile: ../../Dockerfile | ||
container_name: gva-web | ||
restart: always | ||
ports: | ||
- '8080:8080' | ||
depends_on: | ||
- server | ||
command: [ 'nginx-debug', '-g', 'daemon off;' ] | ||
networks: | ||
network: | ||
ipv4_address: 177.7.0.11 | ||
|
||
server: | ||
build: | ||
context: ../../server | ||
dockerfile: ./Dockerfile | ||
container_name: gva-server | ||
restart: always | ||
ports: | ||
- '8888:8888' | ||
depends_on: | ||
- mysql | ||
- redis | ||
links: | ||
- mysql | ||
- redis | ||
networks: | ||
network: | ||
ipv4_address: 177.7.0.12 | ||
|
||
mysql: | ||
image: mysql:8.0.21 # 如果您是 arm64 架构:如 MacOS 的 M1,请修改镜像为 image: mysql/mysql-server:8.0.21 | ||
container_name: gva-mysql | ||
command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci #设置utf8字符集 | ||
restart: always | ||
ports: | ||
- "13306:3306" # host物理直接映射端口为13306 | ||
environment: | ||
MYSQL_DATABASE: 'qmPlus' # 初始化启动时要创建的数据库的名称 | ||
MYSQL_ROOT_PASSWORD: 'Aa@6447985' # root管理员用户密码 | ||
volumes: | ||
- mysql:/var/lib/mysql | ||
networks: | ||
network: | ||
ipv4_address: 177.7.0.13 | ||
|
||
redis: | ||
image: redis:6.0.6 | ||
container_name: gva-redis # 容器名 | ||
restart: always | ||
ports: | ||
- '16379:6379' | ||
volumes: | ||
- redis:/data | ||
networks: | ||
network: | ||
ipv4_address: 177.7.0.14 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.