ljw 1 год назад
Родитель
Сommit
c58f08af27
2 измененных файлов с 271 добавлено и 95 удалено
  1. 271 0
      .github/workflows/build_test.yml
  2. 0 95
      .github/workflows/release.yml

+ 271 - 0
.github/workflows/build_test.yml

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

+ 0 - 95
.github/workflows/release.yml

@@ -1,95 +0,0 @@
1
-name: Build and Release
2
-
3
-on:
4
-  workflow_dispatch:
5
-#    tags:
6
-#      - 'v*.*.*'  # 当推送带有版本号的 tag(例如 v1.0.0)时触发工作流
7
-#on:
8
-#  push:
9
-#    branches: [ "master" ]
10
-#  pull_request:
11
-#    branches: [ "master" ]
12
-
13
-jobs:
14
-  build:
15
-    runs-on: ubuntu-latest
16
-
17
-    strategy:
18
-      matrix:
19
-        goos: [ linux, windows ] # 指定要构建的操作系统
20
-        goarch: [ amd64 ]         # 指定架构
21
-
22
-    steps:
23
-      - name: Checkout code
24
-        uses: actions/checkout@v4
25
-
26
-      - name: Set up Go environment
27
-        uses: actions/setup-go@v4
28
-        with:
29
-          go-version: '1.22'  # 选择 Go 版本
30
-
31
-      - name: Set up npm
32
-        uses: actions/setup-node@v2
33
-        with:
34
-          node-version: '20'
35
-
36
-      - name: install gcc zip musl
37
-        run: |
38
-          if [ "${{ matrix.goos }}" = "windows" ]; then
39
-            sudo apt-get install gcc-mingw-w64-x86-64 zip -y
40
-          else
41
-            sudo apt-get install musl musl-dev musl-tools -y
42
-          fi
43
-
44
-
45
-      - name: build rustdesk-api-web
46
-        run: |
47
-          git clone https://github.com/lejianwen/rustdesk-api-web
48
-          cd rustdesk-api-web
49
-          npm install
50
-          npm run build
51
-          mkdir ../resources/admin/ -p
52
-          cp -ar dist/* ../resources/admin/
53
-
54
-      - name: tidy
55
-        run: go mod tidy
56
-
57
-
58
-      - name: swag
59
-        run: |
60
-          go install github.com/swaggo/swag/cmd/swag@latest
61
-          swag init -g cmd/apimain.go --output docs/api --instanceName api --exclude http/controller/admin
62
-          swag init -g cmd/apimain.go --output docs/admin --instanceName admin --exclude http/controller/api
63
-
64
-      - name: Build for ${{ matrix.goos }}-${{ matrix.goarch }}
65
-        run: |
66
-          mkdir release -p
67
-          cp -ar resources release/
68
-          cp -ar docs release/
69
-          cp -ar conf release/
70
-          mkdir -p release/data
71
-          mkdir -p release/runtime
72
-          if [ "${{ matrix.goos }}" = "windows" ]; then
73
-            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
74
-            zip -r ${{ matrix.goos}}-${{ matrix.goarch }}.zip ./release
75
-          else
76
-            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
77
-            tar -czf ${{ matrix.goos}}-${{ matrix.goarch }}.tar.gz ./release 
78
-          fi
79
-
80
-      - name: Upload artifact
81
-        uses: actions/upload-artifact@v4
82
-        with:
83
-          name: myapp-${{ matrix.goos }}-${{ matrix.goarch }}
84
-          path: |
85
-            ${{ matrix.goos}}-${{ matrix.goarch }}.tar.gz
86
-            ${{ matrix.goos}}-${{ matrix.goarch }}.zip
87
-
88
-      - name: Upload to GitHub Release
89
-        uses: softprops/action-gh-release@v2
90
-        with:
91
-          files: |
92
-            ${{ matrix.goos}}-${{ matrix.goarch }}.tar.gz
93
-            ${{ matrix.goos}}-${{ matrix.goarch }}.zip
94
-        env:
95
-          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}