Explorar o código

Merge pull request #3 from langgenius/feat/0.2.2

Feat/0.2.2
Yeuoly hai 1 ano
pai
achega
799ab11102

+ 0 - 0
.github/workflows/build-arm64.yml


+ 59 - 0
.github/workflows/build-universal.yml

@@ -0,0 +1,59 @@
+name: Build And Push Universal
+
+on:
+  push:
+    branches:
+      - main
+  release:
+    types: [published]
+
+jobs:
+  build-amd64:
+    uses: ./.github/workflows/build.yml
+    with:
+      runner: ubuntu-latest
+      arch: amd64
+      arch_label: AMD64
+    secrets:
+      DOCKERHUB_USER: ${{ secrets.DOCKERHUB_USER }}
+      DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
+
+  build-arm64:
+    uses: ./.github/workflows/build.yml
+    with:
+      runner: arm64_runner
+      arch: arm64
+      arch_label: ARM64
+    secrets:
+      DOCKERHUB_USER: ${{ secrets.DOCKERHUB_USER }}
+      DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
+
+  build-universal:
+    needs: [build-amd64, build-arm64]
+    runs-on: ubuntu-latest
+    steps:
+      - name: Checkout code
+        uses: actions/checkout@v4
+
+      - name: Login to Docker Hub
+        uses: docker/login-action@v2
+        with:
+          username: ${{ secrets.DOCKERHUB_USER }}
+          password: ${{ secrets.DOCKERHUB_TOKEN }}
+
+      - name: Extract metadata (tags, labels) for Docker
+        id: meta
+        uses: docker/metadata-action@v5
+        with:
+          images: ${{ vars.DIFY_SANDBOX_IMAGE_NAME || 'langgenius/dify-sandbox' }}
+          tags: |
+            type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/') }}
+            type=ref,event=branch
+            type=sha,enable=true,priority=100,prefix=,suffix=,format=long
+            type=raw,value=${{ github.ref_name }},enable=${{ startsWith(github.ref, 'refs/tags/') }}
+
+      - name: Build Universal Docker Image
+        run: docker manifest create ${{ steps.meta.outputs.tags }} ${{ steps.meta.outputs.tags }}-amd64 ${{ steps.meta.outputs.tags }}-arm64
+      
+      - name: Push Universal Docker Image
+        run: docker manifest push ${{ steps.meta.outputs.tags }}

+ 26 - 20
.github/workflows/build-amd64.yml

@@ -1,21 +1,27 @@
-name: Build AMD64
+name: Universal Build
 
 on:
-  push:
-    branches:
-      - main
-  release:
-    types: [published]
-
-env:
-  DOCKERHUB_USER: ${{ secrets.DOCKERHUB_USER }}
-  DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
-  DIFY_SANDBOX_IMAGE_NAME: ${{ vars.DIFY_SANDBOX_IMAGE_NAME || 'langgenius/dify-sandbox' }}
+  workflow_call:
+    inputs:
+      runner:
+        required: true
+        type: string
+      arch:
+        required: true
+        type: string
+      arch_label:
+        required: true
+        type: string
+    secrets:
+      DOCKERHUB_USER:
+        required: true
+      DOCKERHUB_TOKEN:
+        required: true
 
 jobs:
-  build_amd64:
-    name: Build AMD64
-    runs-on: ubuntu-latest
+  build:
+    name: Build ${{ inputs.arch_label }}
+    runs-on: ${{ inputs.runner }}
 
     steps:
       - name: Checkout code
@@ -24,14 +30,14 @@ jobs:
       - name: Login to Docker Hub
         uses: docker/login-action@v2
         with:
-          username: ${{ env.DOCKERHUB_USER }}
-          password: ${{ env.DOCKERHUB_TOKEN }}
+          username: ${{ secrets.DOCKERHUB_USER }}
+          password: ${{ secrets.DOCKERHUB_TOKEN }}
 
       - name: Extract metadata (tags, labels) for Docker
         id: meta
         uses: docker/metadata-action@v5
         with:
-          images: ${{ env.DIFY_SANDBOX_IMAGE_NAME }}
+          images: ${{ vars.DIFY_SANDBOX_IMAGE_NAME || 'langgenius/dify-sandbox' }}
           tags: |
             type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/') }}
             type=ref,event=branch
@@ -50,10 +56,10 @@ jobs:
         run: go mod tidy
 
       - name: Run Build Binary
-        run: bash ./build/build_amd64.sh 
+        run: bash ./build/build_${{ inputs.arch }}.sh
 
       - name: Run Build Docker Image
-        run: docker build -t ${{ env.DIFY_SANDBOX_IMAGE_NAME }}:${{ steps.meta.outputs.tag }}-amd64 -f ./docker/amd64/dockerfile .
+        run: docker build -t ${{ steps.meta.outputs.tags }}-${{ inputs.arch }} -f ./docker/${{ inputs.arch }}/dockerfile .
 
       - name: Run Push Docker Image
-        run: docker push ${{ env.DIFY_SANDBOX_IMAGE_NAME }}:${{ steps.meta.outputs.tag }}
+        run: docker push ${{ steps.meta.outputs.tags }}-${{ inputs.arch }}