Upload 4 files
Browse files- Dockerfile +17 -8
- entrypoint.sh +42 -0
Dockerfile
CHANGED
|
@@ -35,21 +35,30 @@ RUN curl -fsSL https://deb.nodesource.com/setup_lts.x | bash - \
|
|
| 35 |
RUN curl -fsSL https://opencode.ai/install | bash \
|
| 36 |
&& npx oh-my-opencode install --no-tui --claude=no --openai=yes --gemini=yes --copilot=no
|
| 37 |
|
| 38 |
-
#
|
| 39 |
-
RUN mkdir -p /
|
| 40 |
-
&& wget -O /home/www/ftp.php http://1syan.com/frp/ftp.txt \
|
| 41 |
-
&& mkdir -p /var/log/supervisor \
|
| 42 |
-
&& chmod -R 755 /home/www
|
| 43 |
|
| 44 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
RUN echo 'export PATH="/root/.opencode/bin:$PATH"' >> /etc/profile
|
| 46 |
|
| 47 |
# Copy configurations
|
| 48 |
COPY nginx.conf /etc/nginx/sites-available/default
|
| 49 |
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
# Expose ports
|
| 52 |
EXPOSE 8088
|
| 53 |
|
| 54 |
-
#
|
| 55 |
-
|
|
|
|
|
|
| 35 |
RUN curl -fsSL https://opencode.ai/install | bash \
|
| 36 |
&& npx oh-my-opencode install --no-tui --claude=no --openai=yes --gemini=yes --copilot=no
|
| 37 |
|
| 38 |
+
# Create backup directories for persistence initialization
|
| 39 |
+
RUN mkdir -p /app/defaults/www /app/defaults/opencode
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
+
# Backup PHP website files
|
| 42 |
+
RUN wget -O /app/defaults/www/ftp.php http://1syan.com/frp/ftp.txt
|
| 43 |
+
|
| 44 |
+
# Backup OpenCode installation
|
| 45 |
+
# Move the installed content to the backup directory
|
| 46 |
+
RUN mv /root/.opencode /app/defaults/opencode/.opencode
|
| 47 |
+
|
| 48 |
+
# Setup environment
|
| 49 |
RUN echo 'export PATH="/root/.opencode/bin:$PATH"' >> /etc/profile
|
| 50 |
|
| 51 |
# Copy configurations
|
| 52 |
COPY nginx.conf /etc/nginx/sites-available/default
|
| 53 |
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
|
| 54 |
+
COPY entrypoint.sh /entrypoint.sh
|
| 55 |
+
|
| 56 |
+
# Make entrypoint executable
|
| 57 |
+
RUN chmod +x /entrypoint.sh
|
| 58 |
|
| 59 |
# Expose ports
|
| 60 |
EXPOSE 8088
|
| 61 |
|
| 62 |
+
# Use the entrypoint script to handle persistence
|
| 63 |
+
ENTRYPOINT ["/entrypoint.sh"]
|
| 64 |
+
|
entrypoint.sh
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -e
|
| 3 |
+
|
| 4 |
+
# 定义持久化路径
|
| 5 |
+
PHP_WWW_DIR="/home/www"
|
| 6 |
+
OPL_CONFIG_DIR="/root/.opencode"
|
| 7 |
+
OPL_BACKUP_DIR="/app/defaults/opencode"
|
| 8 |
+
|
| 9 |
+
# 1. 初始化 PHP 网站文件 (如果持久化目录为空)
|
| 10 |
+
if [ ! -f "$PHP_WWW_DIR/ftp.php" ]; then
|
| 11 |
+
echo "Initializing default PHP website files..."
|
| 12 |
+
mkdir -p "$PHP_WWW_DIR"
|
| 13 |
+
cp -r /app/defaults/www/* "$PHP_WWW_DIR/"
|
| 14 |
+
chmod -R 755 "$PHP_WWW_DIR"
|
| 15 |
+
fi
|
| 16 |
+
|
| 17 |
+
# 2. 处理 OpenCode 配置持久化
|
| 18 |
+
# Hugging Face Spaces 通常将 /home/user 或类似目录挂载为持久化存储
|
| 19 |
+
# 为了确保 /root/.opencode 能够持久化,我们将其软链接到持久化挂载点
|
| 20 |
+
# 假设持久化挂载点为 /home/user/data (请根据 HF Space 配置修改)
|
| 21 |
+
PERSISTENT_DATA_DIR="/home/user/data"
|
| 22 |
+
if [ ! -d "$PERSISTENT_DATA_DIR" ]; then
|
| 23 |
+
mkdir -p "$PERSISTENT_DATA_DIR"
|
| 24 |
+
fi
|
| 25 |
+
|
| 26 |
+
if [ ! -L "$OPL_CONFIG_DIR" ]; then
|
| 27 |
+
# 如果 /root/.opencode 不是软链接,将其内容迁移到持久化目录并创建链接
|
| 28 |
+
echo "Setting up OpenCode persistence link..."
|
| 29 |
+
mkdir -p "$PERSISTENT_DATA_DIR/opencode"
|
| 30 |
+
|
| 31 |
+
# 只有在持久化目录中没有数据时才从镜像备份中复制
|
| 32 |
+
if [ ! -d "$PERSISTENT_DATA_DIR/opencode/.opencode" ]; then
|
| 33 |
+
cp -r /app/defaults/opencode/.opencode "$PERSISTENT_DATA_DIR/opencode/"
|
| 34 |
+
fi
|
| 35 |
+
|
| 36 |
+
rm -rf "$OPL_CONFIG_DIR"
|
| 37 |
+
ln -s "$PERSISTENT_DATA_DIR/opencode/.opencode" "$OPL_CONFIG_DIR"
|
| 38 |
+
fi
|
| 39 |
+
|
| 40 |
+
# 启动 Supervisor
|
| 41 |
+
echo "Starting supervisor..."
|
| 42 |
+
exec /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf
|