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

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