Просмотр исходного кода

Merge pull request #5 from gigaion/new-build-1

build.yml - Add GHCR & Dynamic Inputs
1 год назад
Родитель
Сommit
857abc16e7
1 измененных файлов с 114 добавлено и 14 удалено
  1. 114 14
      .github/workflows/build.yml

+ 114 - 14
.github/workflows/build.yml

@@ -2,6 +2,31 @@ name: Build
2
 
2
 
3
 on:
3
 on:
4
   workflow_dispatch:
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'
5
   push:
30
   push:
6
     tags:
31
     tags:
7
       - 'v*.*.*'  # 当推送带有版本号的 tag(例如 v1.0.0)时触发工作流
32
       - 'v*.*.*'  # 当推送带有版本号的 tag(例如 v1.0.0)时触发工作流
@@ -9,6 +34,12 @@ on:
9
 
34
 
10
 env:
35
 env:
11
   LATEST_TAG: latest
36
   LATEST_TAG: latest
37
+  WEBCLIENT_SOURCE_LOCATION: ${{ github.event.inputs.WEBCLIENT_SOURCE_LOCATION }}
38
+  BASE_IMAGE_NAMESPACE: ${{ github.event.inputs.BASE_IMAGE_NAMESPACE || github.actor }}
39
+  DOCKERHUB_IMAGE_NAMESPACE: ${{ github.event.inputs.DOCKERHUB_IMAGE_NAMESPACE || github.actor }}
40
+  GHCR_IMAGE_NAMESPACE: ${{ github.event.inputs.GHCR_IMAGE_NAMESPACE || github.actor }}
41
+  SKIP_DOCKER_HUB: ${{ github.event.inputs.SKIP_DOCKER_HUB }}
42
+  SKIP_GHCR: ${{ github.event.inputs.SKIP_GHCR }}
12
 jobs:
43
 jobs:
13
   build:
44
   build:
14
     runs-on: ubuntu-latest
45
     runs-on: ubuntu-latest
@@ -38,7 +69,7 @@ jobs:
38
 
69
 
39
       - name: build rustdesk-api-web
70
       - name: build rustdesk-api-web
40
         run: |
71
         run: |
41
-          git clone https://github.com/lejianwen/rustdesk-api-web
72
+          git clone ${{ env.WEBCLIENT_SOURCE_LOCATION }}
42
           cd rustdesk-api-web
73
           cd rustdesk-api-web
43
           npm install
74
           npm install
44
           npm run build
75
           npm run build
@@ -86,13 +117,13 @@ jobs:
86
           path: |
117
           path: |
87
             ${{ matrix.job.goos}}-${{ matrix.job.platform }}.tar.gz
118
             ${{ matrix.job.goos}}-${{ matrix.job.platform }}.tar.gz
88
             ${{ matrix.job.goos}}-${{ matrix.job.platform }}.zip
119
             ${{ matrix.job.goos}}-${{ matrix.job.platform }}.zip
89
-
90
       - name: Upload to GitHub Release
120
       - name: Upload to GitHub Release
91
         uses: softprops/action-gh-release@v2
121
         uses: softprops/action-gh-release@v2
92
         with:
122
         with:
93
           files: |
123
           files: |
94
             ${{ matrix.job.goos}}-${{ matrix.job.platform }}.tar.gz
124
             ${{ matrix.job.goos}}-${{ matrix.job.platform }}.tar.gz
95
             ${{ matrix.job.goos}}-${{ matrix.job.platform }}.zip
125
             ${{ matrix.job.goos}}-${{ matrix.job.platform }}.zip
126
+          tag_name: ${{ env.LATEST_TAG }}
96
         env:
127
         env:
97
           GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
128
           GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
98
 
129
 
@@ -117,20 +148,34 @@ jobs:
117
         uses: docker/setup-buildx-action@v2
148
         uses: docker/setup-buildx-action@v2
118
 
149
 
119
       - name: Log in to Docker Hub
150
       - name: Log in to Docker Hub
151
+        if: ${{ env.SKIP_DOCKER_HUB == 'false' }}  # Only log in if SKIP_DOCKER_HUB is false
120
         uses: docker/login-action@v2
152
         uses: docker/login-action@v2
121
         with:
153
         with:
122
           username: ${{ secrets.DOCKER_USERNAME }}
154
           username: ${{ secrets.DOCKER_USERNAME }}
123
           password: ${{ secrets.DOCKER_ACCESS_TOKEN }}
155
           password: ${{ secrets.DOCKER_ACCESS_TOKEN }}
124
 
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
+
125
       - name: Extract version from tag
165
       - name: Extract version from tag
126
         id: vars
166
         id: vars
127
-        run: echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
167
+        run: |
168
+          if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
169
+            echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
170
+          else
171
+            echo "TAG=latest" >> $GITHUB_ENV  # Default to 'latest' if not a tag
172
+          fi
128
 
173
 
129
       - name: Extract metadata (tags, labels) for Docker
174
       - name: Extract metadata (tags, labels) for Docker
130
         id: meta
175
         id: meta
131
         uses: docker/metadata-action@v4
176
         uses: docker/metadata-action@v4
132
         with:
177
         with:
133
-          images: lejianwen/rustdesk-api
178
+          images: ${{ env.BASE_IMAGE_NAMESPACE }}/rustdesk-api
134
 
179
 
135
       - name: Download binaries
180
       - name: Download binaries
136
         uses: actions/download-artifact@v4
181
         uses: actions/download-artifact@v4
@@ -144,7 +189,8 @@ jobs:
144
           tar -xzf ${{ matrix.job.goos }}-${{ matrix.job.platform }}.tar.gz -C ${{ matrix.job.platform }}
189
           tar -xzf ${{ matrix.job.goos }}-${{ matrix.job.platform }}.tar.gz -C ${{ matrix.job.platform }}
145
           file ${{ matrix.job.platform }}/apimain
190
           file ${{ matrix.job.platform }}/apimain
146
 
191
 
147
-      - name: Build and push Docker image ${{ matrix.job.platform }}
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
148
         uses: docker/build-push-action@v5
194
         uses: docker/build-push-action@v5
149
         with:
195
         with:
150
           context: "."
196
           context: "."
@@ -155,8 +201,24 @@ jobs:
155
           build-args: |
201
           build-args: |
156
             BUILDARCH=${{ matrix.job.platform }}
202
             BUILDARCH=${{ matrix.job.platform }}
157
           tags: |
203
           tags: |
158
-            lejianwen/rustdesk-api:${{ env.LATEST_TAG }}-${{ matrix.job.platform }}
159
-            lejianwen/rustdesk-api:${{ env.TAG }}-${{ matrix.job.platform }}
204
+            ${{ env.DOCKERHUB_IMAGE_NAMESPACE }}/rustdesk-api:${{ env.LATEST_TAG }}-${{ matrix.job.platform }},
205
+            ${{ env.DOCKERHUB_IMAGE_NAMESPACE }}/rustdesk-api:${{ env.TAG }}-${{ matrix.job.platform }}
206
+          labels: ${{ steps.meta.outputs.labels }}
207
+
208
+      - name: Build and push Docker image to GHCR ${{ matrix.job.platform }}
209
+        if: ${{ env.SKIP_GHCR == 'false' }}  # Only run this step if SKIP_GHCR is false
210
+        uses: docker/build-push-action@v5
211
+        with:
212
+          context: "."
213
+          file: ./Dockerfile
214
+          platforms: ${{ matrix.job.docker_platform }}
215
+          push: true
216
+          provenance: false
217
+          build-args: |
218
+            BUILDARCH=${{ matrix.job.platform }}
219
+          tags: |
220
+            ghcr.io/${{ env.GHCR_IMAGE_NAMESPACE }}/rustdesk-api:${{ env.LATEST_TAG }}-${{ matrix.job.platform }},
221
+            ghcr.io/${{ env.GHCR_IMAGE_NAMESPACE }}/rustdesk-api:${{ env.TAG }}-${{ matrix.job.platform }}
160
           labels: ${{ steps.meta.outputs.labels }}
222
           labels: ${{ steps.meta.outputs.labels }}
161
 
223
 
162
   #
224
   #
@@ -167,24 +229,62 @@ jobs:
167
     steps:
229
     steps:
168
       - name: Extract version from tag
230
       - name: Extract version from tag
169
         id: vars
231
         id: vars
170
-        run: echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
232
+        run: |
233
+          if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
234
+            echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
235
+          else
236
+            echo "TAG=latest" >> $GITHUB_ENV  # Default to 'latest' if not a tag
237
+          fi
171
 
238
 
172
       - name: Log in to Docker Hub
239
       - name: Log in to Docker Hub
240
+        if: ${{ env.SKIP_DOCKER_HUB == 'false' }}  # Only log in if Docker Hub push is enabled
173
         uses: docker/login-action@v2
241
         uses: docker/login-action@v2
174
         with:
242
         with:
175
           username: ${{ secrets.DOCKER_USERNAME }}
243
           username: ${{ secrets.DOCKER_USERNAME }}
176
           password: ${{ secrets.DOCKER_ACCESS_TOKEN }}
244
           password: ${{ secrets.DOCKER_ACCESS_TOKEN }}
177
 
245
 
178
-      - name: Create and push manifest (:version)
246
+      - name: Log in to GitHub Container Registry
247
+        if: ${{ env.SKIP_GHCR == 'false' }}  # Only log in if GHCR push is enabled
248
+        uses: docker/login-action@v2
249
+        with:
250
+          registry: ghcr.io
251
+          username: ${{ github.actor }}
252
+          password: ${{ secrets.GITHUB_TOKEN }}
253
+
254
+      - name: Create and push manifest Docker Hub (:version)
255
+        if: ${{ env.SKIP_DOCKER_HUB == 'false' }}
256
+        uses: Noelware/docker-manifest-action@master
257
+        with:
258
+          base-image: ${{ env.BASE_IMAGE_NAMESPACE }}/rustdesk-api:${{ env.TAG }}
259
+          extra-images: ${{ env.DOCKERHUB_IMAGE_NAMESPACE }}/rustdesk-api:${{ env.TAG }}-amd64, 
260
+                        ${{ env.DOCKERHUB_IMAGE_NAMESPACE }}/rustdesk-api:${{ env.TAG }}-arm64
261
+          push: true
262
+
263
+      - name: Create and push manifest GHCR (:version)
264
+        if: ${{ env.SKIP_GHCR == 'false' }}
265
+        uses: Noelware/docker-manifest-action@master
266
+        with:
267
+          base-image: ghcr.io/${{ env.BASE_IMAGE_NAMESPACE }}/rustdesk-api:${{ env.TAG }}
268
+          extra-images: ghcr.io/${{ env.GHCR_IMAGE_NAMESPACE }}/rustdesk-api:${{ env.TAG }}-amd64, 
269
+                        ghcr.io/${{ env.GHCR_IMAGE_NAMESPACE }}/rustdesk-api:${{ env.TAG }}-arm64
270
+          push: true
271
+          amend: true
272
+
273
+      - name: Create and push manifest Docker Hub (:latest)
274
+        if: ${{ env.SKIP_DOCKER_HUB == 'false' }}
179
         uses: Noelware/docker-manifest-action@master
275
         uses: Noelware/docker-manifest-action@master
180
         with:
276
         with:
181
-          base-image: lejianwen/rustdesk-api:${{ env.TAG }}
182
-          extra-images: lejianwen/rustdesk-api:${{ env.TAG }}-amd64,lejianwen/rustdesk-api:${{ env.TAG }}-arm64
277
+          base-image: ${{ env.BASE_IMAGE_NAMESPACE }}/rustdesk-api:latest
278
+          extra-images: ${{ env.DOCKERHUB_IMAGE_NAMESPACE }}/rustdesk-api:latest-amd64, 
279
+                        ${{ env.DOCKERHUB_IMAGE_NAMESPACE }}/rustdesk-api:latest-arm64
183
           push: true
280
           push: true
184
 
281
 
185
-      - name: Create and push manifest (:latest)
282
+      - name: Create and push manifest GHCR (:latest)
283
+        if: ${{ env.SKIP_GHCR == 'false' }}
186
         uses: Noelware/docker-manifest-action@master
284
         uses: Noelware/docker-manifest-action@master
187
         with:
285
         with:
188
-          base-image: lejianwen/rustdesk-api:latest
189
-          extra-images: lejianwen/rustdesk-api:latest-amd64,lejianwen/rustdesk-api:latest-arm64
286
+          base-image: ghcr.io/${{ env.BASE_IMAGE_NAMESPACE }}/rustdesk-api:latest
287
+          extra-images: ghcr.io/${{ env.GHCR_IMAGE_NAMESPACE }}/rustdesk-api:latest-amd64, 
288
+                        ghcr.io/${{ env.GHCR_IMAGE_NAMESPACE }}/rustdesk-api:latest-arm64
190
           push: true
289
           push: true
290
+          amend: true