You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

build-push.yml 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. name: Build and Push API & Web
  2. on:
  3. push:
  4. branches:
  5. - "main"
  6. - "deploy/dev"
  7. - "deploy/enterprise"
  8. - "build/**"
  9. - "release/e-*"
  10. tags:
  11. - "*"
  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_WEB_IMAGE_NAME: ${{ vars.DIFY_WEB_IMAGE_NAME || 'langgenius/dify-web' }}
  19. DIFY_API_IMAGE_NAME: ${{ vars.DIFY_API_IMAGE_NAME || 'langgenius/dify-api' }}
  20. jobs:
  21. build:
  22. runs-on: ${{ matrix.platform == 'linux/arm64' && 'arm64_runner' || 'ubuntu-latest' }}
  23. if: github.repository == 'langgenius/dify'
  24. strategy:
  25. matrix:
  26. include:
  27. - service_name: "build-api-amd64"
  28. image_name_env: "DIFY_API_IMAGE_NAME"
  29. context: "api"
  30. platform: linux/amd64
  31. - service_name: "build-api-arm64"
  32. image_name_env: "DIFY_API_IMAGE_NAME"
  33. context: "api"
  34. platform: linux/arm64
  35. - service_name: "build-web-amd64"
  36. image_name_env: "DIFY_WEB_IMAGE_NAME"
  37. context: "web"
  38. platform: linux/amd64
  39. - service_name: "build-web-arm64"
  40. image_name_env: "DIFY_WEB_IMAGE_NAME"
  41. context: "web"
  42. platform: linux/arm64
  43. steps:
  44. - name: Prepare
  45. run: |
  46. platform=${{ matrix.platform }}
  47. echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
  48. - name: Login to Docker Hub
  49. uses: docker/login-action@v3
  50. with:
  51. username: ${{ env.DOCKERHUB_USER }}
  52. password: ${{ env.DOCKERHUB_TOKEN }}
  53. - name: Set up QEMU
  54. uses: docker/setup-qemu-action@v3
  55. - name: Set up Docker Buildx
  56. uses: docker/setup-buildx-action@v3
  57. - name: Extract metadata for Docker
  58. id: meta
  59. uses: docker/metadata-action@v5
  60. with:
  61. images: ${{ env[matrix.image_name_env] }}
  62. - name: Build Docker image
  63. id: build
  64. uses: docker/build-push-action@v6
  65. with:
  66. context: "{{defaultContext}}:${{ matrix.context }}"
  67. platforms: ${{ matrix.platform }}
  68. build-args: COMMIT_SHA=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }}
  69. labels: ${{ steps.meta.outputs.labels }}
  70. outputs: type=image,name=${{ env[matrix.image_name_env] }},push-by-digest=true,name-canonical=true,push=true
  71. cache-from: type=gha,scope=${{ matrix.service_name }}
  72. cache-to: type=gha,mode=max,scope=${{ matrix.service_name }}
  73. - name: Export digest
  74. env:
  75. DIGEST: ${{ steps.build.outputs.digest }}
  76. run: |
  77. mkdir -p /tmp/digests
  78. sanitized_digest=${DIGEST#sha256:}
  79. touch "/tmp/digests/${sanitized_digest}"
  80. - name: Upload digest
  81. uses: actions/upload-artifact@v4
  82. with:
  83. name: digests-${{ matrix.context }}-${{ env.PLATFORM_PAIR }}
  84. path: /tmp/digests/*
  85. if-no-files-found: error
  86. retention-days: 1
  87. create-manifest:
  88. needs: build
  89. runs-on: ubuntu-latest
  90. if: github.repository == 'langgenius/dify'
  91. strategy:
  92. matrix:
  93. include:
  94. - service_name: "merge-api-images"
  95. image_name_env: "DIFY_API_IMAGE_NAME"
  96. context: "api"
  97. - service_name: "merge-web-images"
  98. image_name_env: "DIFY_WEB_IMAGE_NAME"
  99. context: "web"
  100. steps:
  101. - name: Download digests
  102. uses: actions/download-artifact@v4
  103. with:
  104. path: /tmp/digests
  105. pattern: digests-${{ matrix.context }}-*
  106. merge-multiple: true
  107. - name: Login to Docker Hub
  108. uses: docker/login-action@v3
  109. with:
  110. username: ${{ env.DOCKERHUB_USER }}
  111. password: ${{ env.DOCKERHUB_TOKEN }}
  112. - name: Extract metadata for Docker
  113. id: meta
  114. uses: docker/metadata-action@v5
  115. with:
  116. images: ${{ env[matrix.image_name_env] }}
  117. tags: |
  118. type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/') && !contains(github.ref, '-') }}
  119. type=ref,event=branch
  120. type=sha,enable=true,priority=100,prefix=,suffix=,format=long
  121. type=raw,value=${{ github.ref_name }},enable=${{ startsWith(github.ref, 'refs/tags/') }}
  122. - name: Create manifest list and push
  123. working-directory: /tmp/digests
  124. env:
  125. IMAGE_NAME: ${{ env[matrix.image_name_env] }}
  126. run: |
  127. docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
  128. $(printf "$IMAGE_NAME@sha256:%s " *)
  129. - name: Inspect image
  130. env:
  131. IMAGE_NAME: ${{ env[matrix.image_name_env] }}
  132. IMAGE_VERSION: ${{ steps.meta.outputs.version }}
  133. run: |
  134. docker buildx imagetools inspect "$IMAGE_NAME:$IMAGE_VERSION"