build-push.yml 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. dockerfile: "docker/serverless/Dockerfile"
  27. scope: serverless
  28. - service_name: "build-serverless-daemon-arm64"
  29. image_name_env: "DIFY_DAEMON_IMAGE_NAME"
  30. platform: linux/arm64
  31. dockerfile: "docker/serverless/Dockerfile"
  32. scope: serverless
  33. - service_name: "build-local-daemon-amd64"
  34. image_name_env: "DIFY_DAEMON_IMAGE_NAME"
  35. platform: linux/amd64
  36. dockerfile: "docker/local/Dockerfile"
  37. scope: local
  38. - service_name: "build-local-daemon-arm64"
  39. image_name_env: "DIFY_DAEMON_IMAGE_NAME"
  40. platform: linux/arm64
  41. dockerfile: "docker/local/Dockerfile"
  42. scope: local
  43. steps:
  44. - name: Checkout code
  45. uses: actions/checkout@v3
  46. - name: Prepare
  47. run: |
  48. platform=${{ matrix.platform }}
  49. echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
  50. echo "BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/})" >> $GITHUB_ENV
  51. - name: Login to Docker Hub
  52. uses: docker/login-action@v2
  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 -t dify-plugin-daemon -f ./docker/${{ matrix.scope }}/Dockerfile .
  68. - name: Tag Docker Images
  69. run:
  70. for tag in $(echo "${{ steps.meta.outputs.tags }}" | tr ',' '\n');
  71. do
  72. docker tag dify-plugin-daemon "$tag-${{ matrix.scope }}-${{ env.PLATFORM_PAIR }}";
  73. done
  74. - name: Push Docker Image
  75. run:
  76. for tag in $(echo "${{ steps.meta.outputs.tags }}" | tr ',' '\n');
  77. do
  78. docker push $tag-${{ matrix.scope }}-${{ env.PLATFORM_PAIR }};
  79. done
  80. create-manifest:
  81. needs: build
  82. runs-on: ubuntu-latest
  83. strategy:
  84. matrix:
  85. scope: [serverless, local]
  86. steps:
  87. - name: Checkout code
  88. uses: actions/checkout@v3
  89. - name: Login to Docker Hub
  90. uses: docker/login-action@v2
  91. with:
  92. username: ${{ env.DOCKERHUB_USER }}
  93. password: ${{ env.DOCKERHUB_TOKEN }}
  94. - name: Extract metadata (tags, labels) for Docker
  95. id: meta
  96. uses: docker/metadata-action@v5
  97. with:
  98. images: ${{ vars.DIFY_DAEMON_IMAGE_NAME || 'langgenius/dify-plugin-daemon' }}
  99. tags: |
  100. type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/') }}
  101. type=ref,event=branch
  102. type=sha,enable=true,priority=100,prefix=,suffix=,format=long
  103. type=raw,value=${{ github.ref_name }},enable=${{ startsWith(github.ref, 'refs/tags/') }}
  104. - name: Build Universal Docker Images
  105. run:
  106. for tag in $(echo "${{ steps.meta.outputs.tags }}" | tr ',' '\n');
  107. do
  108. docker manifest create $tag-${{ matrix.scope }} $tag-${{ matrix.scope }}-linux-amd64 $tag-${{ matrix.scope }}-linux-arm64;
  109. docker manifest push $tag-${{ matrix.scope }};
  110. done