update
Browse files- Dockerfile +10 -27
Dockerfile
CHANGED
|
@@ -4,13 +4,8 @@ FROM node:20
|
|
| 4 |
# ---------- 2. 系统级依赖 ----------
|
| 5 |
RUN apt-get update && apt-get install -y git curl cron && rm -rf /var/lib/apt/lists/*
|
| 6 |
|
| 7 |
-
# ---------- 3.
|
| 8 |
-
|
| 9 |
-
useradd -r -g opencode -u 1001 opencode && \
|
| 10 |
-
mkdir -p /home/opencode && \
|
| 11 |
-
chown opencode:opencode /home/opencode && \
|
| 12 |
-
mkdir -p /home/opencode/.local/share && \
|
| 13 |
-
chown -R opencode:opencode /home/opencode/.local
|
| 14 |
|
| 15 |
# ---------- 5. 全局安装 opencode-ai ----------
|
| 16 |
# 安装完先验证二进制是否存在,若不存在就手动解压
|
|
@@ -22,36 +17,24 @@ RUN npm install -g opencode-ai@latest && \
|
|
| 22 |
|
| 23 |
# ---------- 6. 工作目录 ----------
|
| 24 |
WORKDIR /app
|
| 25 |
-
COPY
|
| 26 |
-
COPY
|
| 27 |
RUN if [ -f package.json ]; then npm ci --only=production; fi
|
| 28 |
|
| 29 |
-
# ---------- 7. 修正权限 ----------
|
| 30 |
-
RUN chown -R opencode:opencode /app /home/opencode
|
| 31 |
-
|
| 32 |
# ---------- 8. 启动脚本 ----------
|
| 33 |
-
|
| 34 |
-
RUN mkdir -p /home/opencode/.local/bin
|
| 35 |
RUN printf '#!/bin/sh\n\
|
| 36 |
echo "Starting OpenCode AI Web Server ..."\n\
|
| 37 |
-
# 确保 cron 目录权限正确\n\
|
| 38 |
-
mkdir -p /var/run/crond && \
|
| 39 |
-
chmod 755 /var/run/crond && \
|
| 40 |
# 启动 cron 服务\n\
|
| 41 |
cron && \
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
RUN printf '#!/bin/sh\n\
|
| 47 |
-
echo "Starting opencode serve..."\n\
|
| 48 |
-
exec /usr/local/bin/opencode serve --hostname 0.0.0.0 --port 7860\n' > /home/opencode/.local/bin/start-opencode.sh && \
|
| 49 |
-
chmod +x /home/opencode/.local/bin/start-opencode.sh
|
| 50 |
-
USER opencode
|
| 51 |
|
| 52 |
# ---------- 9. 端口与健康检查 ----------
|
| 53 |
EXPOSE 7860
|
| 54 |
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
| 55 |
CMD curl -f http://localhost:7860/health || exit 1
|
| 56 |
|
| 57 |
-
CMD ["/
|
|
|
|
| 4 |
# ---------- 2. 系统级依赖 ----------
|
| 5 |
RUN apt-get update && apt-get install -y git curl cron && rm -rf /var/lib/apt/lists/*
|
| 6 |
|
| 7 |
+
# ---------- 3. 跳过用户创建,使用 root 用户 ----------
|
| 8 |
+
# 直接使用 root 用户运行所有服务
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
# ---------- 5. 全局安装 opencode-ai ----------
|
| 11 |
# 安装完先验证二进制是否存在,若不存在就手动解压
|
|
|
|
| 17 |
|
| 18 |
# ---------- 6. 工作目录 ----------
|
| 19 |
WORKDIR /app
|
| 20 |
+
COPY package*.json ./
|
| 21 |
+
COPY . /app
|
| 22 |
RUN if [ -f package.json ]; then npm ci --only=production; fi
|
| 23 |
|
|
|
|
|
|
|
|
|
|
| 24 |
# ---------- 8. 启动脚本 ----------
|
| 25 |
+
RUN mkdir -p /usr/local/bin
|
|
|
|
| 26 |
RUN printf '#!/bin/sh\n\
|
| 27 |
echo "Starting OpenCode AI Web Server ..."\n\
|
|
|
|
|
|
|
|
|
|
| 28 |
# 启动 cron 服务\n\
|
| 29 |
cron && \
|
| 30 |
+
echo "Cron started successfully"\n\
|
| 31 |
+
# 启动 opencode 服务\n\
|
| 32 |
+
exec /usr/local/bin/opencode serve --hostname 0.0.0.0 --port 7860\n' > /usr/local/bin/start.sh && \
|
| 33 |
+
chmod +x /usr/local/bin/start.sh
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
# ---------- 9. 端口与健康检查 ----------
|
| 36 |
EXPOSE 7860
|
| 37 |
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
| 38 |
CMD curl -f http://localhost:7860/health || exit 1
|
| 39 |
|
| 40 |
+
CMD ["/usr/local/bin/start.sh"]
|