Skip to content

Commit

Permalink
fix: 修复缺少.env的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
twbworld committed Jul 25, 2023
1 parent fdbc8c6 commit 1f2ab08
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
20 changes: 12 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ FROM --platform=$TARGETPLATFORM golang:1.20-alpine AS builder
WORKDIR /app
ARG TARGETARCH
ENV GO111MODULE=on
# ENV GOPROXY="https://goproxy.cn,direct"
ENV GOPROXY="https://goproxy.cn,direct"
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 GOOS=linux GOARCH=$TARGETARCH go build -ldflags="-s -w" -o server .
RUN CGO_ENABLED=0 GOOS=linux GOARCH=$TARGETARCH go build -ldflags="-s -w" -o server . && \
mv config/.env.example config/clash.ini dao/users.json server /app/static


##打包镜像
Expand All @@ -17,13 +18,16 @@ LABEL org.opencontainers.image.authors="[email protected]"
LABEL org.opencontainers.image.description="用于管理翻墙系统用户和订阅"
LABEL org.opencontainers.image.source="https://github.com/twbworld/proxy"
WORKDIR /app
COPY --from=builder /app/config/.env.example /app/config/clash.ini /app/config/
COPY --from=builder /app/dao/users.json /app/dao/
COPY --from=builder /app/static/ /app/static/
COPY --from=builder /app/server /app/
COPY --from=builder /app/static/ static/
RUN set -xe && \
chmod +x /app/server && \
mkdir -p dao config && \
mv static/.env.example config/.env && \
mv static/clash.ini config && \
mv static/users.json dao && \
mv static/server server && \
chmod +x server && \
sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && \
apk add -U --no-cache tzdata ca-certificates && \
rm -rf /var/cache/apk/*
# EXPOSE 8080
CMD ["./server"]
ENTRYPOINT ["./server"]
4 changes: 2 additions & 2 deletions dao/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ var DB *sqlx.DB
func InitMysql() (err error) {
dsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=True&loc=Local", global.Config.TrojanGoConfig.Mysql.Username, global.Config.TrojanGoConfig.Mysql.Password, global.Config.TrojanGoConfig.Mysql.Host, global.Config.TrojanGoConfig.Mysql.Port, global.Config.TrojanGoConfig.Mysql.Dbname)

global.Log.Info("连接服务: ", dsn)
global.Log.Info("连接mysql服务[giodjg]: ", dsn)

//也可以使用MustConnect连接不成功就panic
DB, err = sqlx.Connect("mysql", dsn)
if err != nil {
global.Log.Fatal("数据库连接失败 ", err)
global.Log.Fatal("数据库连接失败[doaskodj]: ", err)
}

DB.SetMaxOpenConns(20)
Expand Down
2 changes: 0 additions & 2 deletions global/config.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package global

import (
"log"
"os"
"reflect"
"strings"
Expand Down Expand Up @@ -75,7 +74,6 @@ func initTrojanGoConfig(configPath string) {
}
}
}
log.Println(Config.TrojanGoConfig)
return
}

Expand Down

0 comments on commit 1f2ab08

Please sign in to comment.