update
Browse files- Dockerfile +37 -27
Dockerfile
CHANGED
|
@@ -1,52 +1,62 @@
|
|
| 1 |
-
#
|
| 2 |
FROM node:20-alpine
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
|
| 6 |
-
|
|
|
|
| 7 |
|
| 8 |
-
#
|
| 9 |
-
ENV PATH="/home/opencode/.local/bin:/usr/local/bin:$PATH"
|
| 10 |
ENV NODE_ENV=production
|
| 11 |
ENV PORT=7860
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
#
|
| 14 |
RUN apk add --no-cache git curl
|
| 15 |
|
| 16 |
-
#
|
| 17 |
WORKDIR /app
|
| 18 |
|
| 19 |
-
#
|
| 20 |
USER root
|
| 21 |
RUN npm install -g opencode-ai@latest
|
| 22 |
|
| 23 |
-
#
|
|
|
|
| 24 |
COPY --chown=opencode:opencode . /app
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
RUN chown -R opencode:opencode /app && \
|
| 26 |
chown -R opencode:opencode /home/opencode
|
| 27 |
|
| 28 |
-
#
|
| 29 |
USER opencode
|
| 30 |
|
| 31 |
-
#
|
| 32 |
RUN mkdir -p /home/opencode/.local/bin
|
| 33 |
|
| 34 |
-
#
|
| 35 |
-
RUN
|
| 36 |
-
|
| 37 |
-
echo "
|
| 38 |
-
echo "
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
# 调试:验证脚本内容
|
| 46 |
-
RUN cat -A /home/opencode/.local/bin/start.sh
|
| 47 |
-
|
| 48 |
-
# Expose the port that HuggingFace Spaces expects
|
| 49 |
EXPOSE 7860
|
| 50 |
|
| 51 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
CMD ["/home/opencode/.local/bin/start.sh"]
|
|
|
|
| 1 |
+
# 使用Node.js 20 LTS Alpine版本作为基础镜像[7](@ref)[8](@ref)
|
| 2 |
FROM node:20-alpine
|
| 3 |
|
| 4 |
+
# 设置元数据标签[2](@ref)[6](@ref)
|
| 5 |
+
LABEL maintainer="your-email@example.com"
|
| 6 |
+
LABEL description="OpenCode AI Web Application"
|
| 7 |
+
LABEL version="1.0.0"
|
| 8 |
|
| 9 |
+
# 设置环境变量[2](@ref)[5](@ref)
|
|
|
|
| 10 |
ENV NODE_ENV=production
|
| 11 |
ENV PORT=7860
|
| 12 |
+
ENV PATH="/home/opencode/.local/bin:/usr/local/bin:$PATH"
|
| 13 |
+
|
| 14 |
+
# 创建非root用户以提高安全性[7](@ref)[8](@ref)
|
| 15 |
+
RUN addgroup -g 1001 -S opencode && \
|
| 16 |
+
adduser -S opencode -u 1001
|
| 17 |
|
| 18 |
+
# 安装必要的系统依赖[8](@ref)
|
| 19 |
RUN apk add --no-cache git curl
|
| 20 |
|
| 21 |
+
# 设置工作目录[1](@ref)[3](@ref)
|
| 22 |
WORKDIR /app
|
| 23 |
|
| 24 |
+
# 以root用户安装全局依赖[1](@ref)
|
| 25 |
USER root
|
| 26 |
RUN npm install -g opencode-ai@latest
|
| 27 |
|
| 28 |
+
# 复制应用程序文件并设置权限[1](@ref)[4](@ref)
|
| 29 |
+
COPY --chown=opencode:opencode package*.json ./
|
| 30 |
COPY --chown=opencode:opencode . /app
|
| 31 |
+
|
| 32 |
+
# 安装应用程序依赖(如果存在package.json)[4](@ref)
|
| 33 |
+
RUN if [ -f "package.json" ]; then npm ci --only=production; fi
|
| 34 |
+
|
| 35 |
+
# 设置文件所有权[8](@ref)
|
| 36 |
RUN chown -R opencode:opencode /app && \
|
| 37 |
chown -R opencode:opencode /home/opencode
|
| 38 |
|
| 39 |
+
# 切换到非root用户[8](@ref)
|
| 40 |
USER opencode
|
| 41 |
|
| 42 |
+
# 创建用户目录
|
| 43 |
RUN mkdir -p /home/opencode/.local/bin
|
| 44 |
|
| 45 |
+
# 创建启动脚本 - 使用printf避免换行符问题
|
| 46 |
+
RUN printf '#!/bin/sh\n\
|
| 47 |
+
echo "Starting OpenCode AI Web Server..."\n\
|
| 48 |
+
echo "Server will be available at http://0.0.0.0:7860 "\n\
|
| 49 |
+
echo "OpenAPI documentation available at http://0.0.0.0:7860/doc "\n\
|
| 50 |
+
exec /usr/local/bin/opencode serve --hostname 0.0.0.0 --port 7860\n\
|
| 51 |
+
' > /home/opencode/.local/bin/start.sh && \
|
| 52 |
+
chmod +x /home/opencode/.local/bin/start.sh
|
| 53 |
|
| 54 |
+
# 暴露应用程序端口[1](@ref)[2](@ref)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
EXPOSE 7860
|
| 56 |
|
| 57 |
+
# 健康检查[6](@ref)
|
| 58 |
+
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
| 59 |
+
CMD curl -f http://localhost:7860/health || exit 1
|
| 60 |
+
|
| 61 |
+
# 设置容器启动命令[3](@ref)[5](@ref)
|
| 62 |
CMD ["/home/opencode/.local/bin/start.sh"]
|