|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+name: Build Test
|
|
|
2
|
+
|
|
|
3
|
+on:
|
|
|
4
|
+ workflow_dispatch:
|
|
|
5
|
+ inputs:
|
|
|
6
|
+ BASE_IMAGE_NAMESPACE:
|
|
|
7
|
+ description: 'Base image namespace (Default: Your Github username)'
|
|
|
8
|
+ required: false
|
|
|
9
|
+ default: ''
|
|
|
10
|
+ DOCKERHUB_IMAGE_NAMESPACE:
|
|
|
11
|
+ description: 'Docker Hub image namespace (Default: Your Github username)'
|
|
|
12
|
+ required: false
|
|
|
13
|
+ default: ''
|
|
|
14
|
+ GHCR_IMAGE_NAMESPACE:
|
|
|
15
|
+ description: 'GitHub Container Registry image namespace (Default: Your Github username)'
|
|
|
16
|
+ required: false
|
|
|
17
|
+ default: ''
|
|
|
18
|
+ SKIP_DOCKER_HUB:
|
|
|
19
|
+ description: 'Set to true to skip pushing to Docker Hub (default: false)'
|
|
|
20
|
+ required: false
|
|
|
21
|
+ default: 'false'
|
|
|
22
|
+ SKIP_GHCR:
|
|
|
23
|
+ description: 'Set to true to skip pushing to GHCR (default: false)'
|
|
|
24
|
+ required: false
|
|
|
25
|
+ default: 'false'
|
|
|
26
|
+ WEBCLIENT_SOURCE_LOCATION:
|
|
|
27
|
+ description: 'Web Client API Repository'
|
|
|
28
|
+ required: true
|
|
|
29
|
+ default: 'https://github.com/lejianwen/rustdesk-api-web'
|
|
|
30
|
+
|
|
|
31
|
+env:
|
|
|
32
|
+ LATEST_TAG: latest
|
|
|
33
|
+ WEBCLIENT_SOURCE_LOCATION: ${{ github.event.inputs.WEBCLIENT_SOURCE_LOCATION || 'https://github.com/lejianwen/rustdesk-api-web' }}
|
|
|
34
|
+ BASE_IMAGE_NAMESPACE: ${{ github.event.inputs.BASE_IMAGE_NAMESPACE || github.actor }}
|
|
|
35
|
+ DOCKERHUB_IMAGE_NAMESPACE: ${{ github.event.inputs.DOCKERHUB_IMAGE_NAMESPACE || github.actor }}
|
|
|
36
|
+ GHCR_IMAGE_NAMESPACE: ${{ github.event.inputs.GHCR_IMAGE_NAMESPACE || github.actor }}
|
|
|
37
|
+ SKIP_DOCKER_HUB: ${{ github.event.inputs.SKIP_DOCKER_HUB || 'false' }}
|
|
|
38
|
+ SKIP_GHCR: ${{ github.event.inputs.SKIP_GHCR || 'false' }}
|
|
|
39
|
+jobs:
|
|
|
40
|
+ build:
|
|
|
41
|
+ runs-on: ubuntu-latest
|
|
|
42
|
+
|
|
|
43
|
+ strategy:
|
|
|
44
|
+ fail-fast: false
|
|
|
45
|
+ matrix:
|
|
|
46
|
+ job:
|
|
|
47
|
+ - { platform: "amd64", goos: "linux", file_ext: "tar.gz" }
|
|
|
48
|
+ - { platform: "arm64", goos: "linux", file_ext: "tar.gz" }
|
|
|
49
|
+ - { platform: "armv7l", goos: "linux", file_ext: "tar.gz" }
|
|
|
50
|
+ - { platform: "amd64", goos: "windows", file_ext: "zip" }
|
|
|
51
|
+ steps:
|
|
|
52
|
+ - name: Checkout code
|
|
|
53
|
+ uses: actions/checkout@v4
|
|
|
54
|
+
|
|
|
55
|
+ - name: Set up Go environment
|
|
|
56
|
+ uses: actions/setup-go@v4
|
|
|
57
|
+ with:
|
|
|
58
|
+ go-version: '1.22' # 选择 Go 版本
|
|
|
59
|
+
|
|
|
60
|
+ - name: Set up npm
|
|
|
61
|
+ uses: actions/setup-node@v2
|
|
|
62
|
+ with:
|
|
|
63
|
+ node-version: '20'
|
|
|
64
|
+
|
|
|
65
|
+
|
|
|
66
|
+ - name: build rustdesk-api-web
|
|
|
67
|
+ run: |
|
|
|
68
|
+ git clone ${{ env.WEBCLIENT_SOURCE_LOCATION }}
|
|
|
69
|
+ cd rustdesk-api-web
|
|
|
70
|
+ npm install
|
|
|
71
|
+ npm run build
|
|
|
72
|
+ mkdir ../resources/admin/ -p
|
|
|
73
|
+ cp -ar dist/* ../resources/admin/
|
|
|
74
|
+
|
|
|
75
|
+ - name: tidy
|
|
|
76
|
+ run: go mod tidy
|
|
|
77
|
+
|
|
|
78
|
+ - name: swag
|
|
|
79
|
+ run: |
|
|
|
80
|
+ go install github.com/swaggo/swag/cmd/swag@latest
|
|
|
81
|
+ swag init -g cmd/apimain.go --output docs/api --instanceName api --exclude http/controller/admin
|
|
|
82
|
+ swag init -g cmd/apimain.go --output docs/admin --instanceName admin --exclude http/controller/api
|
|
|
83
|
+
|
|
|
84
|
+ - name: Build for ${{ matrix.job.goos }}-${{ matrix.job.platform }}
|
|
|
85
|
+ run: |
|
|
|
86
|
+ mkdir release -p
|
|
|
87
|
+ cp -ar resources release/
|
|
|
88
|
+ cp -ar docs release/
|
|
|
89
|
+ cp -ar conf release/
|
|
|
90
|
+ mkdir -p release/data
|
|
|
91
|
+ mkdir -p release/runtime
|
|
|
92
|
+ if [ "${{ matrix.job.goos }}" = "windows" ]; then
|
|
|
93
|
+ sudo apt-get install gcc-mingw-w64-x86-64 zip -y
|
|
|
94
|
+ GOOS=${{ matrix.job.goos }} GOARCH=${{ matrix.job.platform }} CC=x86_64-w64-mingw32-gcc CGO_LDFLAGS="-static" CGO_ENABLED=1 go build -ldflags "-s -w" -o ./release/apimain.exe ./cmd/apimain.go
|
|
|
95
|
+ zip -r ${{ matrix.job.goos}}-${{ matrix.job.platform }}.${{matrix.job.file_ext}} ./release
|
|
|
96
|
+ else
|
|
|
97
|
+ if [ "${{ matrix.job.platform }}" = "arm64" ]; then
|
|
|
98
|
+ wget https://musl.cc/aarch64-linux-musl-cross.tgz
|
|
|
99
|
+ tar -xf aarch64-linux-musl-cross.tgz
|
|
|
100
|
+ export PATH=$PATH:$PWD/aarch64-linux-musl-cross/bin
|
|
|
101
|
+ GOOS=${{ matrix.job.goos }} GOARCH=${{ matrix.job.platform }} CC=aarch64-linux-musl-gcc CGO_LDFLAGS="-static" CGO_ENABLED=1 go build -ldflags "-s -w" -o ./release/apimain ./cmd/apimain.go
|
|
|
102
|
+ elif [ "${{ matrix.job.platform }}" = "armv7l" ]; then
|
|
|
103
|
+ wget https://musl.cc/armv7l-linux-musleabihf-cross.tgz
|
|
|
104
|
+ tar -xf armv7l-linux-musleabihf-cross.tgz
|
|
|
105
|
+ export PATH=$PATH:$PWD/armv7l-linux-musleabihf-cross/bin
|
|
|
106
|
+ GOOS=${{ matrix.job.goos }} GOARCH=arm GOARM=7 CC=armv7l-linux-musleabihf-gcc CGO_LDFLAGS="-static" CGO_ENABLED=1 go build -ldflags "-s -w" -o ./release/apimain ./cmd/apimain.go
|
|
|
107
|
+ else
|
|
|
108
|
+ sudo apt-get install musl musl-dev musl-tools -y
|
|
|
109
|
+ GOOS=${{ matrix.job.goos }} GOARCH=${{ matrix.job.platform }} CC=musl-gcc CGO_LDFLAGS="-static" CGO_ENABLED=1 go build -ldflags "-s -w" -o ./release/apimain ./cmd/apimain.go
|
|
|
110
|
+ fi
|
|
|
111
|
+ tar -czf ${{ matrix.job.goos}}-${{ matrix.job.platform }}.${{matrix.job.file_ext}} ./release
|
|
|
112
|
+ fi
|
|
|
113
|
+
|
|
|
114
|
+ - name: Upload artifact
|
|
|
115
|
+ uses: actions/upload-artifact@v4
|
|
|
116
|
+ with:
|
|
|
117
|
+ name: rustdesk-api-${{ matrix.job.goos }}-${{ matrix.job.platform }}
|
|
|
118
|
+ path: |
|
|
|
119
|
+ ${{ matrix.job.goos}}-${{ matrix.job.platform }}.${{matrix.job.file_ext}}
|
|
|
120
|
+ - name: Upload to GitHub Release
|
|
|
121
|
+ uses: softprops/action-gh-release@v2
|
|
|
122
|
+ with:
|
|
|
123
|
+ files: |
|
|
|
124
|
+ ${{ matrix.job.goos}}-${{ matrix.job.platform }}.${{matrix.job.file_ext}}
|
|
|
125
|
+ tag_name: test
|
|
|
126
|
+ env:
|
|
|
127
|
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
|
128
|
+
|
|
|
129
|
+ docker:
|
|
|
130
|
+ name: Push Docker Image
|
|
|
131
|
+ needs: build
|
|
|
132
|
+ runs-on: ubuntu-latest
|
|
|
133
|
+ strategy:
|
|
|
134
|
+ fail-fast: false
|
|
|
135
|
+ matrix:
|
|
|
136
|
+ job:
|
|
|
137
|
+ - { platform: "amd64", goos: "linux", docker_platform: "linux/amd64" }
|
|
|
138
|
+ - { platform: "arm64", goos: "linux", docker_platform: "linux/arm64" }
|
|
|
139
|
+ - { platform: "armv7l", goos: "linux", docker_platform: "linux/arm/v7" }
|
|
|
140
|
+ steps:
|
|
|
141
|
+ - name: Checkout code
|
|
|
142
|
+ uses: actions/checkout@v4
|
|
|
143
|
+
|
|
|
144
|
+ - name: Set up QEMU
|
|
|
145
|
+ uses: docker/setup-qemu-action@v2
|
|
|
146
|
+
|
|
|
147
|
+ - name: Set up Docker Buildx
|
|
|
148
|
+ uses: docker/setup-buildx-action@v2
|
|
|
149
|
+
|
|
|
150
|
+ - name: Log in to Docker Hub
|
|
|
151
|
+ if: ${{ env.SKIP_DOCKER_HUB == 'false' }} # Only log in if SKIP_DOCKER_HUB is false
|
|
|
152
|
+ uses: docker/login-action@v2
|
|
|
153
|
+ with:
|
|
|
154
|
+ username: ${{ secrets.DOCKER_USERNAME }}
|
|
|
155
|
+ password: ${{ secrets.DOCKER_ACCESS_TOKEN }}
|
|
|
156
|
+
|
|
|
157
|
+ - name: Log in to GitHub Container Registry
|
|
|
158
|
+ if: ${{ env.SKIP_GHCR == 'false' }} # Only log in if GHCR push is enabled
|
|
|
159
|
+ uses: docker/login-action@v2
|
|
|
160
|
+ with:
|
|
|
161
|
+ registry: ghcr.io
|
|
|
162
|
+ username: ${{ github.actor }}
|
|
|
163
|
+ password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
164
|
+
|
|
|
165
|
+ - name: Extract version from tag
|
|
|
166
|
+ id: vars
|
|
|
167
|
+ run: |
|
|
|
168
|
+ if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
|
|
|
169
|
+ echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
|
|
|
170
|
+ else
|
|
|
171
|
+ echo "TAG=test" >> $GITHUB_ENV # Default to 'test' if not a tag
|
|
|
172
|
+ fi
|
|
|
173
|
+
|
|
|
174
|
+ - name: Extract metadata (tags, labels) for Docker
|
|
|
175
|
+ id: meta
|
|
|
176
|
+ uses: docker/metadata-action@v4
|
|
|
177
|
+ with:
|
|
|
178
|
+ images: ${{ env.BASE_IMAGE_NAMESPACE }}/rustdesk-api
|
|
|
179
|
+
|
|
|
180
|
+ - name: Download binaries
|
|
|
181
|
+ uses: actions/download-artifact@v4
|
|
|
182
|
+ with:
|
|
|
183
|
+ name: rustdesk-api-${{ matrix.job.goos }}-${{ matrix.job.platform }}
|
|
|
184
|
+ path: ./
|
|
|
185
|
+
|
|
|
186
|
+ - name: Unzip binaries
|
|
|
187
|
+ run: |
|
|
|
188
|
+ mkdir -p ${{ matrix.job.platform }}
|
|
|
189
|
+ tar -xzf ${{ matrix.job.goos }}-${{ matrix.job.platform }}.tar.gz -C ${{ matrix.job.platform }}
|
|
|
190
|
+ file ${{ matrix.job.platform }}/apimain
|
|
|
191
|
+
|
|
|
192
|
+ - name: Build and push Docker image to Docker Hub ${{ matrix.job.platform }}
|
|
|
193
|
+ if: ${{ env.SKIP_DOCKER_HUB == 'false' }} # Only run this step if SKIP_DOCKER_HUB is false
|
|
|
194
|
+ uses: docker/build-push-action@v5
|
|
|
195
|
+ with:
|
|
|
196
|
+ context: "."
|
|
|
197
|
+ file: ./Dockerfile
|
|
|
198
|
+ platforms: ${{ matrix.job.docker_platform }}
|
|
|
199
|
+ push: true
|
|
|
200
|
+ provenance: false
|
|
|
201
|
+ build-args: |
|
|
|
202
|
+ BUILDARCH=${{ matrix.job.platform }}
|
|
|
203
|
+ tags: |
|
|
|
204
|
+ ${{ env.DOCKERHUB_IMAGE_NAMESPACE }}/rustdesk-api:${{ env.TAG }}-${{ matrix.job.platform }}
|
|
|
205
|
+ labels: ${{ steps.meta.outputs.labels }}
|
|
|
206
|
+
|
|
|
207
|
+ - name: Build and push Docker image to GHCR ${{ matrix.job.platform }}
|
|
|
208
|
+ if: ${{ env.SKIP_GHCR == 'false' }} # Only run this step if SKIP_GHCR is false
|
|
|
209
|
+ uses: docker/build-push-action@v5
|
|
|
210
|
+ with:
|
|
|
211
|
+ context: "."
|
|
|
212
|
+ file: ./Dockerfile
|
|
|
213
|
+ platforms: ${{ matrix.job.docker_platform }}
|
|
|
214
|
+ push: true
|
|
|
215
|
+ provenance: false
|
|
|
216
|
+ build-args: |
|
|
|
217
|
+ BUILDARCH=${{ matrix.job.platform }}
|
|
|
218
|
+ tags: |
|
|
|
219
|
+ ghcr.io/${{ env.GHCR_IMAGE_NAMESPACE }}/rustdesk-api:${{ env.TAG }}-${{ matrix.job.platform }}
|
|
|
220
|
+ labels: ${{ steps.meta.outputs.labels }}
|
|
|
221
|
+
|
|
|
222
|
+ #
|
|
|
223
|
+ docker-manifest:
|
|
|
224
|
+ name: Push Docker Manifest
|
|
|
225
|
+ needs: docker
|
|
|
226
|
+ runs-on: ubuntu-latest
|
|
|
227
|
+ steps:
|
|
|
228
|
+ - name: Extract version from tag
|
|
|
229
|
+ id: vars
|
|
|
230
|
+ run: |
|
|
|
231
|
+ if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
|
|
|
232
|
+ echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
|
|
|
233
|
+ else
|
|
|
234
|
+ echo "TAG=test" >> $GITHUB_ENV # Default to 'test' if not a tag
|
|
|
235
|
+ fi
|
|
|
236
|
+
|
|
|
237
|
+ - name: Log in to Docker Hub
|
|
|
238
|
+ if: ${{ env.SKIP_DOCKER_HUB == 'false' }} # Only log in if Docker Hub push is enabled
|
|
|
239
|
+ uses: docker/login-action@v2
|
|
|
240
|
+ with:
|
|
|
241
|
+ username: ${{ secrets.DOCKER_USERNAME }}
|
|
|
242
|
+ password: ${{ secrets.DOCKER_ACCESS_TOKEN }}
|
|
|
243
|
+
|
|
|
244
|
+ - name: Log in to GitHub Container Registry
|
|
|
245
|
+ if: ${{ env.SKIP_GHCR == 'false' }} # Only log in if GHCR push is enabled
|
|
|
246
|
+ uses: docker/login-action@v2
|
|
|
247
|
+ with:
|
|
|
248
|
+ registry: ghcr.io
|
|
|
249
|
+ username: ${{ github.actor }}
|
|
|
250
|
+ password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
251
|
+
|
|
|
252
|
+ - name: Create and push manifest Docker Hub (:version)
|
|
|
253
|
+ if: ${{ env.SKIP_DOCKER_HUB == 'false' }}
|
|
|
254
|
+ uses: Noelware/docker-manifest-action@master
|
|
|
255
|
+ with:
|
|
|
256
|
+ base-image: ${{ env.BASE_IMAGE_NAMESPACE }}/rustdesk-api:${{ env.TAG }}
|
|
|
257
|
+ extra-images: ${{ env.DOCKERHUB_IMAGE_NAMESPACE }}/rustdesk-api:${{ env.TAG }}-amd64,
|
|
|
258
|
+ ${{ env.DOCKERHUB_IMAGE_NAMESPACE }}/rustdesk-api:${{ env.TAG }}-armv7l,
|
|
|
259
|
+ ${{ env.DOCKERHUB_IMAGE_NAMESPACE }}/rustdesk-api:${{ env.TAG }}-arm64
|
|
|
260
|
+ push: true
|
|
|
261
|
+
|
|
|
262
|
+ - name: Create and push manifest GHCR (:version)
|
|
|
263
|
+ if: ${{ env.SKIP_GHCR == 'false' }}
|
|
|
264
|
+ uses: Noelware/docker-manifest-action@master
|
|
|
265
|
+ with:
|
|
|
266
|
+ base-image: ghcr.io/${{ env.BASE_IMAGE_NAMESPACE }}/rustdesk-api:${{ env.TAG }}
|
|
|
267
|
+ extra-images: ghcr.io/${{ env.GHCR_IMAGE_NAMESPACE }}/rustdesk-api:${{ env.TAG }}-amd64,
|
|
|
268
|
+ ghcr.io/${{ env.GHCR_IMAGE_NAMESPACE }}/rustdesk-api:${{ env.TAG }}-armv7l,
|
|
|
269
|
+ ghcr.io/${{ env.GHCR_IMAGE_NAMESPACE }}/rustdesk-api:${{ env.TAG }}-arm64
|
|
|
270
|
+ push: true
|
|
|
271
|
+ amend: true
|