Files
opencode-container/Dockerfile
T

110 lines
2.9 KiB
Docker

# syntax=docker/dockerfile:1
ARG UBUNTU_VERSION=26.04
FROM ubuntu:${UBUNTU_VERSION}
ARG NODE_VERSION=24.21.0
ARG OPENCODE_VERSION=2.0.22
ARG EXTRA_APT_PACKAGES=""
ARG DEV_UID=1000
ARG DEV_GID=1000
ENV DEBIAN_FRONTEND=noninteractive
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
# System packages
RUN apt-get update \
&& apt-get upgrade -y \
&& apt-get install -y --no-install-recommends \
bash \
build-essential \
ca-certificates \
curl \
fd-find \
file \
git \
gzip \
jq \
less \
locales \
maven \
neovim \
openjdk-11-jdk \
openjdk-17-jdk \
openssh-client \
iputils-ping \
pkg-config \
procps \
python3 \
python3-dev \
python3-pip \
python3-venv \
ripgrep \
tar \
tree \
unzip \
util-linux \
wget \
xz-utils \
zip \
&& echo 'en_US.UTF-8 UTF-8' > /etc/locale.gen \
&& locale-gen \
&& ln -s "$(command -v fdfind)" /usr/local/bin/fd
RUN if [ -n "${EXTRA_APT_PACKAGES}" ]; then \
echo "Installing extra packages: ${EXTRA_APT_PACKAGES}" \
&& apt-get install -y --no-install-recommends ${EXTRA_APT_PACKAGES}; \
fi
RUN rm -rf /var/lib/apt/lists/*
COPY ./certs /usr/local/share/ca-certificates
RUN update-ca-certificates
ENV NODE_EXTRA_CA_CERTS=/etc/ssl/certs/ca-certificates.crt
# Remove ubuntu user and create the dev one with host uid and gid
RUN (userdel -r ubuntu 2>/dev/null || true) \
&& (groupdel ubuntu 2>/dev/null || true) \
&& groupadd --gid "${DEV_GID}" dev \
&& useradd --uid "${DEV_UID}" --gid "${DEV_GID}" --create-home --shell /bin/bash dev
# Node.js + OpenCode
RUN f="node-v${NODE_VERSION}-linux-x64.tar.xz" \
&& curl -fsSLO "https://nodejs.org/dist/v${NODE_VERSION}/${f}" \
&& curl -fsSLO "https://nodejs.org/dist/v${NODE_VERSION}/SHASUMS256.txt" \
&& grep " ${f}\$" SHASUMS256.txt | sha256sum -c - \
&& tar -xJf "node-v${NODE_VERSION}-linux-x64.tar.xz" -C /usr/local --strip-components=1 \
&& rm -f "${f}" SHASUMS256.txt \
&& echo -n "node version: " && node --version \
&& echo -n "npm version: " && npm --version \
&& npm install -g "@opencode/cli@${OPENCODE_VERSION}" \
&& echo -n "opencode version: " && opencode --version \
&& npm cache clean --force
# User directories and dot expansion
RUN mkdir -p \
/workspace \
/home/dev/.config/opencode \
/home/dev/.local/share/opencode \
/home/dev/.cache/opencode \
/home/dev/.cache/pip \
/home/dev/.npm \
/home/dev/.m2 \
&& chown -R dev:dev /workspace /home/dev \
&& printf '%s\n' 'shopt -s dotglob' >> /etc/bash.bashrc
# Runtime
USER dev
ENV HOME=/home/dev \
EDITOR=nvim \
VISUAL=nvim \
PIP_CACHE_DIR=/home/dev/.cache/pip \
NPM_CONFIG_CACHE=/home/dev/.npm
WORKDIR /workspace
CMD ["bash"]