129 lines
4.6 KiB
Docker
129 lines
4.6 KiB
Docker
FROM smanx/opencode:1.18.13@sha256:b976acda21efffacd44abd7847dac7d646910dbaa477d1877e2881b39cf22a91 AS base
|
|
USER root
|
|
ARG UBUNTU_APT_MIRROR=
|
|
ARG PYPI_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple
|
|
ARG PYPI_TRUSTED_HOST=pypi.tuna.tsinghua.edu.cn
|
|
ENV VIRTUAL_ENV=/opt/venv
|
|
ENV PATH="$VIRTUAL_ENV/bin:/root/.local/bin:$PATH"
|
|
ENV PIP_INDEX_URL=${PYPI_INDEX_URL}
|
|
ENV PIP_TRUSTED_HOST=${PYPI_TRUSTED_HOST}
|
|
ENV UV_INDEX_URL=${PYPI_INDEX_URL}
|
|
|
|
COPY vendor/bun-linux-x64.zip /tmp/bun.zip
|
|
|
|
RUN if [ -n "${UBUNTU_APT_MIRROR}" ]; then \
|
|
sed -i "s|http://archive.ubuntu.com|https://${UBUNTU_APT_MIRROR}|g; s|http://security.ubuntu.com|https://${UBUNTU_APT_MIRROR}|g" /etc/apt/sources.list 2>/dev/null || true; \
|
|
sed -i "s|http://archive.ubuntu.com|https://${UBUNTU_APT_MIRROR}|g; s|http://security.ubuntu.com|https://${UBUNTU_APT_MIRROR}|g" /etc/apt/sources.list.d/*.sources 2>/dev/null || true; \
|
|
fi && \
|
|
apt-get update && apt-get install -y --no-install-recommends \
|
|
curl \
|
|
jq \
|
|
libseccomp2 \
|
|
unzip \
|
|
python3 \
|
|
python3-venv && \
|
|
unzip -q /tmp/bun.zip -d /usr/local && \
|
|
mv /usr/local/bun-linux-x64 /usr/local/bun && \
|
|
ln -sf /usr/local/bun/bun /usr/local/bin/bun && \
|
|
rm -f /tmp/bun.zip && \
|
|
curl -LsSf https://astral.sh/uv/install.sh | sh && \
|
|
ln -s /root/.local/bin/uv /usr/local/bin/uv && \
|
|
ln -sf /usr/bin/python3 /usr/local/bin/python && \
|
|
mkdir -p /root/.config/pip && \
|
|
printf "[global]\nindex-url = %s\ntrusted-host = %s\n" "$PIP_INDEX_URL" "$PIP_TRUSTED_HOST" > /root/.config/pip/pip.conf && \
|
|
uv venv "$VIRTUAL_ENV" && \
|
|
uv pip install --python "$VIRTUAL_ENV/bin/python" \
|
|
--index-url "$UV_INDEX_URL" \
|
|
pip \
|
|
setuptools \
|
|
wheel \
|
|
requests \
|
|
httpx \
|
|
pydantic \
|
|
python-dotenv \
|
|
rich \
|
|
ipython \
|
|
pytest && \
|
|
(getent group 10001 >/dev/null || groupadd --gid 10001 tjwater-sandbox) && \
|
|
(getent passwd 10001 >/dev/null || useradd --uid 10001 --gid 10001 --no-create-home --shell /usr/sbin/nologin tjwater-sandbox) && \
|
|
rm -rf /var/lib/apt/lists/*
|
|
|
|
FROM base AS opencode-builder
|
|
|
|
ARG OPENCODE_SOURCE_COMMIT=a105350812f05f914c768e468559dbd6bd508d8e
|
|
ARG OPENCODE_PATCH_VERSION=1.18.13-tjwater.1
|
|
WORKDIR /tmp/opencode-src
|
|
|
|
RUN git init . && \
|
|
git remote add origin https://github.com/anomalyco/opencode.git && \
|
|
git fetch --depth 1 origin "$OPENCODE_SOURCE_COMMIT" && \
|
|
git checkout --detach FETCH_HEAD
|
|
|
|
COPY patches/opencode-1.18.13-message-phase.patch /tmp/opencode-message-phase.patch
|
|
|
|
RUN git apply --check /tmp/opencode-message-phase.patch && \
|
|
git apply /tmp/opencode-message-phase.patch && \
|
|
bun install --frozen-lockfile --ignore-scripts && \
|
|
bun test --cwd packages/llm test/provider/openai-responses.test.ts && \
|
|
OPENCODE_VERSION="$OPENCODE_PATCH_VERSION" bun run --cwd packages/opencode build --single --skip-install --skip-embed-web-ui && \
|
|
case "$(uname -m)" in \
|
|
x86_64) binary=packages/opencode/dist/opencode-linux-x64/bin/opencode ;; \
|
|
aarch64|arm64) binary=packages/opencode/dist/opencode-linux-arm64/bin/opencode ;; \
|
|
*) echo "unsupported OpenCode build architecture: $(uname -m)" >&2; exit 1 ;; \
|
|
esac && \
|
|
install -D -m 0755 "$binary" /out/opencode
|
|
|
|
FROM base AS deps
|
|
|
|
WORKDIR /app
|
|
|
|
COPY package.json bun.lock ./
|
|
COPY .opencode/package.json .opencode/bun.lock ./.opencode/
|
|
RUN bun install --frozen-lockfile
|
|
|
|
FROM base AS build
|
|
WORKDIR /app
|
|
|
|
COPY --from=deps /app/node_modules ./node_modules
|
|
COPY --from=deps /app/.opencode/node_modules ./.opencode/node_modules
|
|
COPY package.json bun.lock ./
|
|
COPY tsconfig.json opencode.json README.md .gitignore Dockerfile ./
|
|
COPY src ./src
|
|
COPY cli ./cli
|
|
COPY scripts ./scripts
|
|
COPY .opencode ./.opencode
|
|
RUN bun run check
|
|
|
|
FROM build AS test
|
|
COPY --from=opencode-builder /out/opencode /usr/local/bin/opencode
|
|
RUN apt-get update && apt-get install -y --no-install-recommends nodejs && \
|
|
rm -rf /var/lib/apt/lists/*
|
|
COPY contracts ./contracts
|
|
COPY node-tests ./node-tests
|
|
COPY scripts ./scripts
|
|
COPY tests ./tests
|
|
RUN bun run test:ci
|
|
|
|
FROM build AS runner
|
|
WORKDIR /app
|
|
|
|
COPY --from=opencode-builder /out/opencode /usr/local/bin/opencode
|
|
RUN opencode --version
|
|
|
|
ENV NODE_ENV=production
|
|
ENV HOST=0.0.0.0
|
|
ENV PORT=8787
|
|
ENV OPENCODE_HOST=127.0.0.1
|
|
ENV OPENCODE_HOSTNAME=127.0.0.1
|
|
ENV TJWATER_CLI_PATH=./cli/tjwater-cli
|
|
|
|
COPY entrypoint.sh /entrypoint.sh
|
|
RUN chmod +x /entrypoint.sh ./cli/tjwater-cli
|
|
|
|
ENTRYPOINT ["/entrypoint.sh"]
|
|
|
|
EXPOSE 8787
|
|
HEALTHCHECK --interval=30s --timeout=5s --start-period=60s --retries=3 \
|
|
CMD curl --fail --silent --show-error "http://127.0.0.1:${PORT}/health" >/dev/null || exit 1
|
|
CMD ["bun", "src/server.ts"]
|