opencode / Dockerfile
tanbushi's picture
update
496b622
raw
history blame
1.4 kB
# Use Node.js 20 LTS as base image
FROM node:20-alpine
# Create a non-root user first
RUN addgroup -g 1001 -S opencode && \
adduser -S opencode -u 1001
# Set environment variables for user
ENV PATH="/home/opencode/.local/bin:/usr/local/bin:$PATH"
ENV NODE_ENV=production
ENV PORT=7860
# Install git and other system dependencies
RUN apk add --no-cache git curl
# Create workspace directory
WORKDIR /app
# Install opencode globally as root
USER root
RUN npm install -g opencode-ai@latest
# Copy files and set ownership
COPY --chown=opencode:opencode . /app
RUN chown -R opencode:opencode /app && \
chown -R opencode:opencode /home/opencode
# Switch to non-root user
USER opencode
# Create user's bin directory
RUN mkdir -p /home/opencode/.local/bin
# Create startup script using cat with heredoc to avoid newline issues
RUN cat > /home/opencode/.local/bin/start.sh << 'EOF'
#!/bin/ash
echo "Starting OpenCode AI Web Server..."
echo "Server will be available at http://0.0.0.0:7860 "
echo "OpenAPI documentation available at http://0.0.0.0:7860/doc "
exec /usr/local/bin/opencode serve --hostname 0.0.0.0 --port 7860
EOF
RUN chmod +x /home/opencode/.local/bin/start.sh
# 调试:验证脚本内容
RUN cat -A /home/opencode/.local/bin/start.sh
# Expose the port that HuggingFace Spaces expects
EXPOSE 7860
# 简化CMD,直接执行脚本
CMD ["/home/opencode/.local/bin/start.sh"]