opencode / Dockerfile
tanbushi's picture
update
69cbd0d
raw
history blame
1.32 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
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\
export PATH="/usr/local/bin:$PATH"\n\
exec /usr/local/bin/opencode serve --hostname 0.0.0.0 --port 7860\n\
' > /home/opencode/.local/bin/start.sh && chmod +x /home/opencode/.local/bin/start.sh
# Expose the port that HuggingFace Spaces expects
EXPOSE 7860
# Default command - start web server
CMD ["/home/opencode/.local/bin/start.sh"]