Skip to content

Commit

Permalink
chore: optimize docker config
Browse files Browse the repository at this point in the history
  • Loading branch information
quanlong committed Mar 10, 2021
1 parent 9c8336d commit f460e35
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 19 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,4 @@ vendor

# custom
snake
config/config.yaml
config/config.local.yaml
config/config.yaml
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
├── build # 编译目录
├── cmd # 脚手架目录
├── conf # 配置文件统一存放目录
├── db.sql # 在部署新环境时,可以登录 MySQL 客户端,执行 source db.sql 创建数据库和表
├── init.sql # 在部署新环境时,可以登录 MySQL 客户端,执行 source init.sql 创建数据库和表
├── docs # Swagger 文档,执行 swag init 生成的
├── handler # 控制器目录,用来读取输入、调用业务处理、返回结果
├── internal # 业务目录
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions build/docker/mysql/my.cnf
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ general_log = 1
general_log_file = /var/lib/mysql/mysql.log

performance_schema = 0
explicit_defaults_for_timestamp
explicit_defaults_for_timestamp=true

#lower_case_table_names = 1

Expand Down Expand Up @@ -97,4 +97,4 @@ max_allowed_packet = 500M
key_buffer_size = 8M
sort_buffer_size = 8M
read_buffer = 4M
write_buffer = 4M
write_buffer = 4M
2 changes: 1 addition & 1 deletion cmd/snake/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ snake new snake-demo -d ./
├── cmd # 脚手架目录
├── conf # 配置文件统一存放目录
├── config # 专门用来处理配置和配置文件的 Go package
├── db.sql # 在部署新环境时,可以登录 MySQL 客户端,执行 source db.sql 创建数据库和表
├── init.sql # 在部署新环境时,可以登录 MySQL 客户端,执行 source init.sql 创建数据库和表
├── docs # Swagger 文档,执行 swag init 生成的
├── handler # 控制器目录,用来读取输入、调用业务处理、返回结果
├── internal # 业务目录
Expand Down
99 changes: 99 additions & 0 deletions config/config.local.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
app:
Name: snake
Version: 1.0.0
Port: :8080
PprofPort: :5555
Mode: debug # debug, release, test
JwtSecret: JWT_SECRET
JwtTimeout: 86400
CookieName: jwt-token
ReadTimeout: 5
WriteTimeout: 5
SSL: true
CtxDefaultTimeout: 12
CSRF: true
Debug: false

log:
name: snake # 应用名称
writers: file,stdout # 有2个可选项:file,stdout, 可以两者同时选择输出位置,有2个可选项:file,stdout。选择file会将日志记录到logger_file指定的日志文件中,选择stdout会将日志输出到标准输出,当然也可以两者同时选择
logger_level: DEBUG # 日志级别,DEBUG, INFO, WARN, ERROR, FATAL
logger_file: /tmp/log/snake.log # 日志文件
logger_warn_file: /tmp/log/snake.wf.log
logger_error_file: /tmp/log/snake.err.log
log_format_text: false # 日志的输出格式,json或者plaintext,目前设置为false即可,暂时也只支持json格式
log_rolling_policy: daily, # rotate依据,可选的有:daily, hourly。如果选daily(默认)则根据天进行转存,如果是hourly则根据小时进行转存
log_rotate_date: 1 # rotate转存时间,配合rollingPolicy: daily使用
log_rotate_size: 1 # rotate转存大小,配合rollingPolicy: size使用

logger:
Development: true
DisableCaller: false
DisableStacktrace: false
Encoding: json
Level: info

mysql:
Name: snake # 数据库名称
Addr: 127.0.0.1:3306 # 如果是 docker,可以替换为 对应的服务名称,eg: db:3306
UserName: root
Password: 123456
ShowLog: true # 是否打印SQL日志
MaxIdleConn: 10 # 最大闲置的连接数,0意味着使用默认的大小2, 小于0表示不使用连接池
MaxOpenConn: 60 # 最大打开的连接数, 需要小于数据库配置中的max_connections数
ConnMaxLifeTime: 60m # 单个连接最大存活时间,建议设置比数据库超时时长(wait_timeout)稍小一些

redis:
Addr: 127.0.0.1:6379
Password: ""
DB: 0
MinIdleConn: 200
DialTimeout: 60s
ReadTimeout: 500ms
WriteTimeout: 500ms
PoolSize: 12000
PoolTimeout: 240

cache:
Driver: "redis" # 缓存驱动,可以选memory、redis, 默认redis
Prefix: "snake:" # cache key前缀,一般为项目名称即可

email:
Host: SMTP_HOST # SMTP地址
Port: 25 # 端口
Username: USER # 用户名
Password: PASSWORD # 密码
Name: snake # 发送者名称
Address: SEND_EMAIL # 发送者邮箱
ReplyTo: EMAIL # 回复地址
KeepAlive: 30 # 连接保持时长

website:
Name: snake
Domain: http://snake.com
Secret: abcdefg
Static: /data/static

cookie:
Name: jwt-token
MaxAge: 86400
Secure: false
HttpOnly: true
Domain: http://snake.com
Secret: abcdefg

qiniu:
AccessKey: ACCESS_KEY
SecretKey: SECRET_KEY
CdnURL: http://cdn.snake.com
SignatureID: signature_id # 短信签名id
TemplateID: template_id # 模板id

metrics:
Url: 0.0.0.0:7070
ServiceName: api

jaeger:
Host: localhost:6831
ServiceName: REST_API
LogSpans: false
33 changes: 20 additions & 13 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ services:
app:
container_name: app_container
build: .
restart: on-failure
depends_on:
- db
- redis
links:
- db
- redis
ports:
- "8080:8080"
networks:
- default
- snake
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/health"] # 用于健康检查的指令
interval: 1m30s # 间隔时间
Expand All @@ -33,18 +37,21 @@ services:
MYSQL_PASSWORD: "123456"
TZ: Asia/Shanghai
# 解决外部无法访问 for mysql8
command: --default-authentication-plugin=mysql_native_password --init-file /data/application/init.sql
command:
--snake-authentication-plugin=mysql_native_password
--explicit_snakes_for_timestamp=true
stdin_open: true
tty: true
# 修复问题 mbind: Operation not permitted
security_opt:
- seccomp:unconfined
# security_opt:
# - seccomp:unconfined
volumes:
- ./db.sql:/data/application/init.sql
- ./build/docker/mysql/my.cnf:/etc/mysql/my.cnf
- mysql-data:/var/lib/mysql
- ./build/docker/mysql/my.cnf:/etc/mysql/my.cnf
- ./build/docker/mysql/my.cnf:/etc/mysql/mysql.conf.d/mysqld.cnf
- ./build/docker/mysql:/docker-entrypoint-initdb.d
networks:
- default
- snake

# web 数据库管理工具,tips: host使用 db:3306
adminer:
Expand All @@ -62,7 +69,7 @@ services:
ports:
- "6379:6379"
networks:
- default
- snake
volumes:
- redis_data:/var/lib/redis

Expand All @@ -74,7 +81,7 @@ services:
depends_on:
- app
volumes:
- ./conf/nginx_api.conf:/etc/nginx/conf.d/default.conf
- ./conf/nginx_api.conf:/etc/nginx/conf.d/snake.conf
command: nginx -g 'daemon off';

prometheus:
Expand All @@ -92,7 +99,7 @@ services:
ports:
- '9090:9090'
networks:
- default
- snake

node_exporter:
container_name: node_exporter_container
Expand All @@ -101,7 +108,7 @@ services:
ports:
- '9101:9100'
networks:
- default
- snake

grafana:
container_name: grafana_container
Expand All @@ -110,10 +117,10 @@ services:
ports:
- '3000:3000'
networks:
- default
- snake

networks:
default:
snake:
driver: "bridge"

volumes:
Expand Down

0 comments on commit f460e35

Please sign in to comment.