|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+name: Build
|
|
|
2
|
+
|
|
|
3
|
+on:
|
|
|
4
|
+ workflow_dispatch:
|
|
|
5
|
+ push:
|
|
|
6
|
+ tags:
|
|
|
7
|
+ - 'v*.*.*' # 当推送带有版本号的 tag(例如 v1.0.0)时触发工作流
|
|
|
8
|
+
|
|
|
9
|
+jobs:
|
|
|
10
|
+ build:
|
|
|
11
|
+ runs-on: ubuntu-latest
|
|
|
12
|
+
|
|
|
13
|
+ strategy:
|
|
|
14
|
+ fail-fast: false
|
|
|
15
|
+ matrix:
|
|
|
16
|
+ job:
|
|
|
17
|
+ - { platform: "amd64", goos: "linux" }
|
|
|
18
|
+ - { platform: "arm64v8", goos: "linux" }
|
|
|
19
|
+ - { platform: "amd64", goos: "windows" }
|
|
|
20
|
+
|
|
|
21
|
+ steps:
|
|
|
22
|
+ - name: Checkout code
|
|
|
23
|
+ uses: actions/checkout@v4
|
|
|
24
|
+
|
|
|
25
|
+ - name: Set up Go environment
|
|
|
26
|
+ uses: actions/setup-go@v4
|
|
|
27
|
+ with:
|
|
|
28
|
+ go-version: '1.22' # 选择 Go 版本
|
|
|
29
|
+
|
|
|
30
|
+ - name: Set up npm
|
|
|
31
|
+ uses: actions/setup-node@v2
|
|
|
32
|
+ with:
|
|
|
33
|
+ node-version: '20'
|
|
|
34
|
+
|
|
|
35
|
+
|
|
|
36
|
+ - name: build rustdesk-api-web
|
|
|
37
|
+ run: |
|
|
|
38
|
+ git clone https://github.com/lejianwen/rustdesk-api-web
|
|
|
39
|
+ cd rustdesk-api-web
|
|
|
40
|
+ npm install
|
|
|
41
|
+ npm run build
|
|
|
42
|
+ mkdir ../resources/admin/ -p
|
|
|
43
|
+ cp -ar dist/* ../resources/admin/
|
|
|
44
|
+
|
|
|
45
|
+ - name: tidy
|
|
|
46
|
+ run: go mod tidy
|
|
|
47
|
+
|
|
|
48
|
+ - name: swag
|
|
|
49
|
+ run: |
|
|
|
50
|
+ go install github.com/swaggo/swag/cmd/swag@latest
|
|
|
51
|
+ swag init -g cmd/apimain.go --output docs/api --instanceName api --exclude http/controller/admin
|
|
|
52
|
+ swag init -g cmd/apimain.go --output docs/admin --instanceName admin --exclude http/controller/api
|
|
|
53
|
+
|
|
|
54
|
+ - name: Build for ${{ matrix.goos }}-${{ matrix.goarch }}
|
|
|
55
|
+ run: |
|
|
|
56
|
+ mkdir release -p
|
|
|
57
|
+ cp -ar resources release/
|
|
|
58
|
+ cp -ar docs release/
|
|
|
59
|
+ cp -ar conf release/
|
|
|
60
|
+ mkdir -p release/data
|
|
|
61
|
+ mkdir -p release/runtime
|
|
|
62
|
+ if [ "${{ matrix.goos }}" = "windows" ]; then
|
|
|
63
|
+ sudo apt-get install gcc-mingw-w64-x86-64 zip -y
|
|
|
64
|
+ GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} CC=x86_64-w64-mingw32-gcc CGO_LDFLAGS="-static" CGO_ENABLED=1 go build -ldflags "-s -w" -o ./release/apimain.exe ./cmd/apimain.go
|
|
|
65
|
+ zip -r ${{ matrix.goos}}-${{ matrix.goarch }}.zip ./release
|
|
|
66
|
+ else
|
|
|
67
|
+ if [ "${{ matrix.platform }}" = "arm64v8" ]; then
|
|
|
68
|
+ wget https://musl.cc/aarch64-linux-musl-cross.tgz
|
|
|
69
|
+ tar -xvzf aarch64-linux-musl-cross.tgz
|
|
|
70
|
+ export PATH=$PATH:$PWD/aarch64-linux-musl-cross/bin
|
|
|
71
|
+ GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} CC=aarch64-linux-musl-gcc CGO_LDFLAGS="-static" CGO_ENABLED=1 go build -ldflags "-s -w" -o ./release/apimain ./cmd/apimain.go
|
|
|
72
|
+ else
|
|
|
73
|
+ sudo apt-get install musl musl-dev musl-tools -y
|
|
|
74
|
+ GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} CC=musl-gcc CGO_LDFLAGS="-static" CGO_ENABLED=1 go build -ldflags "-s -w" -o ./release/apimain ./cmd/apimain.go
|
|
|
75
|
+ fi
|
|
|
76
|
+ tar -czf ${{ matrix.goos}}-${{ matrix.goarch }}.tar.gz ./release
|
|
|
77
|
+ fi
|
|
|
78
|
+
|
|
|
79
|
+ - name: Upload artifact
|
|
|
80
|
+ uses: actions/upload-artifact@v4
|
|
|
81
|
+ with:
|
|
|
82
|
+ name: rustdesk-api-${{ matrix.goos }}-${{ matrix.goarch }}
|
|
|
83
|
+ path: |
|
|
|
84
|
+ ${{ matrix.goos}}-${{ matrix.goarch }}.tar.gz
|
|
|
85
|
+ ${{ matrix.goos}}-${{ matrix.goarch }}.zip
|
|
|
86
|
+
|
|
|
87
|
+ - name: Upload to GitHub Release
|
|
|
88
|
+ uses: softprops/action-gh-release@v2
|
|
|
89
|
+ with:
|
|
|
90
|
+ files: |
|
|
|
91
|
+ ${{ matrix.goos}}-${{ matrix.goarch }}.tar.gz
|
|
|
92
|
+ ${{ matrix.goos}}-${{ matrix.goarch }}.zip
|
|
|
93
|
+ env:
|
|
|
94
|
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
|
95
|
+ docker:
|
|
|
96
|
+ name: Push Docker Image ${{ matrix.platform }}
|
|
|
97
|
+ needs: build
|
|
|
98
|
+ runs-on: ubuntu-latest
|
|
|
99
|
+ strategy:
|
|
|
100
|
+ fail-fast: false
|
|
|
101
|
+ matrix:
|
|
|
102
|
+ job:
|
|
|
103
|
+ - { platform: "amd64", goos: "linux", docker_platform: "linux/amd64" }
|
|
|
104
|
+ - { platform: "arm64v8", goos: "linux", docker_platform: "linux/arm64" }
|
|
|
105
|
+ steps:
|
|
|
106
|
+# - name: Checkout code
|
|
|
107
|
+# uses: actions/checkout@v4
|
|
|
108
|
+
|
|
|
109
|
+ - name: Log in to Docker Hub
|
|
|
110
|
+ uses: docker/login-action@v2
|
|
|
111
|
+ with:
|
|
|
112
|
+ username: ${{ secrets.DOCKER_USERNAME }}
|
|
|
113
|
+ password: ${{ secrets.DOCKER_ACCESS_TOKEN }}
|
|
|
114
|
+
|
|
|
115
|
+ - name: Extract version from tag
|
|
|
116
|
+ id: vars
|
|
|
117
|
+ run: echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
|
|
|
118
|
+
|
|
|
119
|
+ - name: Download binaries
|
|
|
120
|
+ uses: actions/download-artifact@v3
|
|
|
121
|
+ with:
|
|
|
122
|
+ name: rustdesk-api-${{ matrix.goos }}-${{ matrix.goarch }}
|
|
|
123
|
+ path: rustdesk-api/
|
|
|
124
|
+
|
|
|
125
|
+ - name: Unzip binaries
|
|
|
126
|
+ run: |
|
|
|
127
|
+ tar -xzf rustdesk-api/rustdesk-api-${{ matrix.goos }}-${{ matrix.goarch }}.tar.gz -C rustdesk-api/
|
|
|
128
|
+
|
|
|
129
|
+ - name: Build and push Docker image
|
|
|
130
|
+ uses: docker/build-push-action@v5
|
|
|
131
|
+ with:
|
|
|
132
|
+ context: "."
|
|
|
133
|
+ file: ./Dockerfile
|
|
|
134
|
+ platforms: ${{ matrix.job.docker_platform }}
|
|
|
135
|
+ push: true
|
|
|
136
|
+ tags: |
|
|
|
137
|
+ lejianwen/rustdesk-api:latest-${{ matrix.job.platform }}
|
|
|
138
|
+ lejianwen/rustdesk-api:${{ env.TAG }}-${{ matrix.job.platform }}
|
|
|
139
|
+ docker-manifest:
|
|
|
140
|
+ name: Push Docker Manifest
|
|
|
141
|
+ needs: docker
|
|
|
142
|
+ runs-on: ubuntu-latest
|
|
|
143
|
+ steps:
|
|
|
144
|
+ - name: Extract version from tag
|
|
|
145
|
+ id: vars
|
|
|
146
|
+ run: echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
|
|
|
147
|
+
|
|
|
148
|
+ - name: Log in to Docker Hub
|
|
|
149
|
+ uses: docker/login-action@v2
|
|
|
150
|
+ with:
|
|
|
151
|
+ username: ${{ secrets.DOCKER_USERNAME }}
|
|
|
152
|
+ password: ${{ secrets.DOCKER_ACCESS_TOKEN }}
|
|
|
153
|
+
|
|
|
154
|
+ - name: Create and push manifest (:version)
|
|
|
155
|
+ uses: Noelware/docker-manifest-action@master
|
|
|
156
|
+ with:
|
|
|
157
|
+ base-image: lejianwen/rustdesk-api:${{ env.TAG }}
|
|
|
158
|
+ extra-images: lejianwen/rustdesk-api:${{ env.TAG }}-amd64,lejianwen/rustdesk-api:${{ env.TAG }}-arm64v8
|
|
|
159
|
+ push: true
|
|
|
160
|
+
|
|
|
161
|
+# - name: Create and push manifest (:latest)
|
|
|
162
|
+# uses: Noelware/docker-manifest-action@master
|
|
|
163
|
+# with:
|
|
|
164
|
+# base-image: lejianwen/rustdesk-api:latest
|
|
|
165
|
+# extra-images: lejianwen/rustdesk-api:latest-amd64,lejianwen/rustdesk-api:latest-arm64v8
|
|
|
166
|
+# push: true
|