Skip to content

Commit 57c878f

Browse files
authored
feat(docker): add self-hosted deployment with multi-stage build (anomalyco#184)
* feat(docker): add self-hosted deployment with multi-stage build - Add multi-stage Dockerfile building from source with ARM64/AMD64 support - Bundle desktop UI into static directory for web serving via shuvcode serve - Add docker-compose.yml with workspace volumes and API key injection - Add .dockerignore to exclude unnecessary files from build context - Configure git in container with customizable user identity - Document Docker and PWA features in fork-features.json * fix: restore vite-plugin-pwa dependency lost in upstream merge * fix: restore ghostty-opentui dependency lost in upstream merge
1 parent 1028a0c commit 57c878f

8 files changed

Lines changed: 566 additions & 13 deletions

File tree

‎.dockerignore‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Git
2+
.git
3+
4+
# IDE
5+
.idea
6+
.vscode
7+
*.swp
8+
*~
9+
10+
# Build artifacts (we build fresh in Docker)
11+
node_modules
12+
dist
13+
ts-dist
14+
.turbo
15+
target
16+
17+
# Development files
18+
.DS_Store
19+
.opencode
20+
.worktrees
21+
.sst
22+
.env
23+
playground
24+
tmp
25+
.serena
26+
refs
27+
Session.vim
28+
opencode.json
29+
a.out
30+
.scripts
31+
32+
# Documentation (not needed for build)
33+
docs/
34+
CONTEXT/
35+
specs/
36+
logs/
37+
38+
# Tauri (native desktop app - not needed for Docker)
39+
packages/tauri/src-tauri/target

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ opencode.json
2121
a.out
2222
target
2323
.scripts
24+
docker/workspace

‎bun.lock‎

Lines changed: 336 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎docker/docker-compose.yml‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Docker Compose for running shuvcode
2+
#
3+
# Quick start:
4+
# cd docker && docker compose up
5+
#
6+
# This builds everything from source and starts the server at http://localhost:4096
7+
8+
services:
9+
shuvcode:
10+
build:
11+
context: ..
12+
dockerfile: packages/opencode/Dockerfile
13+
ports:
14+
- "4096:4096"
15+
volumes:
16+
# Mount a workspace directory for the agent to work in
17+
- ./workspace:/workspace
18+
# Persist opencode data (sessions, config, etc.)
19+
- shuvcode-data:/root/.opencode
20+
environment:
21+
# API keys - set these in your environment or .env file
22+
- ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY:-}
23+
- OPENAI_API_KEY=${OPENAI_API_KEY:-}
24+
- OPENCODE_API_KEY=${OPENCODE_API_KEY:-}
25+
# Git user config - set these to use your own identity for commits
26+
- GIT_AUTHOR_NAME=${GIT_AUTHOR_NAME:-shuvcode}
27+
- GIT_AUTHOR_EMAIL=${GIT_AUTHOR_EMAIL:-shuvcode@localhost}
28+
- GIT_COMMITTER_NAME=${GIT_COMMITTER_NAME:-shuvcode}
29+
- GIT_COMMITTER_EMAIL=${GIT_COMMITTER_EMAIL:-shuvcode@localhost}
30+
working_dir: /workspace
31+
restart: unless-stopped
32+
33+
volumes:
34+
shuvcode-data:

‎packages/desktop/package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"typescript": "catalog:",
2727
"vite": "catalog:",
2828
"vite-plugin-icons-spritesheet": "3.0.1",
29+
"vite-plugin-pwa": "1.2.0",
2930
"vite-plugin-solid": "catalog:"
3031
},
3132
"dependencies": {

‎packages/opencode/Dockerfile‎

Lines changed: 51 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,59 @@
1-
FROM alpine AS base
1+
# Multi-stage Dockerfile that builds shuvcode from source
2+
#
3+
# Build: docker build -t shuvcode:local .
4+
# Run: docker run -p 4096:4096 shuvcode:local
5+
6+
# Stage 1: Build the CLI binary and desktop UI
7+
FROM oven/bun:1 AS builder
8+
9+
# Install git (needed by build script to detect branch)
10+
RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/*
11+
12+
WORKDIR /app
13+
14+
# Copy everything (bun workspaces need the full structure)
15+
COPY . .
16+
17+
# Install dependencies
18+
RUN bun install
19+
20+
# Build the desktop UI
21+
RUN cd packages/desktop && bun run build
22+
23+
# Build the CLI (all platforms - needed because runtime is Alpine/musl)
24+
# Set channel to "docker" since .git is not available in build context
25+
ENV OPENCODE_CHANNEL=docker
26+
RUN cd packages/opencode && bun run build
27+
28+
# Copy desktop build to static directory
29+
RUN cp -r packages/desktop/dist packages/opencode/static
30+
31+
# Stage 2: Runtime image
32+
FROM alpine
233

3-
# Disable the runtime transpiler cache by default inside Docker containers.
4-
# On ephemeral containers, the cache is not useful
534
ARG BUN_RUNTIME_TRANSPILER_CACHE_PATH=0
635
ENV BUN_RUNTIME_TRANSPILER_CACHE_PATH=${BUN_RUNTIME_TRANSPILER_CACHE_PATH}
7-
RUN apk add libgcc libstdc++ ripgrep git
836

9-
FROM base AS build-amd64
10-
COPY dist/shuvcode-linux-x64-baseline-musl/bin/shuvcode /usr/local/bin/shuvcode
11-
COPY static /usr/local/bin/static
37+
RUN apk add --no-cache libgcc libstdc++ ripgrep git \
38+
&& git config --global init.defaultBranch main
39+
40+
# Git user config - override these at runtime via environment variables
41+
ENV GIT_AUTHOR_NAME="shuvcode" \
42+
GIT_AUTHOR_EMAIL="shuvcode@localhost" \
43+
GIT_COMMITTER_NAME="shuvcode" \
44+
GIT_COMMITTER_EMAIL="shuvcode@localhost"
1245

13-
FROM base AS build-arm64
14-
COPY dist/shuvcode-linux-arm64-musl/bin/shuvcode /usr/local/bin/shuvcode
15-
COPY static /usr/local/bin/static
46+
# Detect architecture and copy appropriate binary
47+
ARG TARGETARCH=amd64
48+
COPY --from=builder /app/packages/opencode/dist/shuvcode-linux-x64-baseline-musl/bin/shuvcode /tmp/shuvcode-amd64
49+
COPY --from=builder /app/packages/opencode/dist/shuvcode-linux-arm64-musl/bin/shuvcode /tmp/shuvcode-arm64
50+
RUN cp /tmp/shuvcode-${TARGETARCH} /usr/local/bin/shuvcode && rm /tmp/shuvcode-*
51+
52+
COPY --from=builder /app/packages/opencode/static /usr/local/bin/static
1653

17-
ARG TARGETARCH
18-
FROM build-${TARGETARCH}
1954
RUN shuvcode --version
55+
56+
EXPOSE 4096
57+
2058
ENTRYPOINT ["shuvcode"]
59+
CMD ["serve", "--port", "4096", "--hostname", "0.0.0.0"]

‎packages/opencode/package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
"decimal.js": "10.5.0",
8686
"diff": "catalog:",
8787
"fuzzysort": "3.1.0",
88+
"ghostty-opentui": "1.3.7",
8889
"gray-matter": "4.0.3",
8990
"hono": "catalog:",
9091
"hono-openapi": "catalog:",

‎script/sync/fork-features.json‎

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"$schema": "https://json-schema.org/draft/2020-12/schema",
33
"description": "Fork-specific features from upstream PRs that must be preserved during merges",
44
"lastUpdated": "2025-12-21",
5+
"note": "Updated to include Docker self-hosted deployment and PWA service worker features",
56
"apiDependencies": [
67
{
78
"api": "useDialog",
@@ -1005,6 +1006,108 @@
10051006
"markers": ["ideStatus", "Ide.status()"]
10061007
}
10071008
]
1009+
},
1010+
{
1011+
"pr": 0,
1012+
"title": "Docker self-hosted deployment",
1013+
"author": "fork",
1014+
"status": "fork-only",
1015+
"description": "Multi-stage Dockerfile that builds shuvcode from source with ARM64/AMD64 support. Includes docker-compose.yml for easy deployment with workspace volume mounting, API key injection, and git user configuration. Static desktop UI bundled into container for web access.",
1016+
"files": ["packages/opencode/Dockerfile", "docker/docker-compose.yml"],
1017+
"criticalCode": [
1018+
{
1019+
"file": "packages/opencode/Dockerfile",
1020+
"description": "Multi-stage build with builder and runtime stages",
1021+
"markers": ["FROM oven/bun:1 AS builder", "FROM alpine", "ENTRYPOINT [\"shuvcode\"]"]
1022+
},
1023+
{
1024+
"file": "packages/opencode/Dockerfile",
1025+
"description": "Desktop UI copied to static directory for web serving",
1026+
"markers": [
1027+
"cp -r packages/desktop/dist packages/opencode/static",
1028+
"COPY --from=builder /app/packages/opencode/static"
1029+
]
1030+
},
1031+
{
1032+
"file": "packages/opencode/Dockerfile",
1033+
"description": "Multi-arch binary selection (ARM64/AMD64)",
1034+
"markers": ["TARGETARCH=amd64", "shuvcode-linux-x64-baseline-musl", "shuvcode-linux-arm64-musl"]
1035+
},
1036+
{
1037+
"file": "packages/opencode/Dockerfile",
1038+
"description": "Git installed and configured in runtime image",
1039+
"markers": ["apk add --no-cache libgcc libstdc++ ripgrep git", "git config --global init.defaultBranch main"]
1040+
},
1041+
{
1042+
"file": "docker/docker-compose.yml",
1043+
"description": "Workspace volume mounting and API key environment variables",
1044+
"markers": ["./workspace:/workspace", "ANTHROPIC_API_KEY", "OPENAI_API_KEY", "GIT_AUTHOR_NAME"]
1045+
}
1046+
]
1047+
},
1048+
{
1049+
"pr": 0,
1050+
"title": "Desktop PWA service worker",
1051+
"author": "fork",
1052+
"status": "fork-only",
1053+
"description": "Progressive Web App support via vite-plugin-pwa with offline caching, auto-update, and runtime caching for Google Fonts and jsDelivr CDN. Enables installable web app experience with proper manifest and iOS meta tags.",
1054+
"files": [
1055+
"packages/desktop/vite.config.ts",
1056+
"packages/desktop/index.html",
1057+
"packages/desktop/src/index.css",
1058+
"packages/desktop/public/site.webmanifest"
1059+
],
1060+
"criticalCode": [
1061+
{
1062+
"file": "packages/desktop/vite.config.ts",
1063+
"description": "VitePWA plugin configuration with workbox caching",
1064+
"markers": [
1065+
"import { VitePWA }",
1066+
"VitePWA({",
1067+
"registerType: \"autoUpdate\"",
1068+
"workbox:",
1069+
"maximumFileSizeToCacheInBytes: 5 * 1024 * 1024",
1070+
"runtimeCaching:"
1071+
]
1072+
},
1073+
{
1074+
"file": "packages/desktop/vite.config.ts",
1075+
"description": "API route denylist to prevent caching backend calls",
1076+
"markers": ["navigateFallbackDenylist: apiRoutes.map"]
1077+
},
1078+
{
1079+
"file": "packages/desktop/index.html",
1080+
"description": "iOS PWA meta tags and viewport-fit=cover for safe areas",
1081+
"markers": [
1082+
"viewport-fit=cover",
1083+
"apple-mobile-web-app-capable",
1084+
"apple-mobile-web-app-status-bar-style",
1085+
"apple-mobile-web-app-title"
1086+
]
1087+
},
1088+
{
1089+
"file": "packages/desktop/src/index.css",
1090+
"description": "Safe area CSS variables for notch/home indicator",
1091+
"markers": [
1092+
"--safe-area-inset-top: env(safe-area-inset-top",
1093+
"--safe-area-inset-bottom: env(safe-area-inset-bottom"
1094+
]
1095+
},
1096+
{
1097+
"file": "packages/desktop/src/index.css",
1098+
"description": "PWA standalone mode styles for proper viewport sizing",
1099+
"markers": ["@media (display-mode: standalone)", "--pwa-top-offset", "min-height: 100dvh"]
1100+
},
1101+
{
1102+
"file": "packages/desktop/public/site.webmanifest",
1103+
"description": "Web app manifest with shuvcode branding and standalone display",
1104+
"markers": [
1105+
"\"name\": \"shuvcode\"",
1106+
"\"display\": \"standalone\"",
1107+
"\"display_override\": [\"standalone\", \"fullscreen\"]"
1108+
]
1109+
}
1110+
]
10081111
}
10091112
]
10101113
}

0 commit comments

Comments
 (0)