Skip to content

Commit 587bc07

Browse files
committed
feat(docker): add docker support for opencode with litellm integration
- Create Dockerfile_litellm based on Ubuntu 24.04 - Extract and install OpenCode from opencode-linux-x64.tar.gz - Add health check and non-root user for security - Expose port 3000 and set default start command - Add Docker build workflow to ai-codespark-release.yml - Build and push images to GitHub Container Registry - Tag with version and latest - Depend on build-cli-linux job for artifacts - Enable GitHub Actions cache for faster builds Images will be published to ghcr.io/ai-codespark/opencode on each release.
1 parent 82ed483 commit 587bc07

File tree

3 files changed

+180
-0
lines changed

3 files changed

+180
-0
lines changed

.github/workflows/ai-codespark-release.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,3 +263,51 @@ jobs:
263263
with:
264264
name: opencode-vscode-extension
265265
path: sdks/vscode/opencode-vscode-extension.vsix
266+
267+
build-docker:
268+
runs-on: ubuntu-latest
269+
if: github.repository == 'ai-codespark/opencode'
270+
needs: build-cli-linux
271+
steps:
272+
- uses: actions/checkout@v3
273+
with:
274+
fetch-depth: 0
275+
276+
- run: git fetch --force --tags
277+
278+
- name: Set up Docker Buildx
279+
uses: docker/setup-buildx-action@v3
280+
281+
- name: Log in to GitHub Container Registry
282+
uses: docker/login-action@v3
283+
with:
284+
registry: ghcr.io
285+
username: ${{ github.actor }}
286+
password: ${{ secrets.AI_CODESPARK_TOKEN }}
287+
288+
- name: Set version
289+
run: |
290+
VERSION="${{ github.event.release.tag_name }}"
291+
VERSION="${VERSION#v}"
292+
echo "RELEASE_VERSION=$VERSION" >> $GITHUB_ENV
293+
294+
- name: Download CLI artifact
295+
uses: actions/download-artifact@v4
296+
with:
297+
name: opencode-cli-linux-x64
298+
path: .
299+
300+
- name: Build and push Docker image
301+
uses: docker/build-push-action@v5
302+
with:
303+
context: .
304+
file: ./Dockerfile_litellm
305+
push: true
306+
platforms: linux/amd64
307+
build-args: |
308+
OPENCODE_VERSION=${{ env.RELEASE_VERSION }}
309+
tags: |
310+
ghcr.io/${{ github.repository }}:${{ env.RELEASE_VERSION }}
311+
ghcr.io/${{ github.repository }}:latest
312+
cache-from: type=gha
313+
cache-to: type=gha,mode=max

Dockerfile_litellm

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
FROM ubuntu:24.04
2+
3+
LABEL maintainer="AI CodeSpark <[email protected]>"
4+
LABEL description="OpenCode - AI-powered code intelligence platform running on Ubuntu"
5+
6+
# Install system dependencies
7+
RUN apt-get update && apt-get install -y \
8+
curl \
9+
wget \
10+
ca-certificates \
11+
unzip \
12+
&& rm -rf /var/lib/apt/lists/*
13+
14+
# Set working directory
15+
WORKDIR /app
16+
17+
# Copy the opencode-linux-x64 tarball
18+
ARG OPENCODE_VERSION
19+
COPY opencode-linux-x64.tar.gz /tmp/opencode-linux-x64.tar.gz
20+
21+
# Extract and install OpenCode
22+
RUN mkdir -p /usr/local/opencode && \
23+
tar -xzf /tmp/opencode-linux-x64.tar.gz -C /usr/local/opencode && \
24+
rm /tmp/opencode-linux-x64.tar.gz && \
25+
ln -s /usr/local/opencode/opencode /usr/local/bin/opencode && \
26+
chmod +x /usr/local/opencode/opencode
27+
28+
# Set environment variables
29+
ENV OPENCODE_VERSION=${OPENCODE_VERSION}
30+
ENV OPENCODE_CHANNEL=latest
31+
ENV PATH="/usr/local/opencode:${PATH}"
32+
33+
# Create a non-root user for running OpenCode
34+
RUN useradd -m -s /bin/bash opencode && \
35+
chown -R opencode:opencode /app
36+
37+
USER opencode
38+
39+
# Expose default port (if applicable)
40+
EXPOSE 3000
41+
42+
# Health check
43+
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
44+
CMD opencode --version || exit 1
45+
46+
# Default command
47+
CMD ["opencode", "start"]

README_litellm.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,91 @@ export LITELLM_MODEL_NAME="gpt-4"
2323

2424
Then run OpenCode. The model will be automatically available.
2525

26+
## Running with Docker
27+
28+
OpenCode is available as a Docker image for easy deployment on Ubuntu-based systems.
29+
30+
### Pull and Run
31+
32+
Pull the latest image from GitHub Container Registry:
33+
34+
```bash
35+
docker pull ghcr.io/ai-codespark/opencode:latest
36+
```
37+
38+
Run OpenCode with environment variables:
39+
40+
```bash
41+
docker run -d \
42+
--name opencode \
43+
-p 3000:3000 \
44+
-e LITELLM_BASE_URL="http://host.docker.internal:4000" \
45+
-e LITELLM_API_KEY="sk-your-api-key" \
46+
-e LITELLM_MODEL_NAME="gpt-4" \
47+
ghcr.io/ai-codespark/opencode:latest
48+
```
49+
50+
### Docker Compose
51+
52+
Create a `docker-compose.yml` file:
53+
54+
```yaml
55+
version: '3.8'
56+
57+
services:
58+
opencode:
59+
image: ghcr.io/ai-codespark/opencode:latest
60+
container_name: opencode
61+
ports:
62+
- "3000:3000"
63+
environment:
64+
- LITELLM_BASE_URL=http://litellm:4000
65+
- LITELLM_API_KEY=${LITELLM_API_KEY}
66+
- LITELLM_MODEL_NAME=gpt-4
67+
depends_on:
68+
- litellm
69+
restart: unless-stopped
70+
71+
litellm:
72+
image: ghcr.io/berriai/litellm:latest
73+
container_name: litellm
74+
ports:
75+
- "4000:4000"
76+
volumes:
77+
- ./litellm-config.yaml:/app/config.yaml
78+
command: --config /app/config.yaml
79+
restart: unless-stopped
80+
```
81+
82+
Then start both services:
83+
84+
```bash
85+
docker-compose up -d
86+
```
87+
88+
### Volume Mounting for Configuration
89+
90+
To persist configuration and data, mount volumes:
91+
92+
```bash
93+
docker run -d \
94+
--name opencode \
95+
-p 3000:3000 \
96+
-v $(pwd)/opencode-config:/home/opencode/.config/opencode \
97+
-v $(pwd)/opencode-data:/home/opencode/.local/share/opencode \
98+
-e LITELLM_BASE_URL="http://host.docker.internal:4000" \
99+
-e LITELLM_API_KEY="sk-your-api-key" \
100+
-e LITELLM_MODEL_NAME="gpt-4" \
101+
ghcr.io/ai-codespark/opencode:latest
102+
```
103+
104+
### Available Tags
105+
106+
- `latest` - Latest stable release
107+
- `v1.x.x` - Specific version tags (e.g., `v1.0.0`)
108+
109+
Images are automatically built and published to GitHub Container Registry on each release.
110+
26111
## Environment Variables
27112

28113
### `LITELLM_BASE_URL`

0 commit comments

Comments
 (0)