1+ name : Docker
2+
3+ on :
4+ push :
5+ branches : [ "main" ]
6+ tags : [ 'v*.*.*' ]
7+
8+ env :
9+ REGISTRY : ghcr.io
10+ IMAGE_NAME : ${{ github.repository }}
11+
12+ jobs :
13+ build :
14+ runs-on : ubuntu-latest
15+ permissions :
16+ contents : write
17+ packages : write
18+ id-token : write
19+
20+ timeout-minutes : 600
21+
22+ steps :
23+ - name : Free Disk Space (Ubuntu)
24+ uses : jlumbroso/free-disk-space@main
25+ with :
26+ tool-cache : true
27+ android : true
28+ dotnet : true
29+ haskell : true
30+ large-packages : true
31+ swap-storage : false
32+ docker-images : false
33+
34+ - name : Checkout repository
35+ uses : actions/checkout@v3
36+ with :
37+ submodules : recursive
38+
39+ - name : Add Swap
40+ run : |
41+ SWAP_FILE="/mnt/swapfile"
42+
43+ swapon --show
44+ echo "Trying to disable and remove existing swap if needed..."
45+ if swapon --show=NAME | grep -q "$SWAP_FILE"; then
46+ echo "Disabling existing swap at $SWAP_FILE..."
47+ sudo swapoff "$SWAP_FILE"
48+ fi
49+
50+ if [ -f "$SWAP_FILE" ]; then
51+ echo "Removing existing file at $SWAP_FILE..."
52+ sudo rm -f "$SWAP_FILE"
53+ fi
54+
55+ echo "Creating new 32G swap file..."
56+ sudo dd if=/dev/zero of=$SWAP_FILE bs=1G count=32
57+ sudo chmod 600 "$SWAP_FILE"
58+ sudo mkswap "$SWAP_FILE"
59+ sudo swapon "$SWAP_FILE"
60+
61+ echo "Final swap status:"
62+ swapon --show
63+ free -h
64+
65+ - name : Install cosign
66+ if : github.event_name != 'pull_request'
67+ 68+
69+ - name : Setup Docker buildx
70+ uses : docker/setup-buildx-action@v3
71+
72+ - name : Docker cache - restore
73+ uses : actions/cache@v4
74+ with :
75+ path : /tmp/.buildx-cache
76+ key : buildx-${{ runner.os }}-${{ github.sha }}
77+ restore-keys : |
78+ buildx-${{ runner.os }}-
79+
80+ - name : Log into registry ${{ env.REGISTRY }}
81+ if : github.event_name != 'pull_request'
82+ uses : docker/login-action@v3
83+ with :
84+ registry : ${{ env.REGISTRY }}
85+ username : ${{ github.actor }}
86+ password : ${{ secrets.GITHUB_TOKEN }}
87+
88+ - name : Extract Docker metadata
89+ id : meta
90+ uses : docker/metadata-action@v5
91+ with :
92+ images : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
93+
94+ - name : Build and push Docker image
95+ id : build-and-push
96+ uses : docker/build-push-action@v5
97+ with :
98+ context : .
99+ push : ${{ github.event_name != 'pull_request' }}
100+ tags : ${{ steps.meta.outputs.tags }}
101+ labels : ${{ steps.meta.outputs.labels }}
102+ cache-from : type=local,src=/tmp/.buildx-cache
103+ cache-to : type=local,dest=/tmp/.buildx-cache,mode=max
104+
105+ - name : Sign the published Docker image
106+ if : ${{ github.event_name != 'pull_request' }}
107+ env :
108+ TAGS : ${{ steps.meta.outputs.tags }}
109+ DIGEST : ${{ steps.build-and-push.outputs.digest }}
110+ run : echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}
111+
112+ - name : Export wheel from image
113+ run : |
114+ CONTAINER_TAG=$(echo "${{ steps.meta.outputs.tags }}" | head -n1)
115+ CONTAINER_ID=$(docker create $CONTAINER_TAG)
116+ # Copy wheel files from the container to the local machine
117+ docker cp "$CONTAINER_ID:/out" ./out
118+ # Remove the container
119+ docker rm "$CONTAINER_ID"
120+ # Verify wheel file has been copied
121+ echo "Exported wheel files:"
122+ ls -la ./out
123+ WHEEL_COUNT=$(ls -1 ./out/*.whl | wc -l)
124+ echo "Total wheel files: $WHEEL_COUNT"
125+
126+ - name : Upload .whl to GitHub Release
127+ if : startsWith(github.ref, 'refs/tags/')
128+ env :
129+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
130+ run : |
131+ TAG_NAME=${GITHUB_REF##*/}
132+
133+ # Get wheel file information
134+ LIGHTKERNEL_WHEEL=$(ls ./out/lightllm_kernel-*.whl | head -n1 | xargs basename)
135+ FLASH_ATTN_WHEEL=$(ls ./out/flash_attn_3-*.whl | head -n1 | xargs basename)
136+
137+ gh release create "$TAG_NAME" ./out/*.whl \
138+ --title "LightKernel Release $TAG_NAME" \
139+ --notes "🎯 **LightKernel Docker Release $TAG_NAME**
140+
141+ This automated release contains pre-compiled wheel packages:
142+
143+ 📦 **Packages:**
144+ - **$LIGHTKERNEL_WHEEL** - Core CUDA kernel library
145+ - **$FLASH_ATTN_WHEEL** - Flash Attention 3.0 (Hopper)
146+
147+ 🚀 **Quick Installation:**
148+ \`\`\`bash
149+ # Install both packages
150+ pip install https://github.com/${{ github.repository }}/releases/download/$TAG_NAME/$LIGHTKERNEL_WHEEL
151+ pip install https://github.com/${{ github.repository }}/releases/download/$TAG_NAME/$FLASH_ATTN_WHEEL
152+ \`\`\`
153+
154+ 🔧 **Build Environment:**
155+ - CUDA: 12.6.1 with cuDNN
156+ - PyTorch: 2.7.1
157+ - Python: 3.10
158+ - Architecture: CUDA Compute Capabilities 8.0, 8.6, 8.9, 9.0
159+
160+ 🐳 **Docker Image:** \`${{ steps.meta.outputs.tags }}\`
161+
162+ Built on $(date -u)" \
163+ || echo "Release already exists, skipping"
0 commit comments