diff --git a/.github/workflows/build-image-template.yml b/.github/workflows/build-image-template.yml new file mode 100644 index 000000000..fde2fc0bb --- /dev/null +++ b/.github/workflows/build-image-template.yml @@ -0,0 +1,104 @@ +name: Build Image Template + +on: + workflow_call: + inputs: + python_version: + required: true + type: string + dockerfile_path: + required: true + type: string + tag_suffix: + required: true + type: string + +jobs: + build-and-push: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Free up disk space + run: | + # Display initial space + echo "Initial disk space:" + df -h + + # Remove large directories directly + sudo rm -rf /usr/share/dotnet + sudo rm -rf /usr/local/lib/android + sudo rm -rf /opt/ghc + sudo rm -rf /usr/local/share/boost + sudo rm -rf /usr/share/swift + sudo rm -rf /usr/local/lib/node_modules + sudo rm -rf /usr/local/share/powershell + sudo rm -rf /usr/share/rust + sudo rm -rf /usr/local/.ghcup + + # Remove cached files + sudo rm -rf /var/lib/apt/lists/* + sudo rm -rf /var/cache/apt/archives/* + + # Clean Docker + docker system prune -af --volumes + + # Display available space after cleanup + echo "Disk space after cleanup:" + df -h + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Prepare tags + id: prepare-tags + run: | + SHORT_SHA=$(echo ${{ github.sha }} | cut -c1-7) + + TAGS="type=raw,value=${{ inputs.tag_suffix }}-latest" + TAGS="${TAGS}\ntype=raw,value=${{ inputs.tag_suffix }}-sha-${SHORT_SHA}" + + # Set Python 3.10 as the default image + if [[ "${{ inputs.python_version }}" == "3.10" ]]; then + TAGS="${TAGS}\ntype=raw,value=latest" + fi + + echo "tags<> $GITHUB_OUTPUT + echo -e "$TAGS" >> $GITHUB_OUTPUT + echo "EOF" >> $GITHUB_OUTPUT + + - name: Extract metadata for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ghcr.io/${{ github.repository }}/fastvideo-dev + tags: ${{ steps.prepare-tags.outputs.tags }} + + - name: Build and push Docker image + id: build-push + uses: docker/build-push-action@v6 + with: + context: . + file: ${{ inputs.dockerfile_path }} + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: Success message + run: | + echo "✅ Python ${{ inputs.python_version }} image successfully built and pushed to ghcr.io/${{ github.repository }}/fastvideo-dev:${{ inputs.tag_suffix }}-latest" + echo "To run tests with this image, manually trigger the 'Run Tests' workflow." \ No newline at end of file diff --git a/.github/workflows/build-image.yml b/.github/workflows/build-image.yml index 52a445393..b754a32f9 100644 --- a/.github/workflows/build-image.yml +++ b/.github/workflows/build-image.yml @@ -1,78 +1,48 @@ -name: Build and Push Docker Image +name: Build and Push Docker Images on: - workflow_dispatch: # Only manual triggers + workflow_dispatch: + inputs: + python_3_10: + description: 'Build Python 3.10 image' + required: false + default: false + type: boolean + python_3_11: + description: 'Build Python 3.11 image' + required: false + default: false + type: boolean + python_3_12: + description: 'Build Python 3.12 image' + required: false + default: false + type: boolean jobs: - build-and-push: - runs-on: ubuntu-latest - permissions: - contents: read - packages: write - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Free up disk space - run: | - # Display initial space - echo "Initial disk space:" - df -h - - # Remove large directories directly - sudo rm -rf /usr/share/dotnet - sudo rm -rf /usr/local/lib/android - sudo rm -rf /opt/ghc - sudo rm -rf /usr/local/share/boost - sudo rm -rf /usr/share/swift - sudo rm -rf /usr/local/lib/node_modules - sudo rm -rf /usr/local/share/powershell - sudo rm -rf /usr/share/rust - sudo rm -rf /usr/local/.ghcup - - # Remove cached files - sudo rm -rf /var/lib/apt/lists/* - sudo rm -rf /var/cache/apt/archives/* - - # Clean Docker - docker system prune -af --volumes - - # Display available space after cleanup - echo "Disk space after cleanup:" - df -h - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Login to GitHub Container Registry - uses: docker/login-action@v3 - with: - registry: ghcr.io - username: ${{ github.repository_owner }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Extract metadata for Docker - id: meta - uses: docker/metadata-action@v5 - with: - images: ghcr.io/${{ github.repository }}/fastvideo-dev - tags: | - type=raw,value=latest - type=sha,format=short - - - name: Build and push Docker image - id: build-push - uses: docker/build-push-action@v6 - with: - context: . - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - cache-from: type=gha - cache-to: type=gha,mode=max - - - name: Success message - run: | - echo "✅ Image successfully built and pushed to ghcr.io/${{ github.repository }}/fastvideo-dev:latest" - echo "To run tests with this image, manually trigger the 'Run Tests' workflow." \ No newline at end of file + build-python-3-10: + if: ${{ github.event.inputs.python_3_10 == 'true' }} + uses: ./.github/workflows/build-image-template.yml + with: + python_version: '3.10' + dockerfile_path: docker/Dockerfile.python3.10 + tag_suffix: py3.10 + secrets: inherit + + build-python-3-11: + if: ${{ github.event.inputs.python_3_11 == 'true' }} + uses: ./.github/workflows/build-image-template.yml + with: + python_version: '3.11' + dockerfile_path: docker/Dockerfile.python3.11 + tag_suffix: py3.11 + secrets: inherit + + build-python-3-12: + if: ${{ github.event.inputs.python_3_12 == 'true' }} + uses: ./.github/workflows/build-image-template.yml + with: + python_version: '3.12' + dockerfile_path: docker/Dockerfile.python3.12 + tag_suffix: py3.12 + secrets: inherit \ No newline at end of file diff --git a/Dockerfile b/docker/Dockerfile.python3.10 similarity index 97% rename from Dockerfile rename to docker/Dockerfile.python3.10 index 6e9b7f2e7..95701e4e2 100644 --- a/Dockerfile +++ b/docker/Dockerfile.python3.10 @@ -29,7 +29,7 @@ RUN echo "# Placeholder" > README.md RUN conda run -n fastvideo-dev pip install --no-cache-dir --upgrade pip && \ conda run -n fastvideo-dev pip install --no-cache-dir .[dev] && \ - conda run -n fastvideo-dev pip install --no-cache-dir flash-attn==2.7.0.post2 --no-build-isolation && \ + conda run -n fastvideo-dev pip install --no-cache-dir flash-attn==2.7.4.post1 --no-build-isolation && \ conda clean -afy COPY . . diff --git a/docker/Dockerfile.python3.11 b/docker/Dockerfile.python3.11 new file mode 100644 index 000000000..35bd87b17 --- /dev/null +++ b/docker/Dockerfile.python3.11 @@ -0,0 +1,48 @@ +FROM nvidia/cuda:12.4.1-devel-ubuntu20.04 + +ENV DEBIAN_FRONTEND=noninteractive + +WORKDIR /FastVideo + +RUN apt-get update && apt-get install -y --no-install-recommends \ + wget \ + git \ + ca-certificates \ + openssh-server \ + && rm -rf /var/lib/apt/lists/* + +RUN wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh && \ + bash Miniconda3-latest-Linux-x86_64.sh -b -p /opt/conda && \ + rm Miniconda3-latest-Linux-x86_64.sh + +ENV PATH=/opt/conda/bin:$PATH + +RUN conda create --name fastvideo-dev python=3.11.11 -y + +SHELL ["/bin/bash", "-c"] + +# Copy just the pyproject.toml first to leverage Docker cache +COPY pyproject.toml ./ + +# Create a dummy README to satisfy the installation +RUN echo "# Placeholder" > README.md + +RUN conda run -n fastvideo-dev pip install --no-cache-dir --upgrade pip && \ + conda run -n fastvideo-dev pip install --no-cache-dir .[dev] && \ + conda run -n fastvideo-dev pip install --no-cache-dir flash-attn==2.7.4.post1 --no-build-isolation && \ + conda clean -afy + +COPY . . + +RUN conda run -n fastvideo-dev pip install --no-cache-dir -e .[dev] + +# Remove authentication headers +RUN git config --unset-all http.https://github.com/.extraheader || true + +# Set up automatic conda environment activation for all shells +RUN echo 'source /opt/conda/etc/profile.d/conda.sh' >> /root/.bashrc && \ + echo 'conda activate fastvideo-dev' >> /root/.bashrc && \ + # Ensure .bashrc is sourced for SSH login shells + echo 'if [ -f ~/.bashrc ]; then . ~/.bashrc; fi' > /root/.profile + +EXPOSE 22 \ No newline at end of file diff --git a/docker/Dockerfile.python3.12 b/docker/Dockerfile.python3.12 new file mode 100644 index 000000000..2a61dd81e --- /dev/null +++ b/docker/Dockerfile.python3.12 @@ -0,0 +1,48 @@ +FROM nvidia/cuda:12.4.1-devel-ubuntu20.04 + +ENV DEBIAN_FRONTEND=noninteractive + +WORKDIR /FastVideo + +RUN apt-get update && apt-get install -y --no-install-recommends \ + wget \ + git \ + ca-certificates \ + openssh-server \ + && rm -rf /var/lib/apt/lists/* + +RUN wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh && \ + bash Miniconda3-latest-Linux-x86_64.sh -b -p /opt/conda && \ + rm Miniconda3-latest-Linux-x86_64.sh + +ENV PATH=/opt/conda/bin:$PATH + +RUN conda create --name fastvideo-dev python=3.12.9 -y + +SHELL ["/bin/bash", "-c"] + +# Copy just the pyproject.toml first to leverage Docker cache +COPY pyproject.toml ./ + +# Create a dummy README to satisfy the installation +RUN echo "# Placeholder" > README.md + +RUN conda run -n fastvideo-dev pip install --no-cache-dir --upgrade pip && \ + conda run -n fastvideo-dev pip install --no-cache-dir .[dev] && \ + conda run -n fastvideo-dev pip install --no-cache-dir flash-attn==2.7.4.post1 --no-build-isolation && \ + conda clean -afy + +COPY . . + +RUN conda run -n fastvideo-dev pip install --no-cache-dir -e .[dev] + +# Remove authentication headers +RUN git config --unset-all http.https://github.com/.extraheader || true + +# Set up automatic conda environment activation for all shells +RUN echo 'source /opt/conda/etc/profile.d/conda.sh' >> /root/.bashrc && \ + echo 'conda activate fastvideo-dev' >> /root/.bashrc && \ + # Ensure .bashrc is sourced for SSH login shells + echo 'if [ -f ~/.bashrc ]; then . ~/.bashrc; fi' > /root/.profile + +EXPOSE 22 \ No newline at end of file