Tony-ooo commited on
Commit
5b07490
·
1 Parent(s): 182412f

Merge Space

Browse files
Files changed (7) hide show
  1. Dockerfile +107 -0
  2. README.md +23 -4
  3. login.html +212 -0
  4. on_startup.sh +4 -0
  5. packages.txt +9 -0
  6. requirements.txt +1 -0
  7. start_server.sh +22 -0
Dockerfile ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM nvidia/cuda:12.5.1-cudnn-devel-ubuntu20.04
2
+
3
+ ENV DEBIAN_FRONTEND=noninteractive \
4
+ TZ=Europe/Paris
5
+
6
+ # Remove any third-party apt sources to avoid issues with expiring keys.
7
+ # Install some basic utilities
8
+ RUN rm -f /etc/apt/sources.list.d/*.list && \
9
+ apt-get update && apt-get install -y --no-install-recommends \
10
+ curl \
11
+ ca-certificates \
12
+ sudo \
13
+ git \
14
+ wget \
15
+ procps \
16
+ git-lfs \
17
+ zip \
18
+ unzip \
19
+ htop \
20
+ vim \
21
+ nano \
22
+ bzip2 \
23
+ libx11-6 \
24
+ build-essential \
25
+ libsndfile-dev \
26
+ software-properties-common \
27
+ gnupg \
28
+ && rm -rf /var/lib/apt/lists/*
29
+
30
+ RUN add-apt-repository ppa:flexiondotorg/nvtop && \
31
+ apt-get upgrade -y && \
32
+ apt-get install -y --no-install-recommends nvtop
33
+
34
+ RUN curl -sL https://deb.nodesource.com/setup_21.x | bash - && \
35
+ apt-get install -y nodejs && \
36
+ npm install -g configurable-http-proxy
37
+
38
+ # Install VSCode Server
39
+ RUN curl -fsSL https://code-server.dev/install.sh | sh
40
+
41
+ # Create a working directory
42
+ WORKDIR /app
43
+
44
+ # Create a non-root user and switch to it
45
+ RUN adduser --disabled-password --gecos '' --shell /bin/bash user \
46
+ && chown -R user:user /app
47
+ RUN echo "user ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/90-user
48
+ USER user
49
+
50
+ # All users can use /home/user as their home directory
51
+ ENV HOME=/home/user
52
+ RUN mkdir $HOME/.cache $HOME/.config \
53
+ && chmod -R 777 $HOME
54
+
55
+ # Set up the Conda environment
56
+ ENV CONDA_AUTO_UPDATE_CONDA=false \
57
+ PATH=$HOME/miniconda/bin:$PATH
58
+ RUN curl -sLo ~/miniconda.sh https://repo.continuum.io/miniconda/Miniconda3-py39_4.10.3-Linux-x86_64.sh \
59
+ && chmod +x ~/miniconda.sh \
60
+ && ~/miniconda.sh -b -p ~/miniconda \
61
+ && rm ~/miniconda.sh \
62
+ && conda clean -ya
63
+
64
+ WORKDIR $HOME/app
65
+
66
+ #######################################
67
+ # Start root user section
68
+ #######################################
69
+
70
+ USER root
71
+
72
+ # User Debian packages
73
+ ## Security warning : Potential user code executed as root (build time)
74
+ RUN --mount=target=/root/packages.txt,source=packages.txt \
75
+ apt-get update && \
76
+ xargs -r -a /root/packages.txt apt-get install -y --no-install-recommends \
77
+ && rm -rf /var/lib/apt/lists/*
78
+
79
+ RUN --mount=target=/root/on_startup.sh,source=on_startup.sh,readwrite \
80
+ bash /root/on_startup.sh
81
+
82
+ RUN mkdir /data && chown user:user /data
83
+
84
+ #######################################
85
+ # End root user section
86
+ #######################################
87
+
88
+ USER user
89
+
90
+ # Python packages
91
+ RUN --mount=target=requirements.txt,source=requirements.txt \
92
+ pip install --no-cache-dir --upgrade -r requirements.txt
93
+
94
+ # Copy the current directory contents into the container at $HOME/app setting the owner to the user
95
+ COPY --chown=user . $HOME/app
96
+
97
+ RUN chmod +x start_server.sh
98
+
99
+ ENV PYTHONUNBUFFERED=1 \
100
+ GRADIO_ALLOW_FLAGGING=never \
101
+ GRADIO_NUM_PORTS=1 \
102
+ GRADIO_SERVER_NAME=0.0.0 \
103
+ GRADIO_THEME=huggingface \
104
+ SYSTEM=spaces \
105
+ SHELL=/bin/bash
106
+
107
+ CMD ["./start_server.sh"]
README.md CHANGED
@@ -1,10 +1,29 @@
1
  ---
2
- title: Vscode
3
- emoji: 🔥
4
- colorFrom: pink
5
- colorTo: blue
6
  sdk: docker
7
  pinned: false
 
 
 
 
8
  ---
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: VSCode
3
+ emoji: 💻🐳
4
+ colorFrom: blue
5
+ colorTo: purple
6
  sdk: docker
7
  pinned: false
8
+ tags:
9
+ - vscode
10
+ - ide
11
+ suggested_storage: small
12
  ---
13
 
14
+ # VSCode on Hugging Face Spaces
15
+
16
+ This space runs VSCode in a Docker container with a web interface.
17
+
18
+ ## Features
19
+ - Full VSCode web interface
20
+ - Pre-installed development tools
21
+ - GPU support (if available)
22
+ - Customizable environment
23
+
24
+ ## Usage
25
+ 1. Click the "Run" button to start the space
26
+ 2. Access VSCode through the generated URL
27
+ 3. Default password/token is `huggingface`
28
+
29
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
login.html ADDED
@@ -0,0 +1,212 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {% extends "page.html" %}
2
+
3
+ {% block stylesheet %}
4
+ <style>
5
+ body {
6
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
7
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
8
+ margin: 0;
9
+ padding: 0;
10
+ min-height: 100vh;
11
+ display: flex;
12
+ align-items: center;
13
+ justify-content: center;
14
+ }
15
+
16
+ .login-container {
17
+ background: white;
18
+ border-radius: 10px;
19
+ box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
20
+ padding: 40px;
21
+ text-align: center;
22
+ max-width: 400px;
23
+ width: 90%;
24
+ }
25
+
26
+ .logo {
27
+ margin-bottom: 30px;
28
+ }
29
+
30
+ .logo img {
31
+ max-width: 200px;
32
+ }
33
+
34
+ h4 {
35
+ color: #333;
36
+ margin-bottom: 10px;
37
+ font-size: 24px;
38
+ font-weight: 600;
39
+ }
40
+
41
+ h5 {
42
+ color: #666;
43
+ margin-bottom: 30px;
44
+ font-size: 16px;
45
+ font-weight: 400;
46
+ }
47
+
48
+ .token-info {
49
+ background: #f8f9fa;
50
+ border-radius: 8px;
51
+ padding: 15px;
52
+ margin: 20px 0;
53
+ border-left: 4px solid #667eea;
54
+ }
55
+
56
+ .token-value {
57
+ color: #667eea;
58
+ font-weight: 600;
59
+ font-size: 18px;
60
+ letter-spacing: 1px;
61
+ }
62
+
63
+ .form-group {
64
+ margin-bottom: 20px;
65
+ text-align: left;
66
+ }
67
+
68
+ label {
69
+ display: block;
70
+ margin-bottom: 8px;
71
+ color: #333;
72
+ font-weight: 500;
73
+ }
74
+
75
+ input[type="password"] {
76
+ width: 10%;
77
+ padding: 12px 15px;
78
+ border: 2px solid #e9ecef;
79
+ border-radius: 6px;
80
+ font-size: 16px;
81
+ transition: border-color 0.3s;
82
+ box-sizing: border-box;
83
+ }
84
+
85
+ input[type="password"]:focus {
86
+ outline: none;
87
+ border-color: #667eea;
88
+ }
89
+
90
+ .btn {
91
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
92
+ color: white;
93
+ border: none;
94
+ padding: 12px 30px;
95
+ border-radius: 6px;
96
+ font-size: 16px;
97
+ font-weight: 500;
98
+ cursor: pointer;
99
+ width: 100%;
100
+ transition: transform 0.2s, box-shadow 0.2s;
101
+ }
102
+
103
+ .btn:hover {
104
+ transform: translateY(-2px);
105
+ box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
106
+ }
107
+
108
+ .info-text {
109
+ margin-top: 25px;
110
+ color: #666;
111
+ font-size: 14px;
112
+ line-height: 1.5;
113
+ }
114
+
115
+ .info-text a {
116
+ color: #667eea;
117
+ text-decoration: none;
118
+ }
119
+
120
+ .info-text a:hover {
121
+ text-decoration: underline;
122
+ }
123
+
124
+ .footer {
125
+ margin-top: 30px;
126
+ color: #888;
127
+ font-size: 12px;
128
+ }
129
+ </style>
130
+ {% endblock %}
131
+
132
+ {% block site %}
133
+ <div class="login-container">
134
+ <div class="logo">
135
+ <svg width="120" height="120" viewBox="0 0 120 120" xmlns="http://www.w3.org/2000/svg">
136
+ <rect x="20" y="20" width="80" height="80" rx="8" fill="#24AEF9"/>
137
+ <path d="M40 40 L80 40 L80 80 L40 80 Z" fill="#1E90FF"/>
138
+ <path d="M50 50 L70 50 L70 70 L50 70 Z" fill="white"/>
139
+ <circle cx="60" cy="60" r="8" fill="#24AEF9"/>
140
+ </svg>
141
+ </div>
142
+
143
+ <h4>Welcome to VSCode</h4>
144
+ <h5>Code Anywhere, Anytime</h5>
145
+
146
+ <div class="token-info">
147
+ <strong>Default Token:</strong>
148
+ <div class="token-value">huggingface</div>
149
+ </div>
150
+
151
+ {% if login_available %}
152
+ <div class="row">
153
+ <div class="col-sm-12">
154
+ <form action="{{base_url}}login?next={{next}}" method="post" class="form">
155
+ {{ xsrf_form_html() | safe }}
156
+ <div class="form-group">
157
+ {% if token_available %}
158
+ <label for="password_input">Enter VSCode Token <span title="This is the secret you set up when deploying your VSCode space">ⓘ</span></label>
159
+ {% else %}
160
+ <label for="password_input">VSCode Password:</label>
161
+ {% endif %}
162
+ <input type="password" name="password" id="password_input" class="form-control" placeholder="Enter your token..." required>
163
+ </div>
164
+ <button type="submit" class="btn" id="login_submit">Access VSCode</button>
165
+ </form>
166
+ </div>
167
+ {% else %}
168
+ <p>No login available, you shouldn't be seeing this page.</p>
169
+ {% endif %}
170
+
171
+ <div class="info-text">
172
+ <p>If you don't have the credentials for this VSCode space,
173
+ <a href="https://huggingface.co/spaces/SpacesExamples/vscode?duplicate=true" target="_blank">create your own.</a>
174
+ </p>
175
+ </div>
176
+
177
+ <div class="footer">
178
+ <p>Powered by Hugging Face Spaces</p>
179
+ </div>
180
+
181
+ {% if message %}
182
+ <div class="row">
183
+ {% for key in message %}
184
+ <div class="message {{key}}">
185
+ {{message[key]}}
186
+ </div>
187
+ {% endfor %}
188
+ </div>
189
+ {% endif %}
190
+ </div>
191
+ {% endblock %}
192
+
193
+ {% block script %}
194
+ <script>
195
+ document.addEventListener('DOMContentLoaded', function() {
196
+ const passwordInput = document.getElementById('password_input');
197
+ const loginForm = document.querySelector('form');
198
+
199
+ loginForm.addEventListener('submit', function(e) {
200
+ if (!passwordInput.value.trim()) {
201
+ e.preventDefault();
202
+ alert('Please enter a token');
203
+ passwordInput.focus();
204
+ return false;
205
+ }
206
+ });
207
+
208
+ // Auto-focus on password field
209
+ passwordInput.focus();
210
+ });
211
+ </script>
212
+ {% endblock %}
on_startup.sh ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ #!/bin/bash
2
+ # Write some commands here that will run on root user before startup.
3
+ # For example, to install additional system packages or set up environment:
4
+ # apt-get update && apt-get install -y some-package
packages.txt ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ tree
2
+ git
3
+ wget
4
+ curl
5
+ vim
6
+ nano
7
+ htop
8
+ zip
9
+ unzip
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ # Python packages for VSCode environment
start_server.sh ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ VSCODE_TOKEN="${VSCODE_TOKEN:=huggingface}"
3
+
4
+ # Create data directory if it doesn't exist
5
+ mkdir -p /data
6
+
7
+ # Generate code-server config
8
+ mkdir -p ~/.config/code-server
9
+ cat > ~/.config/code-server/config.yaml << EOF
10
+ bind-addr: 0.0.0.0:7860
11
+ auth: password
12
+ password: $VSCODE_TOKEN
13
+ cert: false
14
+ EOF
15
+
16
+ # Start code-server with proper configuration
17
+ code-server \
18
+ --bind-addr 0.0.0.0:7860 \
19
+ --auth password \
20
+ --password $VSCODE_TOKEN \
21
+ --cert false \
22
+ /data