From 5ee0e6b9740b85ff24349aacc4d69615f499490b Mon Sep 17 00:00:00 2001 From: Liana Date: Wed, 20 Nov 2024 23:22:55 -0600 Subject: [PATCH] Containerize Boltz, add CI workflows Add docker files and github workflows for automated docker image builds. Builds images with tags: main (python:3.10-slim), cuda12-1, and cuda12-4. Commit summaries containing "[no-ci]" will skip builds, and CI only runs with changes to core files. Have a good day. --- .dockerignore | 6 +++ .github/workflows/docker-build-base.yaml | 54 ++++++++++++++++++++ .github/workflows/docker-build-cuda12-1.yaml | 54 ++++++++++++++++++++ .github/workflows/docker-build-cuda12-4.yaml | 54 ++++++++++++++++++++ Dockerfile | 51 ++++++++++++++++++ 5 files changed, 219 insertions(+) create mode 100644 .dockerignore create mode 100644 .github/workflows/docker-build-base.yaml create mode 100644 .github/workflows/docker-build-cuda12-1.yaml create mode 100644 .github/workflows/docker-build-cuda12-4.yaml create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..5dac9b0 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +Dockerfile +.git +.gitignore +.dockerignore +.vscode +.DS_STORE diff --git a/.github/workflows/docker-build-base.yaml b/.github/workflows/docker-build-base.yaml new file mode 100644 index 0000000..4fad700 --- /dev/null +++ b/.github/workflows/docker-build-base.yaml @@ -0,0 +1,54 @@ +name: Build and push base docker image + +on: + push: + branches: ["release"] + paths: + - "Dockerfile" + - "scripts/**" + - "src/**" + - "pyproject.toml" + pull_request: + branches: ["release"] + paths: + - "Dockerfile" + - "scripts/**" + - "src/**" + - "pyproject.toml" + +env: + REGISTRY: ghcr.io + +jobs: + build-push-base: + if: "!contains(github.event.head_commit.message, '[no-ci]')" + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Convert repository name to lowercase + run: echo "IMAGE_NAME=$(echo ${GITHUB_REPOSITORY} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV + + - name: Log in to the container registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build and push image + uses: docker/build-push-action@v6 + with: + context: . + push: true + tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:main + build-args: BASE_IMAGE=python:3.10-slim + # cache-from: type=gha + # cache-to: type=gha,mode=max diff --git a/.github/workflows/docker-build-cuda12-1.yaml b/.github/workflows/docker-build-cuda12-1.yaml new file mode 100644 index 0000000..6ccfe5d --- /dev/null +++ b/.github/workflows/docker-build-cuda12-1.yaml @@ -0,0 +1,54 @@ +name: Build and push CUDA 12.1 docker image + +on: + push: + branches: ["release"] + paths: + - "Dockerfile" + - "scripts/**" + - "src/**" + - "pyproject.toml" + pull_request: + branches: ["release"] + paths: + - "Dockerfile" + - "scripts/**" + - "src/**" + - "pyproject.toml" + +env: + REGISTRY: ghcr.io + +jobs: + build-push-cuda12-1: + if: "!contains(github.event.head_commit.message, '[no-ci]')" + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Convert repository name to lowercase + run: echo "IMAGE_NAME=$(echo ${GITHUB_REPOSITORY} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV + + - name: Log in to the container registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build and push image + uses: docker/build-push-action@v6 + with: + context: . + push: true + tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:cuda12-1 + build-args: BASE_IMAGE=nvidia/cuda:12.1.1-cudnn8-runtime-ubuntu22.04 + # cache-from: type=gha + # cache-to: type=gha,mode=max diff --git a/.github/workflows/docker-build-cuda12-4.yaml b/.github/workflows/docker-build-cuda12-4.yaml new file mode 100644 index 0000000..33433ba --- /dev/null +++ b/.github/workflows/docker-build-cuda12-4.yaml @@ -0,0 +1,54 @@ +name: Build and push CUDA 12.4 docker image + +on: + push: + branches: ["release"] + paths: + - "Dockerfile" + - "scripts/**" + - "src/**" + - "pyproject.toml" + pull_request: + branches: ["release"] + paths: + - "Dockerfile" + - "scripts/**" + - "src/**" + - "pyproject.toml" + +env: + REGISTRY: ghcr.io + +jobs: + build-push-cuda12-4: + if: "!contains(github.event.head_commit.message, '[no-ci]')" + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Convert repository name to lowercase + run: echo "IMAGE_NAME=$(echo ${GITHUB_REPOSITORY} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV + + - name: Log in to the container registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build and push image + uses: docker/build-push-action@v6 + with: + context: . + push: true + tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:cuda12-4 + build-args: BASE_IMAGE=nvidia/cuda:12.4.1-cudnn-runtime-ubuntu22.04 + # cache-from: type=gha + # cache-to: type=gha,mode=max diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c82821d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,51 @@ +ARG BASE_IMAGE +FROM ${BASE_IMAGE} AS builder + +RUN apt-get update && apt-get install -y --no-install-recommends \ + git \ + build-essential \ + python3 \ + python3-venv \ + python3-dev \ + && python3 -m venv /opt/venv \ + && . /opt/venv/bin/activate \ + && pip install --no-cache-dir --upgrade pip \ + && pip install --no-cache-dir boltz \ + && apt-get purge -y git build-essential \ + && apt-get autoremove -y \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* + +FROM ${BASE_IMAGE} + +COPY --from=builder /opt/venv /opt/venv + +RUN apt-get update && apt-get install -y --no-install-recommends \ + python3 \ + && apt-get autoremove -y \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* + +ENV PATH="/opt/venv/bin:$PATH" \ + LANG=C.UTF-8 \ + PYTHONUNBUFFERED=1 + +ARG USERNAME=boltz +ARG UID=900 +ARG GID=900 +RUN groupadd --gid $GID $USERNAME && \ + useradd --uid $UID --gid $GID --create-home --shell /bin/bash $USERNAME + +WORKDIR /app + +COPY LICENSE /app/LICENSE +COPY README.md /app/README.md +COPY examples /app/examples +COPY scripts /app/scripts +COPY docs /app/docs + +RUN chown -R $USERNAME:$USERNAME /app + +USER $USERNAME + +ENTRYPOINT ["boltz"]