| name: Build Latest Docker Image on Release |
|
|
| on: |
| release: |
| types: [published] |
| workflow_dispatch: |
|
|
| permissions: |
| contents: read |
| packages: write |
|
|
| jobs: |
| build-and-push: |
| runs-on: ubuntu-latest |
| steps: |
| - name: Checkout code |
| uses: actions/checkout@v6 |
| with: |
| fetch-depth: 0 |
|
|
| - name: Set up Python |
| uses: actions/setup-python@v6 |
| with: |
| python-version: "3.x" |
|
|
| - name: Set up Docker Buildx |
| uses: docker/setup-buildx-action@v4 |
|
|
| - name: Login to GitHub Container Registry |
| uses: docker/login-action@v4 |
| with: |
| registry: ghcr.io |
| username: ${{ github.actor }} |
| password: ${{ secrets.GITHUB_TOKEN }} |
|
|
| - name: Get latest tag |
| id: get_tag |
| run: | |
| if [ "${{ github.event_name }}" = "release" ] && [ -n "${{ github.event.release.tag_name }}" ]; then |
| TAG="${{ github.event.release.tag_name }}" |
| else |
| TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "") |
| fi |
| if [ -z "$TAG" ]; then |
| echo "No git tag found for docker publish" |
| exit 1 |
| fi |
| PACKAGE_VERSION="${TAG#v}" |
| echo "Found tag: $TAG" |
| echo "tag=$TAG" >> $GITHUB_OUTPUT |
| echo "package_version=$PACKAGE_VERSION" >> $GITHUB_OUTPUT |
| |
| - name: Check if pre-release |
| id: check_prerelease |
| run: | |
| TAG="${{ steps.get_tag.outputs.tag }}" |
| if [[ "$TAG" == *"rc"* ]] || [[ "$TAG" == *"dev"* ]]; then |
| echo "is_prerelease=true" >> $GITHUB_OUTPUT |
| echo "This is a pre-release version: $TAG" |
| else |
| echo "is_prerelease=false" >> $GITHUB_OUTPUT |
| echo "This is a stable release: $TAG" |
| fi |
| |
| - name: Update version definitions |
| run: | |
| python scripts/release/set_version.py --core-version "${{ steps.get_tag.outputs.package_version }}" |
| echo "Updated version definitions with ${{ steps.get_tag.outputs.package_version }}" |
| grep '__version__ = ' lightrag/_version.py |
| |
| - name: Extract metadata for Docker |
| id: meta |
| uses: docker/metadata-action@v6 |
| with: |
| images: ghcr.io/${{ github.repository }} |
| tags: | |
| type=raw,value=${{ steps.get_tag.outputs.tag }} |
| type=raw,value=latest,enable=${{ steps.check_prerelease.outputs.is_prerelease == 'false' }} |
| |
| - name: Build and push Docker image |
| uses: docker/build-push-action@v7 |
| with: |
| context: . |
| file: ./Dockerfile |
| platforms: linux/amd64,linux/arm64 |
| push: true |
| tags: ${{ steps.meta.outputs.tags }} |
| labels: ${{ steps.meta.outputs.labels }} |
| cache-from: type=gha |
| cache-to: type=gha,mode=max |
|
|