|
| 1 | +# OpenCode Container with SSH Server |
| 2 | +# Debian-based container for running OpenCode CLI with SSH access |
| 3 | +# Uses official OpenSSH from Debian repositories |
| 4 | + |
| 5 | +FROM node:20-slim |
| 6 | + |
| 7 | +# Install OpenSSH server and essential development tools |
| 8 | +RUN apt-get update && apt-get install -y \ |
| 9 | + openssh-server \ |
| 10 | + git \ |
| 11 | + bash \ |
| 12 | + zsh \ |
| 13 | + curl \ |
| 14 | + unzip \ |
| 15 | + vim \ |
| 16 | + ca-certificates \ |
| 17 | + python3 \ |
| 18 | + python3-pip \ |
| 19 | + sudo \ |
| 20 | + && rm -rf /var/lib/apt/lists/* |
| 21 | + |
| 22 | +# Create opencode user WITHOUT sudo privileges (security hardening) |
| 23 | +# Use UID 1001 to avoid conflict with node user (UID 1000) |
| 24 | +RUN useradd -m -u 1001 -s /bin/zsh opencode |
| 25 | + |
| 26 | +# Set up SSH |
| 27 | +RUN mkdir -p /run/sshd && \ |
| 28 | + ssh-keygen -A && \ |
| 29 | + mkdir -p /home/opencode/.ssh && \ |
| 30 | + chown -R opencode:opencode /home/opencode/.ssh && \ |
| 31 | + chmod 700 /home/opencode/.ssh |
| 32 | + |
| 33 | +# Configure SSH daemon for security (comprehensive hardening) |
| 34 | +RUN echo "PermitRootLogin no" >> /etc/ssh/sshd_config && \ |
| 35 | + echo "PasswordAuthentication no" >> /etc/ssh/sshd_config && \ |
| 36 | + echo "PubkeyAuthentication yes" >> /etc/ssh/sshd_config && \ |
| 37 | + echo "AllowUsers opencode" >> /etc/ssh/sshd_config && \ |
| 38 | + echo "X11Forwarding no" >> /etc/ssh/sshd_config && \ |
| 39 | + echo "MaxAuthTries 3" >> /etc/ssh/sshd_config && \ |
| 40 | + echo "ClientAliveInterval 300" >> /etc/ssh/sshd_config && \ |
| 41 | + echo "ClientAliveCountMax 2" >> /etc/ssh/sshd_config && \ |
| 42 | + echo "PermitEmptyPasswords no" >> /etc/ssh/sshd_config && \ |
| 43 | + echo "ChallengeResponseAuthentication no" >> /etc/ssh/sshd_config |
| 44 | + |
| 45 | +# Create required directories for OpenCode |
| 46 | +RUN mkdir -p /home/opencode/.config/opencode \ |
| 47 | + /home/opencode/.local/share/opencode \ |
| 48 | + /home/opencode/.local/state && \ |
| 49 | + touch /home/opencode/.zshrc && \ |
| 50 | + chown -R opencode:opencode /home/opencode |
| 51 | + |
| 52 | +# Install OpenCode CLI as opencode user |
| 53 | +USER opencode |
| 54 | +WORKDIR /home/opencode |
| 55 | +RUN curl -fsSL https://opencode.ai/install | bash |
| 56 | + |
| 57 | +# Set up shell environment |
| 58 | +ENV SHELL=/bin/zsh |
| 59 | +ENV TERM=xterm-256color |
| 60 | +ENV PATH="/home/opencode/.opencode/bin:${PATH}" |
| 61 | + |
| 62 | +# Copy OpenCode config |
| 63 | +COPY --chown=opencode:opencode opencode.container.json /config/opencode.container.json |
| 64 | + |
| 65 | +# Switch back to root for entrypoint (SSH daemon requires root) |
| 66 | +USER root |
| 67 | + |
| 68 | +# Copy entrypoint as root-executable |
| 69 | +COPY entrypoint-ssh.sh /entrypoint-ssh.sh |
| 70 | +RUN chmod +x /entrypoint-ssh.sh |
| 71 | + |
| 72 | +WORKDIR /workspace |
| 73 | + |
| 74 | +ENTRYPOINT ["/entrypoint-ssh.sh"] |
0 commit comments