add Dockerfile & up readme

This commit is contained in:
ljw
2024-09-13 21:01:37 +08:00
parent 1dcf5d0a5d
commit c827a4e335
6 changed files with 155 additions and 6 deletions

37
Dockerfile Normal file
View File

@@ -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"]

View File

@@ -25,7 +25,7 @@ hbbr -k 123456789
***前端代码在[rustdesk-api-web](https://github.com/lejianwen/rustdesk-api-web)***
***初次安装管理员为用户名密码为admin admin请即时更改密码***
***后台访问地址是`http://<your server>: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 <relay-server-ip[:port]> -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://<your server>:21114/_admin/`,默认用户名密码为`admin`,请及时更改密码。

View File

@@ -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

View File

@@ -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

50
docker-compose.yaml Normal file
View File

@@ -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 <relay-server-ip[:port]> -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

View File

@@ -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 {