ソースを参照

refactor: github workflows

Yeuoly 10 ヶ月 前
コミット
77c9dc47fc
共有1 個のファイルを変更した42 個の追加44 個の削除を含む
  1. 42 44
      .github/workflows/build-push.yml

+ 42 - 44
.github/workflows/build-push.yml

@@ -60,30 +60,36 @@ jobs:
           username: ${{ env.DOCKERHUB_USER }}
           password: ${{ env.DOCKERHUB_TOKEN }}
 
-      - name: Set up QEMU
-        uses: docker/setup-qemu-action@v3
-
-      - name: Set up Docker Buildx
-        uses: docker/setup-buildx-action@v3
-
-      - name: Build and push
-        uses: docker/build-push-action@v5
+      - name: Extract metadata (tags, labels) for Docker
+        id: meta
+        uses: docker/metadata-action@v5
         with:
-          context: .
-          file: ${{ matrix.dockerfile }}
-          platforms: ${{ matrix.platform }}
-          push: true
+          images: ${{ env.DIFY_DAEMON_IMAGE_NAME }}
           tags: |
-            ${{ env.DIFY_DAEMON_IMAGE_NAME }}:${{ matrix.scope }}-latest-${{ env.PLATFORM_PAIR }}
-            ${{ env.DIFY_DAEMON_IMAGE_NAME }}:${{ matrix.scope }}-${{ github.sha }}-${{ env.PLATFORM_PAIR }}
-            ${{ env.DIFY_DAEMON_IMAGE_NAME }}:${{ matrix.scope }}-${{ env.BRANCH_NAME }}-${{ env.PLATFORM_PAIR }}
-          cache-from: type=gha,scope=${{ matrix.service_name }}
-          cache-to: type=gha,mode=max,scope=${{ matrix.service_name }}
+            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: Run Build Docker Image
+        run: docker build -t dify-plugin-daemon -f ./docker/${{ matrix.scope }}/Dockerfile .
+
+      - name: Tag Docker Images
+        run:
+          for tag in $(echo "${{ steps.meta.outputs.tags }}" | tr ',' '\n');
+          do
+            docker tag dify-plugin-daemon "$tag-${{ matrix.scope }}-${{ env.PLATFORM_PAIR }}";
+          done
+      - name: Push Docker Image
+        run:
+          for tag in $(echo "${{ steps.meta.outputs.tags }}" | tr ',' '\n');
+          do
+            docker push $tag-${{ matrix.scope }}-${{ env.PLATFORM_PAIR }};
+          done
 
   create-manifest:
     needs: build
     runs-on: ubuntu-latest
-    if: github.repository == 'langgenius/dify-plugin-daemon'
     strategy:
       matrix:
         scope: [serverless, local]
@@ -91,35 +97,27 @@ jobs:
       - name: Checkout code
         uses: actions/checkout@v3
 
-      - name: Prepare
-        run: |
-          echo "BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/})" >> $GITHUB_ENV
-
       - name: Login to Docker Hub
         uses: docker/login-action@v2
         with:
           username: ${{ env.DOCKERHUB_USER }}
           password: ${{ env.DOCKERHUB_TOKEN }}
 
-      - name: Create and push manifest
-        run: |
-          docker manifest create ${{ env.DIFY_DAEMON_IMAGE_NAME }}:${{ matrix.scope }}-latest \
-            ${{ env.DIFY_DAEMON_IMAGE_NAME }}:${{ matrix.scope }}-latest-linux-amd64 \
-            ${{ env.DIFY_DAEMON_IMAGE_NAME }}:${{ matrix.scope }}-latest-linux-arm64
-          docker manifest push ${{ env.DIFY_DAEMON_IMAGE_NAME }}:${{ matrix.scope }}-latest
-
-          docker manifest create ${{ env.DIFY_DAEMON_IMAGE_NAME }}:${{ matrix.scope }}-${{ github.sha }} \
-            ${{ env.DIFY_DAEMON_IMAGE_NAME }}:${{ matrix.scope }}-${{ github.sha }}-linux-amd64 \
-            ${{ env.DIFY_DAEMON_IMAGE_NAME }}:${{ matrix.scope }}-${{ github.sha }}-linux-arm64
-          docker manifest push ${{ env.DIFY_DAEMON_IMAGE_NAME }}:${{ matrix.scope }}-${{ github.sha }}
-
-          docker manifest create ${{ env.DIFY_DAEMON_IMAGE_NAME }}:${{ matrix.scope }}-${{ env.BRANCH_NAME }} \
-            ${{ env.DIFY_DAEMON_IMAGE_NAME }}:${{ matrix.scope }}-${{ env.BRANCH_NAME }}-linux-amd64 \
-            ${{ env.DIFY_DAEMON_IMAGE_NAME }}:${{ matrix.scope }}-${{ env.BRANCH_NAME }}-linux-arm64
-          docker manifest push ${{ env.DIFY_DAEMON_IMAGE_NAME }}:${{ matrix.scope }}-${{ env.BRANCH_NAME }}
-
-      - name: Inspect images
-        run: |
-          docker buildx imagetools inspect ${{ env.DIFY_DAEMON_IMAGE_NAME }}:${{ matrix.scope }}-latest
-          docker buildx imagetools inspect ${{ env.DIFY_DAEMON_IMAGE_NAME }}:${{ matrix.scope }}-${{ github.sha }}
-          docker buildx imagetools inspect ${{ env.DIFY_DAEMON_IMAGE_NAME }}:${{ matrix.scope }}-${{ env.BRANCH_NAME }}
+      - name: Extract metadata (tags, labels) for Docker
+        id: meta
+        uses: docker/metadata-action@v5
+        with:
+          images: ${{ vars.DIFY_DAEMON_IMAGE_NAME || 'langgenius/dify-plugin-daemon' }}
+          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 Images
+        run:
+          for tag in $(echo "${{ steps.meta.outputs.tags }}" | tr ',' '\n');
+          do
+            docker manifest create $tag-${{ matrix.scope }} $tag-${{ matrix.scope }}-linux-amd64 $tag-${{ matrix.scope }}-linux-arm64;
+            docker manifest push $tag-${{ matrix.scope }};
+          done