Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 29 additions & 33 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,33 +1,29 @@
FROM node:24.15.0-bookworm

ARG OPENCODE_VERSION=latest

# set working directory
WORKDIR /app

# check architecture
RUN uname -m

# install opencode globally
RUN npm i -g "opencode-ai@${OPENCODE_VERSION}" && \
installed_version_raw="$(opencode --version)" && \
installed_version="${installed_version_raw#v}" && \
echo "Installed opencode version: ${installed_version}" && \
if [ "${OPENCODE_VERSION}" != "latest" ] && [ "${installed_version}" != "${OPENCODE_VERSION}" ]; then \
echo "Expected opencode version ${OPENCODE_VERSION}, got ${installed_version}" >&2; \
exit 1; \
fi

# non-root user (recommended)
RUN adduser --disabled-password opencode

# create necessary directories and set permissions
RUN mkdir -p /home/opencode/.local/share/opencode/ && \
mkdir -p /home/opencode/.local/state/opencode && \
mkdir -p /home/opencode/.config/opencode/ && \
chown -R opencode:opencode /home/opencode

# switch to non-root user
USER opencode

# docker buildx build --platform linux/amd64,linux/arm64 -t ghcr.io/pilinux/opencode:0.0.1 --output type=docker .
FROM node:24.15.0-bookworm

ARG OPENCODE_VERSION=latest

WORKDIR /app

RUN uname -m

RUN npm i -g "opencode-ai@${OPENCODE_VERSION}" && \
installed_version_raw="$(opencode --version)" && \
installed_version="${installed_version_raw#v}" && \
echo "Installed opencode version: ${installed_version}" && \
if [ "${OPENCODE_VERSION}" != "latest" ] && [ "${installed_version}" != "${OPENCODE_VERSION}" ]; then \
echo "Expected opencode version ${OPENCODE_VERSION}, got ${installed_version}" >&2; \
exit 1; \
fi

RUN adduser --disabled-password opencode

RUN mkdir -p /home/opencode/.local/share/opencode/ && \
mkdir -p /home/opencode/.local/state/opencode && \
mkdir -p /home/opencode/.config/opencode/ && \
chown -R opencode:opencode /home/opencode

COPY entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh

ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
CMD ["opencode", "serve", "--hostname", "0.0.0.0", "--port", "4096"]
18 changes: 18 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/sh
set -e

PUID="${PUID:-1000}"
PGID="${PGID:-1000}"

if [ "$(id -u)" = "0" ]; then
usermod -o -u "${PUID}" opencode
groupmod -o -g "${PGID}" opencode

chown -R "${PUID}:${PGID}" /home/opencode/.config /home/opencode/.local
chown "${PUID}:${PGID}" /home/opencode

export HOME=/home/opencode
exec setpriv --reuid "${PUID}" --regid "${PGID}" --clear-groups "$@"
fi

exec "$@"