Skip to content

Commit 3a45212

Browse files
[add] optimized github actions and dockerfile
1 parent ec22535 commit 3a45212

File tree

4 files changed

+136
-88
lines changed

4 files changed

+136
-88
lines changed

.github/workflows/fly-deploy-gpu.yml

+18-40
Original file line numberDiff line numberDiff line change
@@ -20,32 +20,31 @@ jobs:
2020
- uses: actions/checkout@v3
2121
with:
2222
submodules: recursive
23-
- uses: superfly/flyctl-actions/setup-flyctl@master
2423

25-
# Print system info
24+
# Set up uv for Python environment management
25+
- name: Set up uv
26+
id: setup-uv
27+
uses: astral-sh/setup-uv@v5
28+
with:
29+
python-version: "3.10"
30+
enable-cache: true
31+
cache-dependency-glob: |
32+
**/requirements*.txt
33+
**/pyproject.toml
34+
src_deploy/setup.sh
35+
36+
# Print system info and uv version
2637
- name: Print system info
2738
run: |
2839
echo "System information:"
2940
uname -a
3041
free -h
3142
df -h
3243
cat /etc/os-release
44+
echo "UV version: ${{ steps.setup-uv.outputs.uv-version }}"
45+
uv --version
3346
34-
# Set up Docker Buildx
35-
- name: Set up Docker Buildx
36-
uses: docker/setup-buildx-action@v3
37-
with:
38-
driver-opts: |
39-
image=moby/buildkit:latest
40-
41-
# Cache Docker layers - Updated approach
42-
- name: Cache Docker layers
43-
uses: actions/cache@v3
44-
with:
45-
path: /tmp/.buildx-cache
46-
key: ${{ runner.os }}-buildx-${{ hashFiles('./src_deploy/gpu.Dockerfile') }}
47-
restore-keys: |
48-
${{ runner.os }}-buildx-
47+
- uses: superfly/flyctl-actions/setup-flyctl@master
4948

5049
# Set Fly secrets
5150
- name: Set Fly secrets
@@ -87,29 +86,8 @@ jobs:
8786
ls -la ./src_deploy/
8887
cat ./src_deploy/gpu.Dockerfile
8988
90-
# Deploy to Fly with build caching - Updated approach
89+
# Deploy to Fly with debug flags
9190
- name: Deploy a docker container to fly.io
92-
uses: docker/build-push-action@v5
93-
with:
94-
context: .
95-
file: ./src_deploy/gpu.Dockerfile
96-
push: false
97-
load: true
98-
tags: flyio-deploy:latest
99-
cache-from: type=local,src=/tmp/.buildx-cache
100-
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
101-
102-
# Move cache to prevent cache growth
103-
- name: Move cache
104-
run: |
105-
rm -rf /tmp/.buildx-cache
106-
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
107-
108-
# Deploy using built image
109-
- name: Deploy to Fly.io
110-
run: |
111-
flyctl deploy --remote-only \
112-
--config src_deploy/gpu.fly.toml \
113-
--image flyio-deploy:latest
91+
run: flyctl deploy --remote-only --config src_deploy/gpu.fly.toml --dockerfile ./src_deploy/gpu.Dockerfile
11492
env:
11593
FLY_API_TOKEN: ${{ secrets.FLY_IO_DEPLOY_TOKEN }}

src_deploy/gpu.Dockerfile

+11-5
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,12 @@ WORKDIR /home/$NB_USER
6565
# Expose sglang server port
6666
EXPOSE 8080
6767

68-
# Install uv
69-
COPY --from=ghcr.io/astral-sh/uv:0.6.9 /uv /uvx /bin/
68+
# Install uv directly from GitHub
69+
RUN curl -LsSf https://astral.sh/uv/install.sh | sh
70+
ENV PATH="/home/$NB_USER/.cargo/bin:$PATH"
7071

7172
# Test that uv works
72-
# RUN uv --version
73+
RUN uv --version
7374

7475
# Copy the entire src_deploy directory structure
7576
COPY --chown=$NB_USER:users ./src_deploy/ /home/$NB_USER/
@@ -81,9 +82,14 @@ RUN chmod +x /home/$NB_USER/setup.sh /home/$NB_USER/entrypoint.py /home/$NB_USER
8182

8283
USER $NB_USER
8384

84-
# Run GPU setup script and create logs directory
85-
RUN /home/$NB_USER/setup.sh || echo "Setup script had issues but we're continuing the build" \
85+
# Create virtual environment using uv and run setup script
86+
RUN uv venv $HOME/.venv \
87+
&& . $HOME/.venv/bin/activate \
88+
&& /home/$NB_USER/setup.sh || echo "Setup script had issues but we're continuing the build" \
8689
&& mkdir -p /home/$NB_USER/logs
8790

91+
# Add venv to PATH
92+
ENV PATH="/home/$NB_USER/.venv/bin:$PATH"
93+
8894
# Set entrypoint to our startup script
8995
CMD ["/home/ubuntu/startup.sh"]

src_deploy/setup.sh

+29-43
Original file line numberDiff line numberDiff line change
@@ -13,60 +13,46 @@ echo "Can't initialize NVML. OR No CUDA runtime is found, using CUDA_HOME='/usr/
1313
echo "Please ignore these warnings. They are expected."
1414
echo "########################################################"
1515

16-
# Block 2: Use uv instead of pip
17-
echo "Setting up Python environment..."
18-
19-
# Create virtual environment using uv
20-
uv venv $HOME/.venv
21-
echo "✓ Virtual environment created"
22-
23-
# Make sure we use the virtual environment's Python and uv
24-
PYTHON="$HOME/.venv/bin/python"
25-
UV="uv"
26-
27-
# Add venv activation to .bashrc
28-
echo 'source $HOME/.venv/bin/activate' >> ~/.bashrc
16+
# Block 2: Python environment is already created by Dockerfile
17+
echo "Using uv for package installation..."
18+
19+
# Make sure we're using the venv from Dockerfile
20+
if [ -d "$HOME/.venv" ]; then
21+
echo "Using existing virtual environment"
22+
source $HOME/.venv/bin/activate
23+
PYTHON="python"
24+
else
25+
echo "Warning: Virtual environment not found, creating one now"
26+
uv venv $HOME/.venv
27+
source $HOME/.venv/bin/activate
28+
PYTHON="python"
29+
fi
2930

3031
# Block 3: Python Dependencies using uv
3132
echo "Installing Python packages..."
32-
$UV pip install --upgrade pip
33-
echo "✓ Pip upgraded"
3433

35-
# Install setuptools first (required by triton)
36-
echo "Installing setuptools..."
37-
$UV pip install setuptools wheel
38-
echo "✓ Setuptools and wheel installed"
34+
# Install packages in parallel with efficient dependency resolution
35+
echo "Installing core packages..."
36+
uv pip install -U "transformers==4.48.3" triton "sglang[all]>=0.4.2.post4" --find-links https://flashinfer.ai/whl/cu124/torch2.5/flashinfer/
3937

40-
# Install transformers
41-
echo "Installing transformers..."
42-
$UV pip install "transformers==4.48.3"
43-
$PYTHON -c "import transformers" && echo "✓ Transformers installed" || echo "Warning: Could not import transformers, but continuing"
38+
echo "Installing additional packages..."
39+
uv pip install -U accelerate bitsandbytes huggingface_hub
4440

45-
# Install triton first as it's a dependency for sglang
46-
echo "Installing triton..."
47-
$UV pip install triton
41+
# Validate installations
42+
$PYTHON -c "import transformers" && echo "✓ Transformers installed" || echo "Warning: Could not import transformers, but continuing"
4843
$PYTHON -c "import triton" && echo "✓ Triton installed" || echo "Warning: Could not import triton"
49-
50-
# Install sglang and dependencies
51-
echo "Installing sglang and dependencies..."
52-
$UV pip install "sglang[all]>=0.4.2.post4" --find-links https://flashinfer.ai/whl/cu124/torch2.5/flashinfer/
5344
$PYTHON -c "import sglang" && echo "✓ SGLang installed" || { echo "ERROR: Could not import sglang, installation failed"; exit 1; }
54-
55-
# Install additional required packages
56-
echo "Installing additional packages..."
57-
$UV pip install accelerate bitsandbytes
5845
$PYTHON -c "import accelerate" && echo "✓ Accelerate installed" || echo "Warning: Could not import accelerate"
59-
# $PYTHON -c "import bitsandbytes" && echo "✓ BitsAndBytes installed" || echo "Warning: Could not import bitsandbytes"
60-
61-
# Install huggingface_hub
62-
echo "Installing huggingface_hub..."
63-
$UV pip install huggingface_hub
6446
$PYTHON -c "import huggingface_hub" && echo "✓ Huggingface_hub installed" || echo "Warning: Could not import huggingface_hub"
6547

66-
# Install requirements.txt packages
67-
echo "Installing requirements.txt packages..."
68-
$UV pip install -r ~/requirements.txt
69-
echo "✓ Application dependencies installed"
48+
# Install requirements.txt packages efficiently
49+
if [ -f ~/requirements.txt ]; then
50+
echo "Installing requirements.txt packages..."
51+
uv pip install -r ~/requirements.txt
52+
echo "✓ Application dependencies installed"
53+
else
54+
echo "No requirements.txt found, skipping"
55+
fi
7056

7157
# Block 4: Skip CUDA Check during build
7258
echo "Note: Skipping CUDA check during build phase. Will check when container runs."

src_deploy/setup_dev.sh

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/bin/bash
2+
3+
# Don't exit immediately on errors during build phase
4+
set +e
5+
6+
echo "Starting setup for sglang server on A10 GPU..."
7+
8+
# Block 1: Skip GPU Check during build
9+
echo "########################################################"
10+
echo "Note: Skipping GPU checks during build phase. Will check when container runs."
11+
echo "You might see a warning about GPU like: "
12+
echo "Can't initialize NVML. OR No CUDA runtime is found, using CUDA_HOME='/usr/local/cuda' "
13+
echo "Please ignore these warnings. They are expected."
14+
echo "########################################################"
15+
16+
# Block 2: Use uv instead of pip
17+
echo "Setting up Python environment..."
18+
19+
# Create virtual environment using uv
20+
uv venv $HOME/.venv
21+
echo "✓ Virtual environment created"
22+
23+
# Make sure we use the virtual environment's Python and uv
24+
PYTHON="$HOME/.venv/bin/python"
25+
UV="uv"
26+
27+
# Add venv activation to .bashrc
28+
echo 'source $HOME/.venv/bin/activate' >> ~/.bashrc
29+
30+
# Block 3: Python Dependencies using uv
31+
echo "Installing Python packages..."
32+
$UV pip install --upgrade pip
33+
echo "✓ Pip upgraded"
34+
35+
# Install setuptools first (required by triton)
36+
echo "Installing setuptools..."
37+
$UV pip install setuptools wheel
38+
echo "✓ Setuptools and wheel installed"
39+
40+
# Install transformers
41+
echo "Installing transformers..."
42+
$UV pip install "transformers==4.48.3"
43+
$PYTHON -c "import transformers" && echo "✓ Transformers installed" || echo "Warning: Could not import transformers, but continuing"
44+
45+
# Install triton first as it's a dependency for sglang
46+
echo "Installing triton..."
47+
$UV pip install triton
48+
$PYTHON -c "import triton" && echo "✓ Triton installed" || echo "Warning: Could not import triton"
49+
50+
# Install sglang and dependencies
51+
echo "Installing sglang and dependencies..."
52+
$UV pip install "sglang[all]>=0.4.2.post4" --find-links https://flashinfer.ai/whl/cu124/torch2.5/flashinfer/
53+
$PYTHON -c "import sglang" && echo "✓ SGLang installed" || { echo "ERROR: Could not import sglang, installation failed"; exit 1; }
54+
55+
# Install additional required packages
56+
echo "Installing additional packages..."
57+
$UV pip install accelerate bitsandbytes
58+
$PYTHON -c "import accelerate" && echo "✓ Accelerate installed" || echo "Warning: Could not import accelerate"
59+
# $PYTHON -c "import bitsandbytes" && echo "✓ BitsAndBytes installed" || echo "Warning: Could not import bitsandbytes"
60+
61+
# Install huggingface_hub
62+
echo "Installing huggingface_hub..."
63+
$UV pip install huggingface_hub
64+
$PYTHON -c "import huggingface_hub" && echo "✓ Huggingface_hub installed" || echo "Warning: Could not import huggingface_hub"
65+
66+
# Install requirements.txt packages
67+
echo "Installing requirements.txt packages..."
68+
$UV pip install -r ~/requirements.txt
69+
echo "✓ Application dependencies installed"
70+
71+
# Block 4: Skip CUDA Check during build
72+
echo "Note: Skipping CUDA check during build phase. Will check when container runs."
73+
74+
echo "Setup completed!"
75+
echo "The next step will download the model when the server starts."
76+
77+
# Return success regardless of individual command results
78+
exit 0

0 commit comments

Comments
 (0)