From a127d2e302a7831a13f31f16c837e9140a6b0c40 Mon Sep 17 00:00:00 2001 From: Maksym Sobolyev Date: Wed, 17 Jul 2024 16:08:16 -0700 Subject: [PATCH] Add simple pipeline to install dependencies and build a docker image for Nvidia and Intel HW. --- .github/workflows/main.yml | 83 ++++++++++++++++++++++++++++++++++ docker/Dockerfile | 31 +++++++++++++ docker/install_conda.sh | 13 ++++++ docker/install_requirements.sh | 35 ++++++++++++++ 4 files changed, 162 insertions(+) create mode 100644 .github/workflows/main.yml create mode 100644 docker/Dockerfile create mode 100755 docker/install_conda.sh create mode 100755 docker/install_requirements.sh diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..fb89f8f --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,83 @@ +# This is a basic workflow to help you get started with Actions + +name: Build & Publush + +# Controls when the action will run. +on: + # Triggers the workflow on all push or pull request events + push: + pull_request: + + release: + types: [created] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + + schedule: + - cron: "0 0 * * *" + +# added using https://github.com/step-security/secure-repo +permissions: + contents: read + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + Docker: + name: Build&Push to DockerHub + if: (github.event_name == 'push' || github.event_name == 'pull_request') + runs-on: ubuntu-latest + strategy: + matrix: + infer-hw: ['nvidia', 'intel'] + env: + DOCKER_REPO: 'sippylabs/infernos' + BASE_IMAGE: 'ubuntu:24.10' + PYTHON_VER: '3.11' + CONDA_MAINENV: 'Infernos' + INFER_HW: ${{ matrix.infer-hw }} + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + submodules: 'recursive' + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to Docker Hub + if: github.event_name != 'pull_request' + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.DOCKER_REPO }} + tags: | + type=schedule + type=ref,event=branch,prefix=${{ env.INFER_HW }}- + type=ref,event=tag,prefix=${{ env.INFER_HW }}- + type=ref,event=pr,prefix=${{ env.INFER_HW }}- + type=raw,value=${{ env.INFER_HW }}-latest,enable={{is_default_branch}} + type=sha + + - name: Build Docker image + uses: docker/build-push-action@v6 + with: + context: . + file: ./docker/Dockerfile + push: true + build-args: | + BASE_IMAGE=${{ env.BASE_IMAGE }} + PYTHON_VER=${{ env.PYTHON_VER }} + CONDA_MAINENV=${{ env.CONDA_MAINENV }} + INFER_HW=${{ env.INFER_HW }} + tags: | + ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..3515b85 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,31 @@ +# syntax=docker/dockerfile:1.7-labs + +ARG BASE_IMAGE=ubuntu:24.10 +FROM $BASE_IMAGE AS build +LABEL maintainer="Maksym Sobolyev " + +USER root + +ARG PYTHON_VER +ARG CONDA_MAINENV +ARG INFER_HW +ARG APT_INSTALL="apt-get install --no-install-recommends -y" +ARG APT_CLEAN="apt-get clean" + +# Set Environment Variables +ENV DEBIAN_FRONTEND=noninteractive +ENV PYTHON_VER=${PYTHON_VER} +ENV CONDA_MAINENV=${CONDA_MAINENV} + +# Build & install everything +WORKDIR /tmp +RUN apt-get update +RUN ${APT_INSTALL} lsb-release ca-certificates && ${APT_CLEAN} +COPY docker/install_conda.sh . +RUN ./install_conda.sh +COPY docker/install_requirements.sh requirements.txt . +RUN ./install_requirements.sh + +COPY --exclude=.git --exclude=.github --link . /Infernos +ENV CONDA_ACTIVATE=". /opt/conda/etc/profile.d/conda.sh && conda activate ${CONDA_MAINENV}" +WORKDIR /Infernos diff --git a/docker/install_conda.sh b/docker/install_conda.sh new file mode 100755 index 0000000..a759b7b --- /dev/null +++ b/docker/install_conda.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +set -e +set -x + +${APT_INSTALL} curl gpg +curl https://repo.anaconda.com/pkgs/misc/gpgkeys/anaconda.asc | gpg --dearmor > /usr/share/keyrings/conda-archive-keyring.gpg + +echo "deb [arch=amd64 signed-by=/usr/share/keyrings/conda-archive-keyring.gpg] https://repo.anaconda.com/pkgs/misc/debrepo/conda stable main" > /etc/apt/sources.list.d/conda.list + +apt update +${APT_INSTALL} conda +${APT_CLEAN} diff --git a/docker/install_requirements.sh b/docker/install_requirements.sh new file mode 100755 index 0000000..d1ba1ac --- /dev/null +++ b/docker/install_requirements.sh @@ -0,0 +1,35 @@ +#!/bin/sh + +set -e +set -x + +PYTHON_CMD="python${PYTHON_VER}" +DEV_PKGS="gcc g++ libc6-dev cmake pkg-config make git" +PIP_INSTALL="${PYTHON_CMD} -m pip install -U" + +${APT_INSTALL} ${DEV_PKGS} +. /opt/conda/etc/profile.d/conda.sh +conda create -y --name "${CONDA_MAINENV}" python=${PYTHON_VER} +conda activate "${CONDA_MAINENV}" +conda install -y pip +${PIP_INSTALL} -r requirements.txt + +case "${INFER_HW}" in +nvidia) + ;; +intel) + ${PIP_INSTALL} torch==2.1.0.post2 torchvision==0.16.0.post2 torchaudio==2.1.0.post2 \ + intel-extension-for-pytorch==2.1.30.post0 oneccl_bind_pt==2.1.300+xpu \ + --extra-index-url https://pytorch-extension.intel.com/release-whl/stable/xpu/us/ + ;; +*) + echo "Unknown INFER_HW: '${INFER_HW}'" >&2 + false + ;; +esac + +apt-get remove -y ${DEV_PKGS} +apt-get autoremove -y +${APT_CLEAN} +rm -r ~/.cache +mkdir ~/.cache