docker-build-manual.yml 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. name: Build Test Docker Image manually
  2. on:
  3. workflow_dispatch:
  4. inputs:
  5. _notes_:
  6. description: '⚠️ Please create a new git tag before building the docker image.'
  7. required: false
  8. type: boolean
  9. default: false
  10. permissions:
  11. contents: read
  12. id-token: write
  13. packages: write
  14. jobs:
  15. build-and-push:
  16. runs-on: ubuntu-latest
  17. steps:
  18. - name: Checkout code
  19. uses: actions/checkout@v6
  20. with:
  21. fetch-depth: 0 # Fetch all history for tags
  22. - name: Set up Python
  23. uses: actions/setup-python@v6
  24. with:
  25. python-version: "3.x"
  26. - name: Get latest tag
  27. id: get_tag
  28. run: |
  29. # Get the latest tag, fallback to commit SHA if no tags exist
  30. LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
  31. if [ -z "$LATEST_TAG" ]; then
  32. LATEST_TAG="sha-$(git rev-parse --short HEAD)"
  33. echo "No tags found, using commit SHA: $LATEST_TAG"
  34. else
  35. echo "Latest tag found: $LATEST_TAG"
  36. fi
  37. PACKAGE_VERSION="${LATEST_TAG#v}"
  38. echo "tag=$LATEST_TAG" >> $GITHUB_OUTPUT
  39. echo "image_tag=$LATEST_TAG" >> $GITHUB_OUTPUT
  40. echo "package_version=$PACKAGE_VERSION" >> $GITHUB_OUTPUT
  41. - name: Update version definitions
  42. run: |
  43. python scripts/release/set_version.py --core-version "${{ steps.get_tag.outputs.package_version }}"
  44. echo "Updated version definitions with ${{ steps.get_tag.outputs.package_version }}"
  45. grep '__version__ = ' lightrag/_version.py
  46. - name: Set up Docker Buildx
  47. uses: docker/setup-buildx-action@v4
  48. - name: Login to GitHub Container Registry
  49. uses: docker/login-action@v4
  50. with:
  51. registry: ghcr.io
  52. username: ${{ github.actor }}
  53. password: ${{ secrets.GITHUB_TOKEN }}
  54. - name: Install cosign
  55. uses: sigstore/cosign-installer@6f9f17788090df1f26f669e9d70d6ae9567deba6 # v4.1.2
  56. - name: Extract metadata for Docker
  57. id: meta
  58. uses: docker/metadata-action@v6
  59. with:
  60. images: ghcr.io/${{ github.repository }}
  61. tags: |
  62. type=raw,value=${{ steps.get_tag.outputs.tag }}
  63. - name: Build and push Docker image
  64. id: build-and-push
  65. uses: docker/build-push-action@v7
  66. with:
  67. context: .
  68. file: ./Dockerfile
  69. platforms: linux/amd64,linux/arm64
  70. push: true
  71. tags: ${{ steps.meta.outputs.tags }}
  72. labels: ${{ steps.meta.outputs.labels }}
  73. cache-from: type=gha
  74. cache-to: type=gha,mode=max
  75. - name: Sign Docker image
  76. if: steps.build-and-push.outputs.digest != ''
  77. env:
  78. DIGEST: ${{ steps.build-and-push.outputs.digest }}
  79. TAGS: ${{ steps.meta.outputs.tags }}
  80. run: |
  81. set -euo pipefail
  82. echo "Signing manifest digest: $DIGEST"
  83. while IFS= read -r tag; do
  84. if [ -z "$tag" ]; then
  85. continue
  86. fi
  87. echo "Signing ${tag}@${DIGEST}"
  88. cosign sign --yes "${tag}@${DIGEST}"
  89. done <<< "$TAGS"
  90. - name: Output image details
  91. run: |
  92. echo "Docker image built and pushed successfully!"
  93. echo "Image tags:"
  94. echo " - ghcr.io/${{ github.repository }}:${{ steps.get_tag.outputs.tag }}"
  95. echo "Signed manifest digest: ${{ steps.build-and-push.outputs.digest }}"
  96. echo "Latest Git tag used: ${{ steps.get_tag.outputs.tag }}"