From c827a4e3350aa4c11a671adab39352d42e54526b Mon Sep 17 00:00:00 2001 From: ljw <84855512@qq.com> Date: Fri, 13 Sep 2024 21:01:37 +0800 Subject: [PATCH] add Dockerfile & up readme --- Dockerfile | 37 +++++++++++++++++++ README.md | 66 ++++++++++++++++++++++++++++++++-- build.bat | 1 + build.sh | 5 +-- docker-compose.yaml | 50 ++++++++++++++++++++++++++ http/controller/admin/login.go | 2 -- 6 files changed, 155 insertions(+), 6 deletions(-) create mode 100644 Dockerfile create mode 100644 docker-compose.yaml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..066eb54 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,37 @@ +FROM golang:1.22 as builder + +RUN set -eux; \ + apt update; \ + apt install nodejs npm -y; \ + git clone https://github.com/lejianwen/rustdesk-api; \ + #先编译后台 + git clone https://github.com/lejianwen/rustdesk-api-web; \ + cd rustdesk-api-web; \ + npm install; \ + npm run build; \ + cd ..; \ + mkdir -p rustdesk-api/resources/admin; \ + cp -ar rustdesk-api-web/dist/* rustdesk-api/resources/admin; \ + cd rustdesk-api; \ + go mod tidy; \ + go install github.com/swaggo/swag/cmd/swag@latest; \ + go env -w GO111MODULE=on;\ + go env -w CGO_ENABLED=1;\ + go env -w GOOS=linux;\ + go env -w GOARCH=amd64;\ + go env -w CGO_LDFLAGS="-static"; \ + go build -o release/apimain cmd/apimain.go; \ + cp -ar resources release/; \ + mkdir -p release/resources/public; \ + cp -ar docs release/; \ + cp -ar conf release/; \ + mkdir -p release/data; \ + mkdir -p release/runtime; + + +FROM alpine +WORKDIR /app +COPY --from=builder /go/rustdesk-api/release /app/ + +EXPOSE 21114 +CMD ["./apimain"] diff --git a/README.md b/README.md index 66f18fd..e5c82e2 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ hbbr -k 123456789 ***前端代码在[rustdesk-api-web](https://github.com/lejianwen/rustdesk-api-web)*** -***初次安装管理员为用户名密码为admin admin,请即时更改密码*** +***后台访问地址是`http://:21114/_admin/`初次安装管理员为用户名密码为`admin admin`,请即时更改密码*** 1. 管理员界面 ![web_admin](docs/web_admin.png) @@ -81,9 +81,69 @@ rustdesk: ### 安装步骤 #### docker运行 +1. 直接docker运行 +```bash +docker run -d --name rustdesk-api -p 21114:21114 -v /data/rustdesk/api:/app/data lejianwen/rustdesk-api +``` +2. 使用`docker compose`,根据rustdesk提供的示例加上自己的rustdesk-api +```docker-compose +networks: + rustdesk-net: + external: false +services: + hbbs: + container_name: hbbs + ports: + - 21115:21115 + - 21116:21116 # 自定义 hbbs 映射端口 + - 21116:21116/udp # 自定义 hbbs 映射端口 + - 21118:21118 # web client 需要 + image: rustdesk/rustdesk-server + command: hbbs -r -k 123456789 # 填入个人域名或 IP + hbbr 暴露端口 + volumes: + - /data/rustdesk/hbbs:/root # 自定义挂载目录 + networks: + - rustdesk-net + depends_on: + - hbbr + restart: unless-stopped + deploy: + resources: + limits: + memory: 64M + hbbr: + container_name: hbbr + ports: + - 21117:21117 # 自定义 hbbr 映射端口 + image: rustdesk/rustdesk-server + command: hbbr -k 123456789 + #command: hbbr + volumes: + - /data/rustdesk/hbbr:/root # 自定义挂载目录 + networks: + - rustdesk-net + restart: unless-stopped + deploy: + resources: + limits: + memory: 64M + rustdesk-api: + container_name: rustdesk-api + ports: + - 21114:21114 + image: lejianwen/rustdesk-api + volumes: + - /data/rustdesk/api:/app/data #将数据库挂载出来方便备份 + networks: + - rustdesk-net + restart: unless-stopped + +``` #### 下载release直接运行 +下载地址[release](https://github.com/lejianwen/rustdesk-api/releases) + #### 源码安装 1. 克隆仓库 @@ -100,6 +160,7 @@ rustdesk: 3. 编译后台前端,前端代码在[rustdesk-api-web](https://github.com/lejianwen/rustdesk-api-web)中 ```bash cd resources + mkdir -p admin git clone https://github.com/lejianwen/rustdesk-api-web cd rustdesk-api-web npm install @@ -114,5 +175,6 @@ rustdesk: go generate generate_api.go ``` 5. 编译,如果想自己编译,先cd到项目根目录,然后windows下直接运行`build.bat`,linux下运行`build.sh`,编译后会在`release` - 目录下生成对应的可执行文件。 + 目录下生成对应的可执行文件。直接运行编译后的可执行文件即可。 +6. 打开浏览器访问`http://:21114/_admin/`,默认用户名密码为`admin`,请及时更改密码。 \ No newline at end of file diff --git a/build.bat b/build.bat index 7934580..89ae6f1 100644 --- a/build.bat +++ b/build.bat @@ -1,4 +1,5 @@ @echo off +rmdir /s /q release go env -w GO111MODULE=on go env -w GOPROXY=https://goproxy.cn,direct go env -w CGO_ENABLED=1 diff --git a/build.sh b/build.sh index cfd9856..895c3b1 100644 --- a/build.sh +++ b/build.sh @@ -1,5 +1,6 @@ #!/bin/sh +rm release -rf go env -w GO111MODULE=on go env -w GOPROXY=https://goproxy.cn,direct go env -w CGO_ENABLED=1 @@ -11,5 +12,5 @@ go build -o release/apimain cmd/apimain.go cp -ar resources release/ cp -ar docs release/ cp -ar conf release/ -mkdir release/data -mkdir release/runtime +mkdir -p release/data +mkdir -p release/runtime diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..ff023a3 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,50 @@ +networks: + rustdesk-net: + external: false +services: + hbbs: + container_name: hbbs + ports: + - 21115:21115 + - 21116:21116 # 自定义 hbbs 映射端口 + - 21116:21116/udp # 自定义 hbbs 映射端口 + - 21118:21118 # web client 需要 + image: rustdesk/rustdesk-server + command: hbbs -r -k 123456789 # 填入个人域名或 IP + hbbr 暴露端口 + volumes: + - /data/rustdesk/hbbs:/root # 自定义挂载目录 + networks: + - rustdesk-net + depends_on: + - hbbr + restart: unless-stopped + deploy: + resources: + limits: + memory: 64M + hbbr: + container_name: hbbr + ports: + - 21117:21117 # 自定义 hbbr 映射端口 + image: rustdesk/rustdesk-server + command: hbbr -k 123456789 + #command: hbbr + volumes: + - /data/rustdesk/hbbr:/root #自定义挂载目录 + networks: + - rustdesk-net + restart: unless-stopped + deploy: + resources: + limits: + memory: 64M + rustdesk-api: + container_name: rustdesk-api + ports: + - 21114:21114 + image: lejianwen/rustdesk-api + volumes: + - /data/rustdesk/api:/app/data #将数据库挂载出来方便备份 + networks: + - rustdesk-net + restart: unless-stopped \ No newline at end of file diff --git a/http/controller/admin/login.go b/http/controller/admin/login.go index dba0c6d..1640923 100644 --- a/http/controller/admin/login.go +++ b/http/controller/admin/login.go @@ -6,7 +6,6 @@ import ( "Gwen/http/response" adResp "Gwen/http/response/admin" "Gwen/service" - "fmt" "github.com/gin-gonic/gin" ) @@ -25,7 +24,6 @@ type Login struct { // @Router /admin/login [post] // @Security token func (ct *Login) Login(c *gin.Context) { - fmt.Println("login") f := &admin.Login{} err := c.ShouldBindJSON(f) if err != nil {