From cfcb58187e016287280aa2501732c38ea5d0c518 Mon Sep 17 00:00:00 2001 From: danellecline Date: Fri, 19 Jul 2024 15:05:12 -0700 Subject: [PATCH] ci: simplified docker build within pypi size limits with pip build and renamed accidentally commited backup file --- .github/workflows/release.yml | 5 +-- docker/Dockerfile | 31 +++++++++++++++++ docker/Dockerfile.bak | 59 -------------------------------- docker/Dockerfile.cuda | 39 ++++++++++++++++++++++ docker/Dockerfile.cuda12 | 63 ----------------------------------- pyproject.toml | 1 + 6 files changed, 74 insertions(+), 124 deletions(-) create mode 100644 docker/Dockerfile delete mode 100644 docker/Dockerfile.bak create mode 100755 docker/Dockerfile.cuda delete mode 100644 docker/Dockerfile.cuda12 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2367047..4821907 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -25,6 +25,7 @@ jobs: pip install poetry poetry config pypi-token.pypi ${{ secrets.PYPI_API_TOKEN }} poetry publish --build + poetry publish - name: docker push version if: steps.semantic.outputs.released == 'true' @@ -33,8 +34,8 @@ jobs: docker login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_TOKEN }} docker buildx create --name mybuilder --platform linux/amd64,linux/arm64 --use cd docker && \ - docker buildx build --push --platform linux/amd64 -t mbari/sdcat:$RELEASE_VERSION-cuda124 --label IMAGE_URI=mbari/sdcat:$RELEASE_VERSION-cuda124 -f Dockerfile.cuda12 . - docker buildx build --push --platform linux/amd64,linux/arm64 -t mbari/sdcat:$RELEASE_VERSION --label IMAGE_URI=mbari/sdcat:$RELEASE_VERSION -f Dockerfile . + docker buildx build --push --platform linux/amd64 -t mbari/sdcat:$RELEASE_VERSION-cuda124 --label GIT_VERSION=$RELEASE_VERSION --label IMAGE_URI=mbari/sdcat:$RELEASE_VERSION-cuda124 -f Dockerfile.cuda . + docker buildx build --push --platform linux/amd64,linux/arm64 -t mbari/sdcat:$RELEASE_VERSION --label GIT_VERSION=$RELEASE_VERSION --label IMAGE_URI=mbari/sdcat:$RELEASE_VERSION -f Dockerfile . push_readme_to_dockerhub: runs-on: ubuntu-latest name: Push README to Docker Hub diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..fdda4d2 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,31 @@ +FROM ubuntu:22.04 + +LABEL vendor="MBARI" +LABEL maintainer="dcline@mbari.org" +LABEL license="Apache License 2.0" + +RUN apt-get update && apt-get install -y \ + software-properties-common \ + && apt-get update && apt-get install -y \ + python3.11 \ + python3.11-dev \ + python3.11-distutils \ + python3-pip \ + curl \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + +ARG GIT_VERSION=latest +ARG IMAGE_URI=mbari/sdcat:${GIT_VERSION} + +ENV APP_HOME=/app +ENV PYTHONPATH=${APP_HOME}/sdcat +ENV HF_HOME=/tmp/transformers_cache +WORKDIR ${APP_HOME} +RUN if [ "$GIT_VERSION" != "latest" ]; then \ + python3.11 -m pip install sdcat:${GIT_VERSION}; \ + else \ + python3.11 -m pip install sdcat; \ + fi + +ENTRYPOINT ["sdcat"] diff --git a/docker/Dockerfile.bak b/docker/Dockerfile.bak deleted file mode 100644 index 97c2f39..0000000 --- a/docker/Dockerfile.bak +++ /dev/null @@ -1,59 +0,0 @@ -FROM python:3.11-slim - -LABEL vendor="MBARI" -LABEL maintainer="dcline@mbari.org" -LABEL license="Apache License 2.0" - -ARG GIT_VERSION=latest -ARG IMAGE_URI=mbari/sdcat:${GIT_VERSION} -ARG DOCKER_GID=1001 -ARG DOCKER_UID=1001 - -WORKDIR /app - -RUN set -ex \ - && addgroup --system --gid ${DOCKER_GID} docker \ - && adduser --system --uid ${DOCKER_UID} --gid ${DOCKER_GID} docker_user \ - && apt-get update \ - && apt-get upgrade -y \ - && apt-get install -y git gcc - -RUN if [ "$GIT_VERSION" != "latest" ]; then \ - git clone -b v${GIT_VERSION} --depth 1 https://github.com/mbari-org/sdcat.git; \ - else \ - git clone --depth 1 https://github.com/mbari-org/sdcat.git;\ - fi - -# Install Miniconda since that does a better job of managing torch dependencies than pip -RUN apt-get update && \ - apt-get install -y wget -y libgl1 libglib2.0-0 libsm6 libxrender1 libxext6 && \ - apt-get clean && \ - rm -rf /var/lib/apt/lists/* && \ - arch=$(uname -m) && \ - if [ "$arch" = "x86_64" ]; then \ - MINICONDA_URL="https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh"; \ - elif [ "$arch" = "aarch64" ]; then \ - MINICONDA_URL="https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-aarch64.sh"; \ - else \ - echo "Unsupported architecture: $arch"; \ - exit 1; \ - fi && \ - wget $MINICONDA_URL -O miniconda.sh && \ - mkdir -p /home/docker_user/.conda && \ - bash miniconda.sh -b -p /home/docker_user/miniconda3 && \ - rm -f miniconda.sh - -# Install the application dependencies using Miniconda -WORKDIR /app/sdcat -ENV PATH=/home/docker_user/miniconda3/bin:$PATH -ENV HOME=/home/docker_user -RUN conda env create -f environment.yml \ - && apt-get clean \ - && apt-get remove -y gcc git \ - && rm -rf /var/lib/apt/lists/* - -RUN chown -R docker_user:docker /app/sdcat && \ - chown -R docker_user:docker /home/docker_user -USER docker_user -WORKDIR /app/sdcat -CMD ["conda", "run", "-n", "sdcat", "python", "sdcat"] \ No newline at end of file diff --git a/docker/Dockerfile.cuda b/docker/Dockerfile.cuda new file mode 100755 index 0000000..89738ac --- /dev/null +++ b/docker/Dockerfile.cuda @@ -0,0 +1,39 @@ +FROM nvidia/cuda:12.4.1-cudnn-devel-ubuntu22.04 + +LABEL vendor="MBARI" +LABEL maintainer="dcline@mbari.org" +LABEL license="Apache License 2.0" + +RUN apt-get update && apt-get install -y \ + build-essential \ + cmake \ + git \ + wget \ + curl \ + && rm -rf /var/lib/apt/lists/* + +RUN apt-get update && apt-get install -y \ + python3 \ + python3-pip \ + && rm -rf /var/lib/apt/lists/* + +ARG GIT_VERSION=latest +ARG IMAGE_URI=mbari/sdcat:${GIT_VERSION} + +ENV APP_HOME=/app +ENV PYTHONPATH=${APP_HOME}/sdcat +ENV HF_HOME=/tmp/transformers_cache +WORKDIR ${APP_HOME} +RUN if [ "$GIT_VERSION" != "latest" ]; then \ + python3 -m pip install sdcat:${GIT_VERSION}; \ + else \ + python3 -m pip install sdcat; \ + fi + +RUN chmod a+rwx ${APP_HOME} +ENV HOME=${APP_HOME} +ENV NUMBA_CACHE_DIR=/tmp +WORKDIR ${APP_HOME} +RUN python3 -m pip install --upgrade pip && \ + python3 -m pip install torch torchvision --index-url https://download.pytorch.org/whl/cu121 +ENTRYPOINT ["sdcat"] diff --git a/docker/Dockerfile.cuda12 b/docker/Dockerfile.cuda12 deleted file mode 100644 index e07560f..0000000 --- a/docker/Dockerfile.cuda12 +++ /dev/null @@ -1,63 +0,0 @@ -FROM pytorch/pytorch:2.3.1-cuda12.1-cudnn8-runtime - -LABEL vendor="MBARI" -LABEL maintainer="dcline@mbari.org" -LABEL license="Apache License 2.0" - -ARG GIT_VERSION=latest -ARG IMAGE_URI=mbari/sdcat:${GIT_VERSION} -ARG DOCKER_GID=1001 -ARG DOCKER_UID=1001 - -ENV DEBIAN_FRONTEND=noninteractive - -RUN apt-get update && apt-get install -y \ - build-essential \ - cmake \ - git \ - wget \ - libgl1 \ - libglib2.0-0 \ - && addgroup --gid ${DOCKER_GID} docker \ - && adduser --uid ${DOCKER_UID} --gid ${DOCKER_GID} --disabled-password --shell /bin/bash --gecos "Docker" docker_user \ - && rm -rf /var/lib/apt/lists/* - -WORKDIR /app -RUN if [ "$GIT_VERSION" != "latest" ]; then \ - git clone -b v${GIT_VERSION} --depth 1 https://github.com/mbari-org/sdcat.git; \ - else \ - git clone --depth 1 https://github.com/mbari-org/sdcat.git;\ - fi - -# Install Miniconda since that does a better job of managing torch dependencies than pip -RUN apt-get update && \ - apt-get install -y wget -y libgl1 libglib2.0-0 libsm6 libxrender1 libxext6 && \ - apt-get clean && \ - rm -rf /var/lib/apt/lists/* && \ - arch=$(uname -m) && \ - if [ "$arch" = "x86_64" ]; then \ - MINICONDA_URL="https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh"; \ - elif [ "$arch" = "aarch64" ]; then \ - MINICONDA_URL="https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-aarch64.sh"; \ - else \ - echo "Unsupported architecture: $arch"; \ - exit 1; \ - fi && \ - wget $MINICONDA_URL -O miniconda.sh && \ - mkdir -p /home/docker_user/.conda && \ - bash miniconda.sh -b -p /home/docker_user/miniconda3 && \ - rm -f miniconda.sh - -# Install the application dependencies using Miniconda -WORKDIR /app/sdcat -ENV PATH=/home/docker_user/miniconda3/bin:$PATH -ENV HOME=/home/docker_user -RUN conda env create -f environment.yml - -RUN chown -R docker_user:docker /app/sdcat && \ - chown -R docker_user:docker /home/docker_user -RUN rm -rf /app/sdcat/.git && rm -rf /app/sdcat/sdcat/tests - -USER docker_user -WORKDIR /app/sdcat -CMD ["conda", "run", "-n", "sdcat", "python", "sdcat"] diff --git a/pyproject.toml b/pyproject.toml index 4482266..4ededf9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -36,6 +36,7 @@ readme = "README.md" packages = [ { include = "sdcat" } ] +exclude = ["sdcat/tests"] [tool.poetry.scripts] sdcat = "sdcat.__main__:cli"