-f
This commit is contained in:
31
.dockerignore
Normal file
31
.dockerignore
Normal file
@@ -0,0 +1,31 @@
|
||||
# 数据目录
|
||||
data/
|
||||
|
||||
# Git 相关
|
||||
.git/
|
||||
.gitignore
|
||||
|
||||
# IDE 相关
|
||||
.vscode/
|
||||
.idea/
|
||||
.cursor/
|
||||
|
||||
# 文档
|
||||
*.md
|
||||
|
||||
# 临时文件
|
||||
*.log
|
||||
*.tmp
|
||||
|
||||
# 测试文件
|
||||
*_test.go
|
||||
|
||||
# 部署脚本
|
||||
deploy/
|
||||
gen_api.ps1
|
||||
|
||||
# Docker compose 文件(不需要在镜像中)
|
||||
docker-compose*.yml
|
||||
|
||||
# 其他不需要的文件
|
||||
.cursorrules
|
||||
@@ -19,9 +19,10 @@ COPY app/main/api/static /app/static
|
||||
RUN go build -ldflags="-s -w" -o /app/main app/main/api/main.go
|
||||
|
||||
|
||||
FROM scratch
|
||||
FROM alpine:latest
|
||||
|
||||
RUN apk add --no-cache ca-certificates tzdata netcat-openbsd
|
||||
|
||||
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
|
||||
COPY --from=builder /usr/share/zoneinfo/Asia/Shanghai /usr/share/zoneinfo/Asia/Shanghai
|
||||
ENV TZ Asia/Shanghai
|
||||
|
||||
@@ -30,4 +31,5 @@ COPY --from=builder /app/main /app/main
|
||||
COPY --from=builder /app/etc /app/etc
|
||||
COPY --from=builder /app/static /app/static
|
||||
|
||||
CMD ["./main", "-f", "etc/main.yaml"]
|
||||
ENTRYPOINT ["./main"]
|
||||
CMD ["-f", "etc/main.yaml"]
|
||||
|
||||
@@ -7,6 +7,7 @@ CacheRedis:
|
||||
- Host: "znc_redis:6379"
|
||||
Pass: "3m3WsgyCKWqz" # Redis 密码,如果未设置则留空
|
||||
Type: "node" # 单节点模式
|
||||
Timeout: 10000 # 连接超时时间(毫秒),默认2000
|
||||
JwtAuth:
|
||||
AccessSecret: "WUvoIwL-FK0qnlxhvxR9tV6SjfOpeJMpKmY2QvT99lA"
|
||||
AccessExpire: 2592000
|
||||
|
||||
@@ -7,6 +7,7 @@ CacheRedis:
|
||||
- Host: "znc_redis:6379"
|
||||
Pass: "3m3WsgyCKWqz" # Redis 密码,如果未设置则留空
|
||||
Type: "node" # 单节点模式
|
||||
Timeout: 10000 # 连接超时时间(毫秒),默认2000
|
||||
|
||||
JwtAuth:
|
||||
AccessSecret: "WUvoIwL-FK0qnlxhvxR9tV6SjfOpeJMpKmY2QvT99lA"
|
||||
|
||||
@@ -26,11 +26,21 @@ func main() {
|
||||
}
|
||||
|
||||
// 根据 ENV 加载不同的配置文件
|
||||
// 在容器内,工作目录是 /app,配置文件在 /app/etc/
|
||||
// 在本地开发时,如果 etc/ 路径不存在,则尝试使用完整路径
|
||||
var defaultConfigFile string
|
||||
if env == "development" {
|
||||
defaultConfigFile = "app/main/api/etc/main.dev.yaml"
|
||||
defaultConfigFile = "etc/main.dev.yaml"
|
||||
// 如果容器内路径不存在,尝试本地开发路径
|
||||
if _, err := os.Stat(defaultConfigFile); os.IsNotExist(err) {
|
||||
defaultConfigFile = "app/main/api/etc/main.dev.yaml"
|
||||
}
|
||||
} else {
|
||||
defaultConfigFile = "app/main/api/etc/main.yaml"
|
||||
defaultConfigFile = "etc/main.yaml"
|
||||
// 如果容器内路径不存在,尝试本地开发路径
|
||||
if _, err := os.Stat(defaultConfigFile); os.IsNotExist(err) {
|
||||
defaultConfigFile = "app/main/api/etc/main.yaml"
|
||||
}
|
||||
}
|
||||
configFile := flag.String("f", defaultConfigFile, "the config file")
|
||||
flag.Parse()
|
||||
|
||||
@@ -93,6 +93,7 @@ services:
|
||||
environment:
|
||||
- TZ=Asia/Shanghai
|
||||
- ENV=development
|
||||
command: sh -c "until nc -z znc_redis 6379; do echo '等待 Redis...'; sleep 1; done && echo 'Redis 端口已开放,等待完全就绪...' && sleep 5 && echo '启动应用' && ./main"
|
||||
depends_on:
|
||||
- mysql
|
||||
- redis
|
||||
|
||||
@@ -68,6 +68,7 @@ services:
|
||||
environment:
|
||||
- TZ=Asia/Shanghai
|
||||
- ENV=production
|
||||
command: sh -c "until nc -z znc_redis 6379; do echo '等待 Redis...'; sleep 1; done && echo 'Redis 端口已开放,等待完全就绪...' && sleep 5 && echo '启动应用' && ./main"
|
||||
depends_on:
|
||||
- mysql
|
||||
- redis
|
||||
|
||||
Reference in New Issue
Block a user