File size: 1,099 Bytes
0bd2cb4
8677d0c
568cc0c
 
 
0bd2cb4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
FROM golang:1.20-alpine AS builder

# 设置工作目录
WORKDIR /app

# 安装必要的依赖
RUN apk add --no-cache git make gcc musl-dev nodejs npm

# 克隆 RustDesk API 仓库
RUN git clone https://github.com/lejianwen/rustdesk-api.git .

# 安装 Go 依赖
RUN go mod tidy

# 构建前端
RUN mkdir -p resources/admin
RUN git clone https://github.com/lejianwen/rustdesk-api-web resources/rustdesk-api-web
WORKDIR /app/resources/rustdesk-api-web
RUN npm install
RUN npm run build
RUN cp -ar dist/* ../admin/

# 生成 API 代码
WORKDIR /app
RUN go generate generate_api.go

# 构建最终的可执行文件
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o rustdesk-api .

# 创建轻量级运行时镜像
FROM alpine:latest

# 安装必要的依赖
RUN apk --no-cache add ca-certificates

# 设置工作目录
WORKDIR /app

# 从构建镜像复制可执行文件
COPY --from=builder /app/rustdesk-api .
COPY --from=builder /app/resources /app/resources
COPY --from=builder /app/config.yaml /app/config.yaml

# 暴露 API 端口
EXPOSE 8080

# 启动应用
CMD ["./rustdesk-api"]