| # Documentation: https://huggingface.co/docs/hub/spaces-sdks-docker | |
| FROM python:3.9 | |
| # Create a non-root user and allow them to have appropriate permissions | |
| # on our Space content | |
| RUN useradd -m -u 1000 user | |
| COPY --chown=user ./requirements.txt /requirements.txt | |
| COPY --chown=user ./train.sh /train.sh | |
| COPY --chown=user ./upload_results.py /upload_results.py | |
| COPY --chown=user ./pause_space.py /pause_space.py | |
| RUN chmod +x /train.sh | |
| # May not need to do this. Just tired of permissions errors and going wild. | |
| RUN chmod +x /upload_results.py | |
| RUN chmod +x /pause_space.py | |
| # Make the working directory for user. | |
| RUN mkdir /app | |
| # Start installing stuff as root so it doesn't complain about install permissions. | |
| #RUN pip install --no-cache-dir --upgrade pip | |
| RUN pip install --no-cache-dir --upgrade -r /requirements.txt | |
| # Clone into the working directory for the user. | |
| RUN git clone https://github.com/lee-ny/teaching_arithmetic.git /app/teaching_arithmetic | |
| #&& cd teaching_arithmetic && pip install -e . | |
| # Copy all files we have into the user's working directory. | |
| COPY --chown=user . /app | |
| # Kept getting permission denied errors when running train.py, which tries to | |
| # create the out directory. Just doing this to try to help that. | |
| RUN mkdir /app/teaching_arithmetic/out | |
| RUN chmod -R 777 /app/ | |
| # Switch to the user profile. | |
| # This will help make sure the permissions of the cloned git stuff | |
| # don't require root privileges (I am guessing). | |
| USER user | |
| # Switch to the /app working directory. | |
| WORKDIR /app | |
| # Permissions. Permissions. Already did this. Doing it again anyway. | |
| RUN chmod +x train.sh | |
| RUN chmod +x upload_results.py | |
| RUN chmod +x pause_space.py | |
| # Expose the secret so it can be used later. | |
| RUN --mount=type=secret,id=DATACOMP_TOKEN | |
| #,mode=0444,required=true \ | |
| # Could also use CMD. Example: | |
| # CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"] | |
| ENTRYPOINT ["/train.sh"] | |
| # Keeping these as FYI, commented out, as they are other things we could do. | |
| #ENV PATH="/home/user/.local/bin:/opt/conda/bin:$PATH" | |
| #ENV HOME="/home/user" | |
| #WORKDIR $HOME/app | |
| # We now install with requirements.txt | |
| #ARG PYTORCH_VERSION=2.1.0 | |
| #ARG PYTHON_VERSION=3.9 #8.10 | |
| #ARG CUDA_VERSION=11.8 | |
| #ARG CU_DNN=8.5.0.96 | |
| #ARG MAMBA_VERSION=24.3.0-0 | |
| #ARG CUDA_CHANNEL=nvidia | |
| #ARG INSTALL_CHANNEL=pytorch | |
| # Automatically set by buildx | |
| #ARG TARGETPLATFORM | |
| # Updating basic dependencies we'll be using. | |
| #RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ | |
| # build-essential \ | |
| # ca-certificates \ | |
| # ccache \ | |
| # curl \ | |
| # python3 \ | |
| # python3-pip \ | |
| # git && \ | |
| # rm -rf /var/lib/apt/lists/* | |
| # Installing conda, translating Docker's TARGETPLATFORM into mamba arches | |
| #RUN case ${TARGETPLATFORM} in \ | |
| # "linux/arm64") MAMBA_ARCH=aarch64 ;; \ | |
| # *) MAMBA_ARCH=x86_64 ;; \ | |
| # esac && \ | |
| # curl -fsSL -v -o ~/mambaforge.sh -O "https://github.com/conda-forge/miniforge/releases/download/${MAMBA_VERSION}/Mambaforge-${MAMBA_VERSION}-Linux-${MAMBA_ARCH}.sh" | |
| #RUN chmod +x ~/mambaforge.sh && \ | |
| # bash ~/mambaforge.sh -b -p /opt/conda && \ | |
| # rm ~/mambaforge.sh | |
| # Installing pytorch | |
| # On arm64 we exit with an error code | |
| #RUN case ${TARGETPLATFORM} in \ | |
| # "linux/arm64") exit 1 ;; \ | |
| # *) /opt/conda/bin/conda update -y conda && \ | |
| # /opt/conda/bin/conda install -c "${INSTALL_CHANNEL}" -c "${CUDA_CHANNEL}" -y "python=${PYTHON_VERSION}" "pytorch=$PYTORCH_VERSION" "pytorch-cuda=$(echo $CUDA_VERSION | cut -d'.' -f 1-2)" ;; \ | |
| # esac && \ | |
| # /opt/conda/bin/conda clean -ya | |
| # Expose the secret DEBUG at buildtime and use its value as git remote URL | |
| #RUN --mount=type=secret,id=DEBUG,mode=0444,required=true \ | |
| # git init && \ | |
| # git remote add origin $(cat /run/secrets/DEBUG) | |