File size: 4,504 Bytes
bdec7a9
 
 
 
0f49f60
 
bdec7a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
938155a
bdec7a9
 
 
 
 
 
938155a
 
 
 
bdec7a9
 
 
 
 
 
 
 
 
e0aa8d5
 
 
bdec7a9
 
 
e0aa8d5
 
bdec7a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
############################################################
# Huggingβ€―Face Space β€” AmazonΒ LinuxΒ 2023 + Python 3.12 + JupyterΒ Lab
############################################################

FROM amazonlinux:2023

# ─────────────────────────────
# 0️⃣  Environment variables
# ─────────────────────────────
ENV TZ=Europe/Paris \
    LANG=en_US.UTF-8 \
    LC_ALL=en_US.UTF-8 \
    PYTHONUNBUFFERED=1

# ─────────────────────────────
# 1️⃣  System packages + Python 3.12
# ─────────────────────────────
RUN yum -y update && \
    yum -y install --allowerasing \
      sudo \
      curl-minimal \
      wget \
      git \
      unzip \
      zip \
      which \
      tar \
      shadow-utils \
      procps-ng \
      nano \
      vim \
      bzip2 \
      gcc \
      gcc-c++ \
      make \
      glibc-langpack-en \
      libX11 \
      openssl \
      ca-certificates \
      libsndfile \
      python3.12 \
      python3.12-pip && \
    yum clean all && \
    alternatives --install /usr/bin/python python /usr/bin/python3.12 1 && \
    alternatives --install /usr/bin/pip pip /usr/bin/pip3.12 1

# ─────────────────────────────
# 2️⃣  Node.js 21 + configurable-http-proxy
# ─────────────────────────────
RUN curl -sL https://rpm.nodesource.com/setup_21.x | bash - && \
    yum install -y nodejs && \
    npm install -g configurable-http-proxy && \
    yum clean all

# ─────────────────────────────
# 3️⃣  Create non‑root user
# ─────────────────────────────
RUN useradd -m user && echo "user ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/90-user

ENV HOME=/home/user
USER user

# >>> ADD THIS LINE <<<
ENV PATH="$HOME/.local/bin:$PATH"


# ─────────────────────────────
# 4️⃣  Workspace & working directory
# ─────────────────────────────
RUN mkdir -p $HOME/app $HOME/.cache $HOME/.config && chmod -R 777 $HOME
WORKDIR $HOME/app

# ─────────────────────────────
# 5️⃣  Install Python packages (including JupyterLab)
# ─────────────────────────────
# ─────────────────────────────
# 5️⃣  Install Python packages (including JupyterLab + Ansible)
# ─────────────────────────────
COPY --chown=user requirements.txt ./requirements.txt
RUN pip install --no-cache-dir --upgrade pip && \
    pip install --no-cache-dir -r requirements.txt && \
    pip install --no-cache-dir jupyterlab ansible-core


# ─────────────────────────────
# 6️⃣  Extra packages + startup logic (as root)
# ─────────────────────────────
USER root

COPY packages.txt /root/packages.txt
RUN xargs -r -a /root/packages.txt yum install -y && yum clean all

COPY on_startup.sh /root/on_startup.sh
RUN chmod +x /root/on_startup.sh && /root/on_startup.sh

RUN mkdir -p /data && chown user:user /data

# ─────────────────────────────
# 7️⃣  Copy project files
# ─────────────────────────────
USER user
COPY --chown=user . $HOME/app

# Optional: override Jupyter login UI
COPY --chown=user login.html /home/user/.local/lib/python3.12/site-packages/jupyter_server/templates/login.html

RUN chmod +x start_server.sh

# ─────────────────────────────
# 8️⃣  Runtime Environment
# ─────────────────────────────
ENV GRADIO_ALLOW_FLAGGING=never \
    GRADIO_NUM_PORTS=1 \
    GRADIO_SERVER_NAME=0.0.0.0 \
    GRADIO_THEME=huggingface \
    SYSTEM=spaces

# πŸš€ Launch JupyterLab on $PORT (required by Hugging Face)
CMD ["./start_server.sh"]