build-push.yml 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. name: Build and Push Daemon
  2. on:
  3. push:
  4. branches:
  5. - "main"
  6. - "deploy/dev"
  7. pull_request:
  8. branches:
  9. - "main"
  10. release:
  11. types: [published]
  12. concurrency:
  13. group: build-push-${{ github.head_ref || github.run_id }}
  14. cancel-in-progress: true
  15. env:
  16. DOCKERHUB_USER: ${{ secrets.DOCKERHUB_USER }}
  17. DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
  18. DIFY_DAEMON_IMAGE_NAME: ${{ vars.DIFY_DAEMON_IMAGE_NAME || 'langgenius/dify-plugin-daemon' }}
  19. jobs:
  20. build:
  21. runs-on: ${{ matrix.platform == 'linux/arm64' && 'arm64_runner' || 'ubuntu-latest' }}
  22. if: github.repository == 'langgenius/dify-plugin-daemon'
  23. strategy:
  24. matrix:
  25. include:
  26. - service_name: "build-serverless-daemon-amd64"
  27. image_name_env: "DIFY_DAEMON_IMAGE_NAME"
  28. platform: linux/amd64
  29. scope: serverless
  30. - service_name: "build-serverless-daemon-arm64"
  31. image_name_env: "DIFY_DAEMON_IMAGE_NAME"
  32. platform: linux/arm64
  33. scope: serverless
  34. - service_name: "build-local-daemon-amd64"
  35. image_name_env: "DIFY_DAEMON_IMAGE_NAME"
  36. platform: linux/amd64
  37. scope: local
  38. - service_name: "build-local-daemon-arm64"
  39. image_name_env: "DIFY_DAEMON_IMAGE_NAME"
  40. platform: linux/arm64
  41. scope: local
  42. steps:
  43. - name: Checkout code
  44. uses: actions/checkout@v3
  45. - name: Prepare
  46. run: |
  47. platform=${{ matrix.platform }}
  48. echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
  49. echo "BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/})" >> $GITHUB_ENV
  50. - name: Login to Docker Hub
  51. uses: docker/login-action@v2
  52. if: github.event_name != 'pull_request'
  53. with:
  54. username: ${{ env.DOCKERHUB_USER }}
  55. password: ${{ env.DOCKERHUB_TOKEN }}
  56. - name: Extract metadata (tags, labels) for Docker
  57. id: meta
  58. uses: docker/metadata-action@v5
  59. with:
  60. images: ${{ env.DIFY_DAEMON_IMAGE_NAME }}
  61. tags: |
  62. type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/') }}
  63. type=ref,event=branch
  64. type=sha,enable=true,priority=100,prefix=,suffix=,format=long
  65. type=raw,value=${{ github.ref_name }},enable=${{ startsWith(github.ref, 'refs/tags/') }}
  66. - name: Run Build Docker Image
  67. run: docker build --build-arg PLATFORM=${{ matrix.scope }} --build-arg VERSION=${{ github.sha }} -t dify-plugin-daemon -f ./docker/${{ matrix.scope }}.dockerfile .
  68. - name: Tag Docker Images
  69. if: github.event_name != 'pull_request'
  70. run:
  71. for tag in $(echo "${{ steps.meta.outputs.tags }}" | tr ',' '\n');
  72. do
  73. docker tag dify-plugin-daemon "$tag-${{ matrix.scope }}-${{ env.PLATFORM_PAIR }}";
  74. done
  75. - name: Push Docker Image
  76. if: github.event_name != 'pull_request'
  77. run:
  78. for tag in $(echo "${{ steps.meta.outputs.tags }}" | tr ',' '\n');
  79. do
  80. docker push $tag-${{ matrix.scope }}-${{ env.PLATFORM_PAIR }};
  81. done
  82. create-manifest:
  83. if: github.event_name != 'pull_request'
  84. needs: build
  85. runs-on: ubuntu-latest
  86. strategy:
  87. matrix:
  88. scope: [serverless, local]
  89. steps:
  90. - name: Checkout code
  91. uses: actions/checkout@v3
  92. - name: Login to Docker Hub
  93. uses: docker/login-action@v2
  94. with:
  95. username: ${{ env.DOCKERHUB_USER }}
  96. password: ${{ env.DOCKERHUB_TOKEN }}
  97. - name: Extract metadata (tags, labels) for Docker
  98. id: meta
  99. uses: docker/metadata-action@v5
  100. with:
  101. images: ${{ vars.DIFY_DAEMON_IMAGE_NAME || 'langgenius/dify-plugin-daemon' }}
  102. tags: |
  103. type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/') }}
  104. type=ref,event=branch
  105. type=sha,enable=true,priority=100,prefix=,suffix=,format=long
  106. type=raw,value=${{ github.ref_name }},enable=${{ startsWith(github.ref, 'refs/tags/') }}
  107. - name: Build Universal Docker Images
  108. run:
  109. for tag in $(echo "${{ steps.meta.outputs.tags }}" | tr ',' '\n');
  110. do
  111. docker manifest create $tag-${{ matrix.scope }} $tag-${{ matrix.scope }}-linux-amd64 $tag-${{ matrix.scope }}-linux-arm64;
  112. docker manifest push $tag-${{ matrix.scope }};
  113. done