diff --git a/.gitignore b/.gitignore index 1269488..5781c7c 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -data +container-home/* +!container-home/.gitkeep diff --git a/Dockerfile b/Dockerfile index 802ed5e..a30e8f3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,31 +1,31 @@ FROM archlinux:latest -# Build args for user ARG USERNAME=dev ARG UID=1000 ARG GID=1000 -# Install basic tools RUN pacman -Syu --noconfirm \ + base-devel \ git \ ca-certificates \ - curl \ bash \ - && pacman -Scc --noconfirm + less \ + ripgrep && \ + groupadd -g ${GID} ${USERNAME} && \ + useradd -m -u ${UID} -g ${GID} -s /bin/bash ${USERNAME} && \ + pacman -Scc --noconfirm -# Create user -RUN groupadd -g ${GID} ${USERNAME} && \ - useradd -m -u ${UID} -g ${GID} -s /bin/bash ${USERNAME} +WORKDIR /tmp +USER ${USERNAME} + +RUN git clone https://aur.archlinux.org/opencode-bin.git && \ + cd opencode-bin && \ + makepkg --noconfirm + +USER root +RUN pacman -U --noconfirm /tmp/opencode-bin/*.pkg.tar.zst && \ + rm -rf /tmp/opencode-bin && \ + pacman -Scc --noconfirm -# Switch to non-root user USER ${USERNAME} WORKDIR /home/${USERNAME} - -# Install OpenCode CLI via official installer -RUN curl -fsSL https://opencode.ai/install | bash - -# Add OpenCode CLI to PATH -ENV PATH="/home/${USERNAME}/.opencode/bin:${PATH}" - -# Default working directory -WORKDIR /home/${USERNAME} diff --git a/README.md b/README.md index 79a34af..46bc693 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,11 @@ git clone https://git.jeena.net/jeena/opencode-container.git Source the helper file `opencode.aliases` in your shell configuration (`.bashrc` or `.zshrc`) so the `opencode` function is available in new sessions. +We set up the ./container-home directory as a central $HOME inside of the +container, independent of the session or project directory we start in. This +presists the whole $HOME from inside the container so everything opencode +writes into config files, etc. presists there. + ## Usage From any project directory: diff --git a/container-home/.gitkeep b/container-home/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/docker-compose.yaml b/docker-compose.yaml index d322953..df43ac1 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -15,12 +15,11 @@ services: tty: true environment: - HOME: "${PWD}/data" UID: "${UID}" GID: "${GID}" volumes: - # Current project (read–write) + - "${CONTAINER_HOME}:/home/${USER}/" - "${PWD}:${PWD}" cap_drop: diff --git a/opencode.aliases b/opencode.aliases index ccd8384..b774657 100644 --- a/opencode.aliases +++ b/opencode.aliases @@ -7,10 +7,11 @@ opencode() { UID="$uid" \ GID="$gid" \ USER="$user" \ + CONTAINER_HOME="$OPENCODE_CONTAINER_DIR/container-home" \ docker compose \ -f "$OPENCODE_CONTAINER_DIR/docker-compose.yaml" \ run --rm \ -u "$uid:$gid" \ - opencode /home/"$user"/.opencode/bin/opencode "$@" \ + opencode opencode "$@" \ 2> >(grep -v "No services to build" >&2) }