docker.yml 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. name: Build and Push Docker Images
  2. on:
  3. push:
  4. tags:
  5. - "v*" # 主项目版本
  6. - "mcp-v*" # MCP 版本
  7. workflow_dispatch:
  8. inputs:
  9. image:
  10. description: "选择要构建的镜像"
  11. required: true
  12. default: "all"
  13. type: choice
  14. options:
  15. - all
  16. - crawler
  17. - mcp
  18. env:
  19. REGISTRY: docker.io
  20. jobs:
  21. build-crawler:
  22. runs-on: ubuntu-latest
  23. # 条件:v* 标签(排除 mcp-v*)或手动触发选择 all/crawler
  24. if: |
  25. (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') && !startsWith(github.ref, 'refs/tags/mcp-v')) ||
  26. (github.event_name == 'workflow_dispatch' && (github.event.inputs.image == 'all' || github.event.inputs.image == 'crawler'))
  27. steps:
  28. - name: Checkout
  29. uses: actions/checkout@v6
  30. - name: Set up QEMU
  31. uses: docker/setup-qemu-action@v4
  32. - name: Set up Docker Buildx
  33. uses: docker/setup-buildx-action@v4
  34. with:
  35. driver-opts: |
  36. network=host
  37. - name: Login to Docker Hub
  38. uses: docker/login-action@v4
  39. with:
  40. username: ${{ secrets.DOCKERHUB_USERNAME }}
  41. password: ${{ secrets.DOCKERHUB_TOKEN }}
  42. - name: Extract metadata
  43. id: meta
  44. uses: docker/metadata-action@v6
  45. with:
  46. images: wantcat/trendradar
  47. tags: |
  48. type=semver,pattern={{version}}
  49. type=semver,pattern={{major}}.{{minor}}
  50. type=raw,value=latest
  51. - name: Build and push
  52. uses: docker/build-push-action@v6
  53. env:
  54. BUILDKIT_PROGRESS: plain
  55. with:
  56. context: .
  57. file: ./docker/Dockerfile
  58. platforms: linux/amd64,linux/arm64
  59. push: true
  60. tags: ${{ steps.meta.outputs.tags }}
  61. labels: ${{ steps.meta.outputs.labels }}
  62. cache-from: type=gha
  63. cache-to: type=gha,mode=max
  64. build-mcp:
  65. runs-on: ubuntu-latest
  66. # 条件:mcp-v* 标签 或手动触发选择 all/mcp
  67. if: |
  68. (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/mcp-v')) ||
  69. (github.event_name == 'workflow_dispatch' && (github.event.inputs.image == 'all' || github.event.inputs.image == 'mcp'))
  70. steps:
  71. - name: Checkout
  72. uses: actions/checkout@v6
  73. - name: Set up QEMU
  74. uses: docker/setup-qemu-action@v4
  75. - name: Set up Docker Buildx
  76. uses: docker/setup-buildx-action@v4
  77. with:
  78. driver-opts: |
  79. network=host
  80. - name: Login to Docker Hub
  81. uses: docker/login-action@v4
  82. with:
  83. username: ${{ secrets.DOCKERHUB_USERNAME }}
  84. password: ${{ secrets.DOCKERHUB_TOKEN }}
  85. - name: Extract version from tag
  86. id: version
  87. run: |
  88. if [[ "${{ github.ref }}" == refs/tags/mcp-v* ]]; then
  89. VERSION="${GITHUB_REF#refs/tags/mcp-v}"
  90. echo "version=${VERSION}" >> $GITHUB_OUTPUT
  91. echo "major_minor=$(echo $VERSION | cut -d. -f1,2)" >> $GITHUB_OUTPUT
  92. else
  93. echo "version=latest" >> $GITHUB_OUTPUT
  94. echo "major_minor=latest" >> $GITHUB_OUTPUT
  95. fi
  96. - name: Extract metadata
  97. id: meta
  98. uses: docker/metadata-action@v6
  99. with:
  100. images: wantcat/trendradar-mcp
  101. tags: |
  102. type=raw,value=${{ steps.version.outputs.version }}
  103. type=raw,value=${{ steps.version.outputs.major_minor }}
  104. type=raw,value=latest
  105. - name: Build and push
  106. uses: docker/build-push-action@v6
  107. env:
  108. BUILDKIT_PROGRESS: plain
  109. with:
  110. context: .
  111. file: ./docker/Dockerfile.mcp
  112. platforms: linux/amd64,linux/arm64
  113. push: true
  114. tags: ${{ steps.meta.outputs.tags }}
  115. labels: ${{ steps.meta.outputs.labels }}
  116. cache-from: type=gha
  117. cache-to: type=gha,mode=max