feat(docker): one-line installer and release Compose file

Add scripts/install.sh, a one-line installer that checks Docker and
Compose v2, installs into ~/opencode-manager (override with OCM_DIR),
prompts for an optional OpenCode config import, a repos folder mount and
LAN sign-in, then pulls and starts the published image.

- Add docker-compose.release.yml, which runs the published image under
  the Compose project name ocm; a checkout's docker-compose.yml keeps
  building from source
- Generate AUTH_SECRET on first container start and persist it to the
  data volume when unset, so Compose installs need no .env
- Refuse to install over a source checkout or beside an existing
  install, so volumes and the auth secret are not silently replaced
- Test the installer, entrypoint secret handling, and the two Compose
  files staying in step
This commit is contained in:
Chris Scott committed 2026-10-05 15:07:23 -04:00
1 parent 87636bf1ff
commit 27996ed12d
10 files changed
+734 -31

No files matched your search

+53 -7
View File
@@ -1,9 +1,10 @@
import { describe, it, expect, beforeEach, afterEach } from 'vitest'
import { spawnSync } from 'child_process'
import { mkdirSync, writeFileSync, rmSync, chmodSync, existsSync, readFileSync } from 'fs'
import { mkdirSync, writeFileSync, rmSync, chmodSync, existsSync, readFileSync, statSync } from 'fs'
import { join } from 'path'
import { tmpdir } from 'os'
import { repoRoot } from '../helpers/repo-root'
import { extractShellFunction as extractEntrypointFunction } from '../helpers/shell-function'
const entrypointPath = join(repoRoot, 'scripts/docker-entrypoint.sh')
@@ -16,12 +17,7 @@ const writeStub = (name: string, body: string) => {
chmodSync(file, 0o755)
}
const extractShellFunction = (name: string) => {
const entrypoint = readFileSync(entrypointPath, 'utf-8')
const match = entrypoint.match(new RegExp(`^${name}\\(\\) \\{\\n[\\s\\S]*?\\n\\}`, 'm'))
if (!match) throw new Error(`${name}() not found in docker-entrypoint.sh`)
return match[0]
}
const extractShellFunction = (name: string) => extractEntrypointFunction(entrypointPath, name)
const extractSupportedFloor = () => {
const match = readFileSync(entrypointPath, 'utf-8').match(/^OPENCODE_SUPPORTED_FLOOR="[^"]+"$/m)
@@ -169,6 +165,56 @@ describe('grant_kvm_access', () => {
})
})
describe('ensure_auth_secret', () => {
const runEnsureAuthSecret = (secretFile: string, env: Record<string, string> = {}) => {
const scriptPath = join(stubDir, 'test.sh')
writeFileSync(
scriptPath,
`set -e\n${extractShellFunction('ensure_auth_secret')}\nensure_auth_secret ${JSON.stringify(secretFile)}\nprintf 'SECRET=%s\\n' "$AUTH_SECRET"\n`,
)
const baseEnv = { ...process.env }
delete baseEnv.AUTH_SECRET
return spawnSync('bash', [scriptPath], { encoding: 'utf-8', env: { ...baseEnv, ...env } })
}
const exportedSecret = (stdout: string) => stdout.match(/^SECRET=(.*)$/m)?.[1] ?? ''
it('generates, persists, and exports a private secret when AUTH_SECRET is unset', () => {
const secretFile = join(stubDir, 'data', '.auth-secret')
const res = runEnsureAuthSecret(secretFile)
expect(res.status).toBe(0)
expect(res.stdout).toContain(`Generated AUTH_SECRET and saved it to ${secretFile}`)
const secret = exportedSecret(res.stdout)
expect(Buffer.from(secret, 'base64')).toHaveLength(32)
expect(readFileSync(secretFile, 'utf-8').trim()).toBe(secret)
expect(statSync(secretFile).mode & 0o777).toBe(0o600)
})
it('reuses the persisted secret on later starts', () => {
const secretFile = join(stubDir, 'data', '.auth-secret')
const first = exportedSecret(runEnsureAuthSecret(secretFile).stdout)
const second = runEnsureAuthSecret(secretFile)
expect(second.status).toBe(0)
expect(second.stdout).not.toContain('Generated AUTH_SECRET')
expect(exportedSecret(second.stdout)).toBe(first)
})
it('keeps an explicit AUTH_SECRET and writes nothing', () => {
const secretFile = join(stubDir, 'data', '.auth-secret')
const res = runEnsureAuthSecret(secretFile, { AUTH_SECRET: 'explicit-secret' })
expect(res.status).toBe(0)
expect(exportedSecret(res.stdout)).toBe('explicit-secret')
expect(existsSync(secretFile)).toBe(false)
})
it('fails when the secret file cannot be written', () => {
const blocker = join(stubDir, 'not-a-dir')
writeFileSync(blocker, '')
const res = runEnsureAuthSecret(join(blocker, '.auth-secret'))
expect(res.status).not.toBe(0)
expect(res.stdout).not.toContain('SECRET=')
})
})
const extractOpenCodeInstallSection = () => {
const entrypoint = readFileSync(entrypointPath, 'utf-8')
const startMarker = 'echo "Checking OpenCode installation..."'