weaigc commited on
Commit
8224768
1 Parent(s): 712f818
Files changed (10) hide show
  1. .gitattributes +0 -1
  2. Dockerfile +140 -0
  3. README.md +5 -6
  4. auto-commit.js +36 -0
  5. nginx.conf +111 -0
  6. ngpasswd +0 -0
  7. on_startup.sh +26 -0
  8. packages.txt +1 -0
  9. requirements.txt +3 -0
  10. start_server.sh +50 -0
.gitattributes CHANGED
@@ -25,7 +25,6 @@
25
  *.safetensors filter=lfs diff=lfs merge=lfs -text
26
  saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
  *.tar.* filter=lfs diff=lfs merge=lfs -text
28
- *.tar filter=lfs diff=lfs merge=lfs -text
29
  *.tflite filter=lfs diff=lfs merge=lfs -text
30
  *.tgz filter=lfs diff=lfs merge=lfs -text
31
  *.wasm filter=lfs diff=lfs merge=lfs -text
 
25
  *.safetensors filter=lfs diff=lfs merge=lfs -text
26
  saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
  *.tar.* filter=lfs diff=lfs merge=lfs -text
 
28
  *.tflite filter=lfs diff=lfs merge=lfs -text
29
  *.tgz filter=lfs diff=lfs merge=lfs -text
30
  *.wasm filter=lfs diff=lfs merge=lfs -text
Dockerfile ADDED
@@ -0,0 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM nvidia/cuda:11.3.1-base-ubuntu20.04
2
+
3
+ ENV DEBIAN_FRONTEND=noninteractive \
4
+ TZ=Aisa/Shanghai \
5
+ LC_CTYPE=C.UTF-8 \
6
+ LANG=C.UTF-8
7
+
8
+ # Remove any third-party apt sources to avoid issues with expiring keys.
9
+ # Install some basic utilities
10
+ RUN rm -f /etc/apt/sources.list.d/*.list && \
11
+ apt-get update && apt-get install -y \
12
+ curl \
13
+ ca-certificates \
14
+ sudo \
15
+ git \
16
+ git-lfs \
17
+ zip \
18
+ unzip \
19
+ htop \
20
+ bzip2 \
21
+ libx11-6 \
22
+ nginx \
23
+ vim \
24
+ lsof \
25
+ telnet \
26
+ wget \
27
+ build-essential \
28
+ libsndfile-dev \
29
+ software-properties-common \
30
+ && rm -rf /var/lib/apt/lists/*
31
+
32
+ ARG BUILD_DATE
33
+ ARG VERSION
34
+ ARG CODE_RELEASE
35
+ RUN \
36
+ echo "**** install openvscode-server runtime dependencies ****" && \
37
+ apt-get update && \
38
+ apt-get install -y \
39
+ jq \
40
+ libatomic1 \
41
+ nano \
42
+ net-tools \
43
+ netcat && \
44
+ echo "**** install openvscode-server ****" && \
45
+ if [ -z ${CODE_RELEASE+x} ]; then \
46
+ CODE_RELEASE=$(curl -sX GET "https://api.github.com/repos/gitpod-io/openvscode-server/releases/latest" \
47
+ | awk '/tag_name/{print $4;exit}' FS='[""]' \
48
+ | sed 's|^openvscode-server-v||'); \
49
+ fi && \
50
+ mkdir -p /app/openvscode-server && \
51
+ curl -o \
52
+ /tmp/openvscode-server.tar.gz -L \
53
+ "https://github.com/gitpod-io/openvscode-server/releases/download/openvscode-server-v${CODE_RELEASE}/openvscode-server-v${CODE_RELEASE}-linux-x64.tar.gz" && \
54
+ tar xf \
55
+ /tmp/openvscode-server.tar.gz -C \
56
+ /app/openvscode-server/ --strip-components=1 && \
57
+ echo "**** clean up ****" && \
58
+ apt-get clean && \
59
+ rm -rf \
60
+ /tmp/* \
61
+ /var/lib/apt/lists/* \
62
+ /var/tmp/*
63
+
64
+ RUN add-apt-repository ppa:flexiondotorg/nvtop && \
65
+ apt-get upgrade -y && \
66
+ apt-get install -y --no-install-recommends nvtop
67
+
68
+ RUN curl -sL https://deb.nodesource.com/setup_18.x | bash - && \
69
+ apt-get install -y nodejs && \
70
+ npm install -g configurable-http-proxy
71
+
72
+ # Create a working directory
73
+ WORKDIR /app
74
+
75
+ # Create a non-root user and switch to it
76
+ RUN adduser --disabled-password --gecos '' --shell /bin/bash user \
77
+ && chown -R user:user /app
78
+ RUN echo "user ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/90-user
79
+ USER user
80
+
81
+ # All users can use /home/user as their home directory
82
+ ENV HOME=/home/user
83
+ RUN mkdir $HOME/.cache $HOME/.config \
84
+ && chmod -R 777 $HOME
85
+
86
+ # Set up the Conda environment
87
+ ENV CONDA_AUTO_UPDATE_CONDA=false \
88
+ PATH=$HOME/miniconda/bin:$PATH
89
+ RUN curl -sLo ~/miniconda.sh https://repo.continuum.io/miniconda/Miniconda3-py310_23.5.2-0-Linux-x86_64.sh \
90
+ && chmod +x ~/miniconda.sh \
91
+ && ~/miniconda.sh -b -p ~/miniconda \
92
+ && rm ~/miniconda.sh \
93
+ && conda clean -ya
94
+
95
+ WORKDIR $HOME/app
96
+
97
+ #######################################
98
+ # Start root user section
99
+ #######################################
100
+
101
+ USER root
102
+
103
+ # User Debian packages
104
+ ## Security warning : Potential user code executed as root (build time)
105
+ RUN --mount=target=/root/packages.txt,source=packages.txt \
106
+ apt-get update && \
107
+ xargs -r -a /root/packages.txt apt-get install -y --no-install-recommends \
108
+ && rm -rf /var/lib/apt/lists/*
109
+
110
+ RUN --mount=target=/root/on_startup.sh,source=on_startup.sh,readwrite \
111
+ bash /root/on_startup.sh
112
+
113
+ #######################################
114
+ # End root user section
115
+ #######################################
116
+
117
+ USER user
118
+
119
+ # Python packages
120
+ RUN --mount=target=requirements.txt,source=requirements.txt \
121
+ pip install --no-cache-dir --upgrade -r requirements.txt
122
+
123
+ # Copy the current directory contents into the container at $HOME/app setting the owner to the user
124
+ COPY --chown=user . $HOME/app
125
+
126
+ WORKDIR $HOME/app
127
+
128
+ RUN chmod +x start_server.sh
129
+
130
+ ENV PYTHONUNBUFFERED=1 \
131
+ GRADIO_ALLOW_FLAGGING=never \
132
+ GRADIO_NUM_PORTS=1 \
133
+ GRADIO_SERVER_NAME=0.0.0.0 \
134
+ GRADIO_THEME=huggingface \
135
+ SYSTEM=spaces \
136
+ SHELL=/bin/bash
137
+
138
+ EXPOSE 7860 3000
139
+
140
+ CMD ["./start_server.sh"]
README.md CHANGED
@@ -1,11 +1,10 @@
1
  ---
2
- title: Bingo Api
3
- emoji: 📉
4
- colorFrom: blue
5
- colorTo: green
6
  sdk: docker
7
  pinned: false
8
- license: apache-2.0
9
  ---
10
 
11
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: Bingo API
3
+ emoji: 💻🐳
4
+ colorFrom: red
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
auto-commit.js ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const fs = require('fs')
2
+ const path = require('path')
3
+ const execSync = require('child_process').execSync
4
+
5
+ function exec(command, options) {
6
+ try {
7
+ const { stdout, stderr } = execSync(command, options)
8
+ if (stderr) {
9
+ throw new Error(stderr)
10
+ }
11
+ console.log(stdout)
12
+ } catch (e) {
13
+ console.log('Exec Error:', e)
14
+ }
15
+ }
16
+
17
+ const root = __dirname
18
+ function loop() {
19
+ console.log(new Date(), 'auto commit start')
20
+ const dirs = fs.readdirSync(root)
21
+ for (let dir of dirs) {
22
+ const cwd = path.join(root, dir)
23
+ if (fs.existsSync(path.join(cwd, '.git/config'))) {
24
+ console.log('auto commit', cwd)
25
+ exec(`git add -A`, { cwd })
26
+ exec(`git commit -am "[WIP] auto commit"`, { cwd })
27
+ exec(`git push`, { cwd })
28
+ console.log('done')
29
+ }
30
+ }
31
+ }
32
+ // loop()
33
+ const timeout = process.env.AUTO_COMMIT || 86400
34
+ if (timeout > 600) {
35
+ setInterval(loop, 1000 * timeout)
36
+ }
nginx.conf ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ error_log /tmp/error.log warn;
2
+ worker_processes auto;
3
+ pid /tmp/nginx.pid;
4
+ include /etc/nginx/modules-enabled/*.conf;
5
+
6
+ events {
7
+ worker_connections 768;
8
+ multi_accept on;
9
+ }
10
+
11
+ http {
12
+ ##
13
+ # Basic Settings
14
+ ##
15
+
16
+ sendfile on;
17
+ tcp_nopush on;
18
+ tcp_nodelay on;
19
+ keepalive_timeout 65;
20
+ types_hash_max_size 2048;
21
+ proxy_buffering off;
22
+ client_max_body_size 800m;
23
+ large_client_header_buffers 4 32k;
24
+ # server_tokens off;
25
+
26
+ # server_names_hash_bucket_size 64;
27
+ # server_name_in_redirect off;
28
+
29
+ include /etc/nginx/mime.types;
30
+
31
+ default_type application/octet-stream;
32
+ proxy_temp_path /tmp/proxy_temp;
33
+ client_body_temp_path /tmp/client_temp;
34
+ fastcgi_temp_path /tmp/fastcgi_temp;
35
+ uwsgi_temp_path /tmp/uwsgi_temp;
36
+ scgi_temp_path /tmp/scgi_temp;
37
+
38
+ ##
39
+ # SSL Settings
40
+ ##
41
+
42
+ ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
43
+ ssl_prefer_server_ciphers on;
44
+
45
+
46
+ ##
47
+ # Gzip Settings
48
+ ##
49
+
50
+ gzip on;
51
+
52
+ # gzip_vary on;
53
+ # gzip_proxied any;
54
+ # gzip_comp_level 6;
55
+ # gzip_buffers 16 8k;
56
+ # gzip_http_version 1.1;
57
+ # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
58
+
59
+ ##
60
+ # Virtual Host Configs
61
+ ##
62
+
63
+ #include /etc/nginx/conf.d/*.conf;
64
+ #include /etc/nginx/sites-enabled/*;
65
+ server {
66
+ listen 7860;
67
+
68
+ access_log /tmp/access.log;
69
+ server_name _;
70
+
71
+ root /var/www/;
72
+ index index.html;
73
+ location /stable-#COMMIT# {
74
+ proxy_pass http://127.0.0.1:5050;
75
+ proxy_http_version 1.1;
76
+ proxy_set_header Upgrade $http_upgrade;
77
+ proxy_set_header Connection "Upgrade";
78
+ proxy_set_header Host $host;
79
+ proxy_read_timeout 86400;
80
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
81
+ }
82
+
83
+ location /vscode/ {
84
+ auth_basic "Restricted Content";
85
+ auth_basic_user_file /home/user/app/ngpasswd;
86
+ proxy_pass http://127.0.0.1:5050/;
87
+ proxy_http_version 1.1;
88
+ proxy_set_header Upgrade $http_upgrade;
89
+ proxy_set_header Connection "Upgrade";
90
+ proxy_set_header Host $host;
91
+ proxy_read_timeout 86400;
92
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
93
+ }
94
+
95
+ location @vscode {
96
+ return 302 https://$host/vscode/?folder=/home/user/app;
97
+ }
98
+
99
+ location / {
100
+ error_page 502 = @vscode;
101
+ proxy_pass http://127.0.0.1:#PORT#;
102
+ proxy_http_version 1.1;
103
+ proxy_set_header Upgrade $http_upgrade;
104
+ proxy_set_header Connection "Upgrade";
105
+ proxy_set_header Host $host;
106
+ proxy_read_timeout 86400;
107
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
108
+ #try_files $uri $uri/ =404;
109
+ }
110
+ }
111
+ }
ngpasswd ADDED
File without changes
on_startup.sh ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ # Write some commands here that will run on root user before startup.
3
+ # For example, to clone transformers and install it in dev mode:
4
+ # git clone https://github.com/huggingface/transformers.git
5
+ # cd transformers && pip install -e ".[dev]"
6
+
7
+ npm i -g tsx tslab http-server miniflare@2 pm2
8
+ sudo chown -R 1000:1000 "/home/user/"
9
+
10
+ echo '
11
+ # >>> conda initialize >>>
12
+ __conda_setup="$(/home/user/miniconda/bin/conda shell.bash hook 2> /dev/null)"
13
+ if [ $? -eq 0 ]; then
14
+ eval "$__conda_setup"
15
+ else
16
+ if [ -f "/home/user/miniconda/etc/profile.d/conda.sh" ]; then
17
+ . "/home/user/miniconda/etc/profile.d/conda.sh"
18
+ else
19
+ export PATH="/home/user/miniconda/bin:$PATH"
20
+ fi
21
+ fi
22
+ unset __conda_setup
23
+ # <<< conda initialize <<<
24
+ ' >> ~/.bashrc
25
+
26
+ sudo chown -R 1000:1000 "/usr/"
packages.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ tree
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ # jupyterlab
2
+ jupyterlab==3.6.1
3
+ jupyter-server==2.3.0
start_server.sh ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ NGX_NAME="${NGX_NAME:-admin}"
4
+ NGX_PASS="${NGX_PASS:-admin}"
5
+ CRYPTPASS=`openssl passwd -apr1 ${NGX_PASS}`
6
+ PORT="${PORT:-8080}"
7
+
8
+ echo "USERNAME:" $NGX_NAME
9
+ echo "PASSWORD:" $NGX_PASS
10
+
11
+ echo "${NGX_NAME}:${CRYPTPASS}" > ngpasswd
12
+
13
+ COMMIT=$(cat /app/openvscode-server/product.json | awk '/commit/{print $4;exit}' FS='[""]')
14
+ sed -i "s/#COMMIT#/$COMMIT/" nginx.conf
15
+ sed -i "s/#PORT#/$PORT/" nginx.conf
16
+
17
+ set +e
18
+ if [[ ! -z "$REPO" ]]; then
19
+ dir=$(basename "$REPO" .git)
20
+ echo start to clone initial repo $REPO into $dir
21
+ git clone --progress $REPO $dir
22
+ cd $dir
23
+ [[ -z $(git config user.name) ]] && git config --global user.name "$(git log -1 --pretty=format:'%an')"
24
+ [[ -z $(git config user.email) ]] && git config --global user.email "$(git log -1 --pretty=format:'%ae')"
25
+ if [[ -e requirements.txt ]]; then
26
+ pip install --no-cache-dir --upgrade -r requirements.txt
27
+ fi
28
+ if [[ -e ecosystem.config.js ]]; then
29
+ echo use pm2 start
30
+ pm2 start ecosystem.config.js
31
+ fi
32
+ cd ..
33
+ fi
34
+ [[ -z $(git config --global user.name) ]] && git config --global user.name "$SPACE_AUTHOR_NAME"
35
+ [[ -z $(git config --global user.email) ]] && git config --global user.email "[email protected]"
36
+
37
+ git config --global http.postBuffer 524288000
38
+ git config --global push.default current
39
+
40
+ echo "Starting VSCode Server..."
41
+ vscode=/app/openvscode-server/bin/openvscode-server
42
+ vscode_cli=/app/openvscode-server/bin/remote-cli/openvscode-server
43
+ $vscode --install-extension ms-toolsai.jupyter
44
+ $vscode --install-extension ms-python.python
45
+ ln -s $vscode_cli $(dirname $vscode_cli)/code
46
+ tslab install --prefix /home/user/miniconda/
47
+ set -e
48
+ pm2 start ./auto-commit.js
49
+ nginx -c $PWD/nginx.conf
50
+ exec $vscode --host 0.0.0.0 --port 5050 --without-connection-token \"${@}\" --