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:
parent
f479a613a0
commit
b1f356c5f5
6 changed files with 27 additions and 21 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -1 +1,2 @@
|
||||||
data
|
container-home/*
|
||||||
|
!container-home/.gitkeep
|
||||||
|
|
|
||||||
34
Dockerfile
34
Dockerfile
|
|
@ -1,31 +1,31 @@
|
||||||
FROM archlinux:latest
|
FROM archlinux:latest
|
||||||
|
|
||||||
# Build args for user
|
|
||||||
ARG USERNAME=dev
|
ARG USERNAME=dev
|
||||||
ARG UID=1000
|
ARG UID=1000
|
||||||
ARG GID=1000
|
ARG GID=1000
|
||||||
|
|
||||||
# Install basic tools
|
|
||||||
RUN pacman -Syu --noconfirm \
|
RUN pacman -Syu --noconfirm \
|
||||||
|
base-devel \
|
||||||
git \
|
git \
|
||||||
ca-certificates \
|
ca-certificates \
|
||||||
curl \
|
|
||||||
bash \
|
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
|
WORKDIR /tmp
|
||||||
RUN groupadd -g ${GID} ${USERNAME} && \
|
USER ${USERNAME}
|
||||||
useradd -m -u ${UID} -g ${GID} -s /bin/bash ${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}
|
USER ${USERNAME}
|
||||||
WORKDIR /home/${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}
|
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,11 @@ git clone https://git.jeena.net/jeena/opencode-container.git
|
||||||
Source the helper file `opencode.aliases` in your shell configuration
|
Source the helper file `opencode.aliases` in your shell configuration
|
||||||
(`.bashrc` or `.zshrc`) so the `opencode` function is available in new sessions.
|
(`.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
|
## Usage
|
||||||
|
|
||||||
From any project directory:
|
From any project directory:
|
||||||
|
|
|
||||||
0
container-home/.gitkeep
Normal file
0
container-home/.gitkeep
Normal file
|
|
@ -15,12 +15,11 @@ services:
|
||||||
tty: true
|
tty: true
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
HOME: "${PWD}/data"
|
|
||||||
UID: "${UID}"
|
UID: "${UID}"
|
||||||
GID: "${GID}"
|
GID: "${GID}"
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
# Current project (read–write)
|
- "${CONTAINER_HOME}:/home/${USER}/"
|
||||||
- "${PWD}:${PWD}"
|
- "${PWD}:${PWD}"
|
||||||
|
|
||||||
cap_drop:
|
cap_drop:
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,11 @@ opencode() {
|
||||||
UID="$uid" \
|
UID="$uid" \
|
||||||
GID="$gid" \
|
GID="$gid" \
|
||||||
USER="$user" \
|
USER="$user" \
|
||||||
|
CONTAINER_HOME="$OPENCODE_CONTAINER_DIR/container-home" \
|
||||||
docker compose \
|
docker compose \
|
||||||
-f "$OPENCODE_CONTAINER_DIR/docker-compose.yaml" \
|
-f "$OPENCODE_CONTAINER_DIR/docker-compose.yaml" \
|
||||||
run --rm \
|
run --rm \
|
||||||
-u "$uid:$gid" \
|
-u "$uid:$gid" \
|
||||||
opencode /home/"$user"/.opencode/bin/opencode "$@" \
|
opencode opencode "$@" \
|
||||||
2> >(grep -v "No services to build" >&2)
|
2> >(grep -v "No services to build" >&2)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue