opencode / Dockerfile
tanbushi's picture
update
e05eb2f
raw
history blame
1.42 kB
# Use Node.js 20 LTS as base image
FROM node:20-alpine
# Set environment variables
ENV NODE_ENV=production
ENV PORT=7860
# Install git and other system dependencies
RUN apk add --no-cache git curl
# Create app directory
WORKDIR /app
# Install opencode globally
RUN npm install -g opencode-ai@latest
# Create a non-root user
RUN addgroup -g 1001 -S opencode && \
adduser -S opencode -u 1001
# Change ownership of the app directory and create workspace
RUN chown -R opencode:opencode /app && \
mkdir -p /home/opencode/workspace && \
chown -R opencode:opencode /home/opencode/workspace && \
touch /home/opencode/start.sh && \
chown opencode:opencode /home/opencode/start.sh
# Switch to non-root user
USER opencode
# Expose the port that HuggingFace Spaces expects
EXPOSE 7860
# Set the working directory for the user
WORKDIR /home/opencode
# Set working directory to workspace
WORKDIR /home/opencode/workspace
# Create startup script for web server before switching to non-root user
USER root
RUN echo '#!/bin/sh\n\
echo "Starting OpenCode AI Web Server..."\n\
echo "Server will be available at http://0.0.0.0:7860"\n\
echo "OpenAPI documentation available at http://0.0.0.0:7860/doc"\n\
exec opencode serve --hostname 0.0.0.0 --port 7860\n\
' > /home/opencode/start.sh && chmod +x /home/opencode/start.sh
USER opencode
# Default command - start web server
CMD ["/home/opencode/start.sh"]