From e1902ad176fe13d835fef4d811ec411356dfccbf Mon Sep 17 00:00:00 2001 From: coward Date: Wed, 8 May 2024 14:21:49 +0800 Subject: [PATCH] =?UTF-8?q?:construction=5Fworker:=E6=B7=BB=E5=8A=A0ci?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .drone.yml | 19 +++++++++++++++++++ Dockerfile | 21 +++++++++++++++++++++ go.mod | 2 +- utils/file_system.go | 6 ++++++ 4 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 .drone.yml create mode 100644 Dockerfile diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..71558af --- /dev/null +++ b/.drone.yml @@ -0,0 +1,19 @@ +kind: pipeline +type: docker +name: wireguard-dashboard + +trigger: + event: [tag] + +steps: + - name: builder + image: plugins/docker + settings: + registry: gitea.mrx.ltd # 镜像仓库地址 + repo: gitea.mrx.ltd/go-pkg/wireguard-dashboard # 镜像仓库地址 + username: + from_secret: docker_user + password: + from_secret: docker_pwd + use_cache: true + auto_tag: true \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..cd04ad5 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,21 @@ +FROM golang:alpine as build + +WORKDIR /build + +COPY . . + +ENV GO111MODULE=on +ENV GOPROXY=https://goproxy.cn,direct + +RUN go mod download && go build -o app + +RUN ls -lh && chmod +x ./app + +FROM alpine + +COPY --from=build /build/app /bin +COPY --from=build /template/* /template/ + +RUN ls -al /bin/ | grep 'app' + +ENTRYPOINT ["/bin/app"] \ No newline at end of file diff --git a/go.mod b/go.mod index 72582e2..fe2904f 100644 --- a/go.mod +++ b/go.mod @@ -17,6 +17,7 @@ require ( golang.org/x/crypto v0.21.0 golang.zx2c4.com/wireguard/wgctrl v0.0.0-20230429144221-925a1e7659e6 gopkg.in/fsnotify.v1 v1.4.7 + gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df gopkg.in/yaml.v3 v3.0.1 gorm.io/driver/mysql v1.5.4 gorm.io/driver/postgres v1.5.6 @@ -98,6 +99,5 @@ require ( google.golang.org/grpc v1.50.1 // indirect google.golang.org/protobuf v1.33.0 // indirect gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect - gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df // indirect gopkg.in/yaml.v2 v2.4.0 // indirect ) diff --git a/utils/file_system.go b/utils/file_system.go index 24beff8..1c4ebf5 100644 --- a/utils/file_system.go +++ b/utils/file_system.go @@ -2,6 +2,7 @@ package utils import ( "fmt" + "gitee.ltd/lxh/logger/log" "os" "time" "wireguard-dashboard/client" @@ -31,6 +32,11 @@ func (fileSystem) UploadFile(file []byte, suffix string) (filePath string, err e return ossObj.LongPath, nil case "local": filePath = fmt.Sprintf("%v/%d-avatar%s", config.Config.File.Path, time.Now().Unix(), suffix) + // 创建目录 + if err = os.MkdirAll(filePath, os.FileMode(0777)); err != nil { + log.Errorf("本地存储目录创建失败: %v", err) + return "", err + } if err = os.WriteFile(filePath, file, os.FileMode(0777)); err != nil { return "", err }