build-push.yml 4.1 KB

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