Fix problem where container home was seperate for each project dir

The problem was that we mounted `pwd` as HOME and that meant that
every time git was used it would look into the data and work for a
long time, and it would also commit everything there.

Now we have a central container-home directory in the directory
where we checked out this git repo and it is used by each session
independent of in which project directory we are.
This commit is contained in:
Jeena 2026-01-15 12:13:05 +09:00
parent f479a613a0
commit b1f356c5f5
6 changed files with 27 additions and 21 deletions

3
.gitignore vendored
View file

@ -1 +1,2 @@
data
container-home/*
!container-home/.gitkeep

View file

@ -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}

View file

@ -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:

0
container-home/.gitkeep Normal file
View file

View file

@ -15,12 +15,11 @@ services:
tty: true
environment:
HOME: "${PWD}/data"
UID: "${UID}"
GID: "${GID}"
volumes:
# Current project (readwrite)
- "${CONTAINER_HOME}:/home/${USER}/"
- "${PWD}:${PWD}"
cap_drop:

View file

@ -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)
}