Spaces:
Paused
Paused
Upload folder using huggingface_hub
Browse filesFiles changed (10)
- .gitattributesAdded+35
- BauCuaPlugin.jarAdded
- Dockerfile+120-8
- InvPlugin.jarAdded
- README.mdAdded+29
- login.htmlAdded+68
- on_startup.shAdded+5
- packages.txtAdded+1
- requirements.txtAdded+3
- start_server.shAdded+99
1234567891011121314151617181920212223242526272829303132333435*.7z filter=lfs diff=lfs merge=lfs -text*.arrow filter=lfs diff=lfs merge=lfs -text*.bin filter=lfs diff=lfs merge=lfs -text*.bz2 filter=lfs diff=lfs merge=lfs -text*.ckpt filter=lfs diff=lfs merge=lfs -text*.ftz filter=lfs diff=lfs merge=lfs -text*.gz filter=lfs diff=lfs merge=lfs -text*.h5 filter=lfs diff=lfs merge=lfs -text*.joblib filter=lfs diff=lfs merge=lfs -text*.lfs.* filter=lfs diff=lfs merge=lfs -text*.mlmodel filter=lfs diff=lfs merge=lfs -text*.model filter=lfs diff=lfs merge=lfs -text*.msgpack filter=lfs diff=lfs merge=lfs -text*.npy filter=lfs diff=lfs merge=lfs -text*.npz filter=lfs diff=lfs merge=lfs -text*.onnx filter=lfs diff=lfs merge=lfs -text*.ot filter=lfs diff=lfs merge=lfs -text*.parquet filter=lfs diff=lfs merge=lfs -text*.pb filter=lfs diff=lfs merge=lfs -text*.pickle filter=lfs diff=lfs merge=lfs -text*.pkl filter=lfs diff=lfs merge=lfs -text*.pt filter=lfs diff=lfs merge=lfs -text*.pth filter=lfs diff=lfs merge=lfs -text*.rar filter=lfs diff=lfs merge=lfs -text*.safetensors filter=lfs diff=lfs merge=lfs -textsaved_model/**/* filter=lfs diff=lfs merge=lfs -text*.tar.* filter=lfs diff=lfs merge=lfs -text*.tar filter=lfs diff=lfs merge=lfs -text*.tflite filter=lfs diff=lfs merge=lfs -text*.tgz filter=lfs diff=lfs merge=lfs -text*.wasm filter=lfs diff=lfs merge=lfs -text*.xz filter=lfs diff=lfs merge=lfs -text*.zip filter=lfs diff=lfs merge=lfs -text*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -text11233456789101112131415161718192021222324252627282930313233343536373839404142434445464754849505178525354555657585960616212636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191412012112212312412512612716128FROM ubuntu:latestFROM nvidia/cuda:12.5.1-cudnn-devel-ubuntu20.04
USER rootENV DEBIAN_FRONTEND=noninteractive \ TZ=Europe/Paris
# Remove any third-party apt sources to avoid issues with expiring keys.# Install some basic utilitiesRUN rm -f /etc/apt/sources.list.d/*.list && \ apt-get update && apt-get install -y --no-install-recommends \ curl \ ca-certificates \ sudo \ git \ wget \ procps \ git-lfs \ zip \ unzip \ htop \ vim \ nano \ bzip2 \ libx11-6 \ build-essential \ libsndfile-dev \ openjdk-21-jdk -y \ software-properties-common \ && rm -rf /var/lib/apt/lists/*
# Install Java 25 - Eclipse TemurinRUN apt-get update && \ apt-get install -y --no-install-recommends wget gpg && \ install -d -m 0755 /etc/apt/keyrings && \ wget -qO- https://packages.adoptium.net/artifactory/api/gpg/key/public \ | gpg --dearmor -o /etc/apt/keyrings/adoptium.gpg && \ echo "deb [signed-by=/etc/apt/keyrings/adoptium.gpg] https://packages.adoptium.net/artifactory/deb focal main" \ > /etc/apt/sources.list.d/adoptium.list && \ apt-get update && \ apt-get install -y --no-install-recommends temurin-25-jdk && \ rm -rf /var/lib/apt/lists/*
RUN add-apt-repository ppa:flexiondotorg/nvtop && \ apt-get upgrade -y && \ apt-get install -y --no-install-recommends nvtop
RUN apt-get update && apt-get upgrade -yRUN curl -sL https://deb.nodesource.com/setup_21.x | bash - && \ apt-get install -y nodejs && \ npm install -g configurable-http-proxy
RUN curl -sL https://deb.nodesource.com/setup_20.x | bash -RUN apt-get install -y nodejs# Install bore (auto TCP tunnel for port 25565)RUN curl -sSL https://github.com/ekzhang/bore/releases/download/v0.5.2/bore-v0.5.2-x86_64-unknown-linux-musl.tar.gz \ | tar -xz -C /usr/local/bin bore && \ chmod +x /usr/local/bin/bore
# Install Portwarp CLI (pwrp)RUN curl -fsSL https://portwarp.com/download/install.sh | bash
# Create a working directoryWORKDIR /app
COPY . .# Create a non-root user and switch to itRUN adduser --disabled-password --gecos '' --shell /bin/bash user \ && chown -R user:user /appRUN echo "user ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/90-userUSER user
# All users can use /home/user as their home directoryENV HOME=/home/userRUN mkdir $HOME/.cache $HOME/.config \ && chmod -R 777 $HOME
# Set up the Conda environmentENV CONDA_AUTO_UPDATE_CONDA=false \ PATH=$HOME/miniconda/bin:$PATHRUN curl -sLo ~/miniconda.sh https://repo.continuum.io/miniconda/Miniconda3-py39_4.10.3-Linux-x86_64.sh \ && chmod +x ~/miniconda.sh \ && ~/miniconda.sh -b -p ~/miniconda \ && rm ~/miniconda.sh \ && conda clean -ya
WORKDIR $HOME/app
######################################## Start root user section#######################################
USER root
# User Debian packages## Security warning : Potential user code executed as root (build time)RUN --mount=target=/root/packages.txt,source=packages.txt \ apt-get update && \ xargs -r -a /root/packages.txt apt-get install -y --no-install-recommends \ && rm -rf /var/lib/apt/lists/*
RUN --mount=target=/root/on_startup.sh,source=on_startup.sh,readwrite \ bash /root/on_startup.sh
RUN mkdir /data && chown user:user /data
######################################## End root user section#######################################
USER user
# Python packagesRUN --mount=target=requirements.txt,source=requirements.txt \ pip install --no-cache-dir --upgrade -r requirements.txt
# Copy the current directory contents into the container at $HOME/app setting the owner to the userCOPY --chown=user . $HOME/app
RUN sed -i 's/\r$//' start_server.sh && chmod +x start_server.sh
COPY --chown=user login.html /home/user/miniconda/lib/python3.9/site-packages/jupyter_server/templates/login.html
RUN npm installENV PYTHONUNBUFFERED=1 \ GRADIO_ALLOW_FLAGGING=never \ GRADIO_NUM_PORTS=1 \ GRADIO_SERVER_NAME=0.0.0.0 \ GRADIO_THEME=huggingface \ SYSTEM=spaces \ SHELL=/bin/bash
CMD ["node", "index.js"]CMD ["./start_server.sh"]1234567891011121314151617181920212223242526272829---title: Tuanemoji: 💻🐳colorFrom: graycolorTo: greensdk: dockerpinned: falsetags:- jupyterlab---
# Minecraft Server on Hugging Face Spaces
### 1. Persistent Storage (HF Storage Buckets)- Mount Storage Bucket vào đường dẫn: `/data` (Read-Write).- Toàn bộ thế giới game, cấu hình và plugin lưu tại `/data/minecraft/` sẽ tồn tại vĩnh viễn không bị mất khi Space restart.
### 2. Auto-Restart- Container tự động quét và chạy file server (`*paper*.jar`, `*purpur*.jar`, `*server*.jar`,...) trong `/data/minecraft/`.- Nếu server bị crash hoặc lệnh `/stop`, tiến trình sẽ tự động restart lại sau 5 giây.- Xem log server tại: `/data/MC_SERVER.log`.
### 3. Tự động kết nối Portwarp (pwrp connect --all)- Đã cài đặt sẵn Portwarp CLI (`pwrp`).- Script tự động chạy `pwrp connect --all` ngầm và ghi log vào `/data/PWRP.log`.- Khi cần đăng nhập lần đầu, bạn chỉ cần mở Terminal trong JupyterLab gõ: `pwrp login`. Dữ liệu đăng nhập được tự động lưu vĩnh viễn trong `/data/.config/portwarp/` nên không bao giờ phải đăng nhập lại sau khi restart.
### 4. Kênh dự phòng bore.pub- Port 25565 vẫn được mở thêm kênh phụ qua `bore.pub` lưu tại `/data/IP_SERVER.txt`.1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768{% extends "page.html" %}
{% block stylesheet %}{% endblock %}
{% block site %}
<div id="jupyter-main-app" class="container"> <img src="https://huggingface.co/front/assets/huggingface_logo-noborder.svg" alt="Hugging Face Logo"> <h4>Welcome to JupyterLab</h4> <h5>The default token is <span style="color:orange;">huggingface</span></h5> {% if login_available %} {# login_available means password-login is allowed. Show the form. #} <div class="row"> <div class="navbar col-sm-8"> <div class="navbar-inner"> <div class="container"> <div class="center-nav"> <form action="{{base_url}}login?next={{next}}" method="post" class="navbar-form pull-left"> {{ xsrf_form_html() | safe }} {% if token_available %} <label for="password_input"><strong>{% trans %}Jupyter token <span title="This is the secret you set up when deploying your JupyterLab space">ⓘ</span> {% endtrans %}</strong></label> {% else %} <label for="password_input"><strong>{% trans %}Jupyter password:{% endtrans %}</strong></label> {% endif %} <input type="password" name="password" id="password_input" class="form-control"> <button type="submit" class="btn btn-default" id="login_submit">{% trans %}Log in{% endtrans %}</button> </form> </div> </div> </div> </div> </div> {% else %} <p>{% trans %}No login available, you shouldn't be seeing this page.{% endtrans %}</p> {% endif %}
<h5>If you don't have the credentials for this Jupyter space, <a target="_blank" href="https://huggingface.co/spaces/SpacesExamples/jupyterlab?duplicate=true">create your own.</a></h5> <br> <p>This template was created by <a href="https://twitter.com/camenduru" target="_blank" >camenduru</a> and <a href="https://huggingface.co/nateraw" target="_blank" >nateraw</a>, with contributions of <a href="https://huggingface.co/osanseviero" target="_blank" >osanseviero</a> and <a href="https://huggingface.co/azzr" target="_blank" >azzr</a> </p> {% if message %} <div class="row"> {% for key in message %} <div class="message {{key}}"> {{message[key]}} </div> {% endfor %} </div> {% endif %} {% if token_available %} {% block token_message %} {% endblock token_message %} {% endif %}</div>
{% endblock %}
{% block script %}{% endblock %}12345#!/bin/bash# Write some commands here that will run on root user before startup.# For example, to clone transformers and install it in dev mode:# git clone https://github.com/huggingface/transformers.git# cd transformers && pip install -e ".[dev]"1tree123jupyterlab==4.2.5tornado==6.2ipywidgets123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899#!/bin/bashJUPYTER_TOKEN="${JUPYTER_TOKEN:=huggingface}"MC_PORT="${MC_PORT:=25565}"
NOTEBOOK_DIR="/data"if [ -d "$NOTEBOOK_DIR/server" ]; then MC_DIR="$NOTEBOOK_DIR/server"elif [ -d "$NOTEBOOK_DIR/minecraft" ]; then MC_DIR="$NOTEBOOK_DIR/minecraft"else MC_DIR="$NOTEBOOK_DIR/server"fi
# Lưu giữ cấu hình đăng nhập của Portwarp (pwrp) vĩnh viễn trong bucket /datamkdir -p "$NOTEBOOK_DIR/.config/portwarp"mkdir -p "$HOME/.config"if [ ! -L "$HOME/.config/portwarp" ]; then rm -rf "$HOME/.config/portwarp" ln -sfn "$NOTEBOOK_DIR/.config/portwarp" "$HOME/.config/portwarp"fi
# Copy sẵn các file plugin từ repo vào /data/minecraft/plugins nếu cómkdir -p "$MC_DIR/plugins"if compgen -G "$HOME/app/*.jar" > /dev/null; then cp -u "$HOME/app"/*.jar "$MC_DIR/plugins/" 2>/dev/null || truefi
# Tự động khởi động và Auto-restart Server Minecraft nếu tìm thấy file jar server( while true; do SERVER_JAR=$(find "$MC_DIR" "$NOTEBOOK_DIR/server" -maxdepth 2 -type f \( -iname "*paper*.jar" -o -iname "*purpur*.jar" -o -iname "*spigot*.jar" -o -iname "*server*.jar" -o -iname "*forge*.jar" -o -iname "*fabric*.jar" -o -iname "*.jar" ! -iname "*Plugin*.jar" \) 2>/dev/null | head -n 1) if [ -n "$SERVER_JAR" ]; then JAR_DIR=$(dirname "$SERVER_JAR") echo "[$(date '+%Y-%m-%d %H:%M:%S')] [MC AUTO-RESTART] Khởi động Minecraft server: $SERVER_JAR" | tee -a "$NOTEBOOK_DIR/MC_SERVER.log" cd "$JAR_DIR" || exit java -Xms1G -Xmx${MC_RAM:-4G} -jar "$SERVER_JAR" nogui 2>&1 | tee -a "$NOTEBOOK_DIR/MC_SERVER.log" EXIT_CODE=$? echo "[$(date '+%Y-%m-%d %H:%M:%S')] [MC AUTO-RESTART] Server dừng với exit code $EXIT_CODE. Tự động khởi động lại sau 5 giây..." | tee -a "$NOTEBOOK_DIR/MC_SERVER.log" sleep 5 else sleep 10 fi done) &
# Tự động xử lý đăng nhập Portwarp và kết nối tunnel: pwrp login -> pwrp connect --all( sleep 3 while true; do CRED_FILE="$NOTEBOOK_DIR/.config/portwarp/credentials.json" if [ ! -f "$CRED_FILE" ] && [ ! -f "$HOME/.config/portwarp/credentials.json" ]; then echo "==================================================" > "$NOTEBOOK_DIR/PWRP_LOGIN.txt" echo "[$(date '+%Y-%m-%d %H:%M:%S')] CHƯA ĐĂNG NHẬP PORTWARP (PWRP)!" >> "$NOTEBOOK_DIR/PWRP_LOGIN.txt" echo "Đang tự động chạy 'pwrp login' để lấy link liên kết tài khoản..." >> "$NOTEBOOK_DIR/PWRP_LOGIN.txt" echo "Bạn cũng có thể mở Terminal trong JupyterLab gõ: pwrp login" >> "$NOTEBOOK_DIR/PWRP_LOGIN.txt" echo "==================================================" >> "$NOTEBOOK_DIR/PWRP_LOGIN.txt"
pwrp login 2>&1 | tee -a "$NOTEBOOK_DIR/PWRP_LOGIN.txt" "$NOTEBOOK_DIR/PWRP.log" sleep 5 else echo "[$(date '+%Y-%m-%d %H:%M:%S')] [PWRP] Đã có cấu hình xác thực. Bắt đầu pwrp connect --all..." | tee -a "$NOTEBOOK_DIR/PWRP.log" pwrp connect --all 2>&1 | tee -a "$NOTEBOOK_DIR/PWRP.log" EXIT_PWRP=$? echo "[$(date '+%Y-%m-%d %H:%M:%S')] [PWRP] pwrp ngắt kết nối (mã $EXIT_PWRP). Thử lại sau 10 giây..." | tee -a "$NOTEBOOK_DIR/PWRP.log" sleep 10 fi done) &
# Tự động mở port ảo TCP 25565 bằng bore.pub (Dự phòng thêm kênh kết nối)( while true; do bore local "$MC_PORT" --to bore.pub 2>&1 | while IFS= read -r line; do echo "$line" if [[ "$line" =~ (bore\.pub:[0-9]+) ]]; then echo "==========================================" > "$NOTEBOOK_DIR/IP_SERVER.txt" echo "ĐỊA CHỈ VÀO SERVER MINECRAFT:" >> "$NOTEBOOK_DIR/IP_SERVER.txt" echo "${BASH_REMATCH[1]}" >> "$NOTEBOOK_DIR/IP_SERVER.txt" echo "==========================================" >> "$NOTEBOOK_DIR/IP_SERVER.txt" fi done sleep 5 done) &
jupyter labextension disable "@jupyterlab/apputils-extension:announcements"
jupyter-lab \ --ip 0.0.0.0 \ --port 7860 \ --no-browser \ --allow-root \ --ServerApp.token="$JUPYTER_TOKEN" \ --ServerApp.tornado_settings="{'headers': {'Content-Security-Policy': 'frame-ancestors *'}}" \ --ServerApp.cookie_options="{'SameSite': 'None', 'Secure': True}" \ --ServerApp.disable_check_xsrf=True \ --LabApp.news_url=None \ --LabApp.check_for_updates_class="jupyterlab.NeverCheckForUpdate" \ --notebook-dir=$NOTEBOOK_DIR.gitattributesAdded+35
BauCuaPlugin.jarAdded
Dockerfile+120-8
InvPlugin.jarAdded
README.mdAdded+29
login.htmlAdded+68
on_startup.shAdded+5
packages.txtAdded+1
requirements.txtAdded+3
start_server.shAdded+99