ejschwartz commited on
Commit
0c0a612
·
verified ·
1 Parent(s): 9a441ca

Try micromamba

Browse files
Files changed (1) hide show
  1. Dockerfile +27 -22
Dockerfile CHANGED
@@ -1,16 +1,12 @@
1
  # read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
2
- # you will also find guides on how best to write your Dockerfile
3
-
4
  FROM python:3.9
5
 
6
  WORKDIR /code
7
 
8
  # Set up a new user named "user" with user ID 1000
9
  RUN useradd -m -u 1000 user
10
-
11
  # Switch to the "user" user
12
  USER user
13
-
14
  # Set home to the user's home directory
15
  ENV HOME=/home/user \
16
  PATH=/home/user/.local/bin:$PATH
@@ -18,35 +14,44 @@ ENV HOME=/home/user \
18
  # Set the working directory to the user's home directory
19
  WORKDIR $HOME/app
20
 
21
- # Install conda
 
 
22
  RUN set -ex; \
23
  ARCH=$(uname -m); \
24
  if [ "$ARCH" = "x86_64" ]; then \
25
- URL="https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh"; \
26
  elif [ "$ARCH" = "aarch64" ]; then \
27
- URL="https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-aarch64.sh"; \
28
  else \
29
  echo "Unsupported architecture: $ARCH"; exit 1; \
30
  fi; \
31
- echo "Downloading Miniconda installer for $ARCH from $URL"; \
32
- mkdir -p ~/miniconda3; \
33
- wget --quiet "$URL" -O ~/miniconda3/miniconda.sh; \
34
- bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3; \
35
- rm ~/miniconda3/miniconda.sh
36
- ENV PATH="$HOME/miniconda3/bin:${PATH}"
37
-
38
- RUN --mount=type=secret,id=GH_TOKEN,mode=0444,required=true \
39
- git clone https://$(cat /run/secrets/GH_TOKEN)@github.com/squaresLab/idioms
40
 
41
- RUN conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/main && \
42
- conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/r
43
 
44
- # solver uses too much memory
45
- RUN conda config --set solver libmamba
 
46
 
47
- RUN conda env create -f idioms/env.yml
 
 
 
 
48
 
49
- ENV PATH="/home/user/miniconda3/envs/idioms/bin:${PATH}"
 
 
50
  ENV PYTHONPATH="${PYTHONPATH}:${HOME}/app/idioms"
51
 
52
  # Install the gradio app's requirements too
 
1
  # read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
 
 
2
  FROM python:3.9
3
 
4
  WORKDIR /code
5
 
6
  # Set up a new user named "user" with user ID 1000
7
  RUN useradd -m -u 1000 user
 
8
  # Switch to the "user" user
9
  USER user
 
10
  # Set home to the user's home directory
11
  ENV HOME=/home/user \
12
  PATH=/home/user/.local/bin:$PATH
 
14
  # Set the working directory to the user's home directory
15
  WORKDIR $HOME/app
16
 
17
+ # --- CHANGED: Install Micromamba instead of Miniconda ---
18
+ # Micromamba is a single binary (C++) that uses significantly less RAM than Conda + Python
19
+ USER root
20
  RUN set -ex; \
21
  ARCH=$(uname -m); \
22
  if [ "$ARCH" = "x86_64" ]; then \
23
+ URL="https://micro.mamba.pm/api/micromamba/linux-64/latest"; \
24
  elif [ "$ARCH" = "aarch64" ]; then \
25
+ URL="https://micro.mamba.pm/api/micromamba/linux-aarch64/latest"; \
26
  else \
27
  echo "Unsupported architecture: $ARCH"; exit 1; \
28
  fi; \
29
+ # Install curl/tar if missing (python:3.9 usually has them, but good practice)
30
+ apt-get update && apt-get install -y curl tar bzip2 && rm -rf /var/lib/apt/lists/*; \
31
+ # Download and extract binary to /bin/micromamba
32
+ curl -Ls "$URL" | tar -xvj -C /usr/local/bin/ --strip-components=1 bin/micromamba; \
33
+ # Ensure it's executable
34
+ chmod +x /usr/local/bin/micromamba
35
+
36
+ # Switch back to user
37
+ USER user
38
 
39
+ # Configure Micromamba root location
40
+ ENV MAMBA_ROOT_PREFIX=/home/user/micromamba
41
 
42
+ # Clone the repo
43
+ RUN --mount=type=secret,id=GH_TOKEN,mode=0444,required=true \
44
+ git clone https://$(cat /run/secrets/GH_TOKEN)@github.com/squaresLab/idioms
45
 
46
+ # --- CHANGED: Create environment using Micromamba ---
47
+ # Note: We removed 'conda tos accept' because Micromamba handles this differently/implicitly
48
+ # We use 'create' to make the env named 'idioms'
49
+ RUN micromamba create -y -n idioms -f idioms/env.yml && \
50
+ micromamba clean --all --yes
51
 
52
+ # --- CHANGED: Update PATH to point to Micromamba env ---
53
+ # Micromamba puts envs in $MAMBA_ROOT_PREFIX/envs
54
+ ENV PATH="${MAMBA_ROOT_PREFIX}/envs/idioms/bin:${PATH}"
55
  ENV PYTHONPATH="${PYTHONPATH}:${HOME}/app/idioms"
56
 
57
  # Install the gradio app's requirements too