mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 20:34:18 +01:00
fix(docker): drop startup /app re-chown to keep cold starts fast
This commit is contained in:
1 parent
4f0da40169
commit
dde09ac85b
5 files changed
+29
-57
No files matched your search
@@ -107,43 +107,35 @@ describe('resolve_target_ids', () => {
|
||||
|
||||
describe('align_container_user', () => {
|
||||
it('is a no-op when ids already match', () => {
|
||||
const res = runScript(
|
||||
'align_container_user node; echo "uidChanged=$OCM_UID_CHANGED gidChanged=$OCM_GID_CHANGED"',
|
||||
{ OCM_STUB_NODE_UID: '1000', OCM_STUB_NODE_GID: '1000', PUID: '1000', PGID: '1000' },
|
||||
)
|
||||
const res = runScript('align_container_user node', {
|
||||
OCM_STUB_NODE_UID: '1000', OCM_STUB_NODE_GID: '1000', PUID: '1000', PGID: '1000',
|
||||
})
|
||||
expect(res.status).toBe(0)
|
||||
expect(stubCalls()).toEqual([])
|
||||
expect(res.stdout).toContain('uidChanged=0 gidChanged=0')
|
||||
})
|
||||
|
||||
it('aligns both ids and records the change, group before user', () => {
|
||||
const res = runScript(
|
||||
'align_container_user node; echo "uidChanged=$OCM_UID_CHANGED gidChanged=$OCM_GID_CHANGED"',
|
||||
{ OCM_STUB_NODE_UID: '1000', OCM_STUB_NODE_GID: '1000', PUID: '1001', PGID: '1002' },
|
||||
)
|
||||
it('aligns both ids, group before user', () => {
|
||||
const res = runScript('align_container_user node', {
|
||||
OCM_STUB_NODE_UID: '1000', OCM_STUB_NODE_GID: '1000', PUID: '1001', PGID: '1002',
|
||||
})
|
||||
expect(res.status).toBe(0)
|
||||
expect(stubCalls()).toEqual(['groupmod -g 1002 node', 'usermod -u 1001 node'])
|
||||
expect(res.stdout).toContain('uidChanged=1 gidChanged=1')
|
||||
})
|
||||
|
||||
it('aligns only the gid when the uid already matches', () => {
|
||||
const res = runScript(
|
||||
'align_container_user node; echo "uidChanged=$OCM_UID_CHANGED gidChanged=$OCM_GID_CHANGED"',
|
||||
{ OCM_STUB_NODE_UID: '1001', PUID: '1001', PGID: '1002' },
|
||||
)
|
||||
const res = runScript('align_container_user node', {
|
||||
OCM_STUB_NODE_UID: '1001', PUID: '1001', PGID: '1002',
|
||||
})
|
||||
expect(res.status).toBe(0)
|
||||
expect(stubCalls()).toEqual(['groupmod -g 1002 node'])
|
||||
expect(res.stdout).toContain('uidChanged=0 gidChanged=1')
|
||||
})
|
||||
|
||||
it('aligns only the uid when the gid already matches', () => {
|
||||
const res = runScript(
|
||||
'align_container_user node; echo "uidChanged=$OCM_UID_CHANGED gidChanged=$OCM_GID_CHANGED"',
|
||||
{ OCM_STUB_NODE_GID: '1002', PUID: '1001', PGID: '1002' },
|
||||
)
|
||||
const res = runScript('align_container_user node', {
|
||||
OCM_STUB_NODE_GID: '1002', PUID: '1001', PGID: '1002',
|
||||
})
|
||||
expect(res.status).toBe(0)
|
||||
expect(stubCalls()).toEqual(['usermod -u 1001 node'])
|
||||
expect(res.stdout).toContain('uidChanged=1 gidChanged=0')
|
||||
})
|
||||
|
||||
it('defaults the account name to node', () => {
|
||||
@@ -165,26 +157,24 @@ describe('align_container_user', () => {
|
||||
expect(res.stdout).toMatch(/Aligning node user to uid 1001/)
|
||||
})
|
||||
|
||||
it('propagates groupmod failure without setting the gid change flag', () => {
|
||||
it('propagates groupmod failure', () => {
|
||||
writeStub('groupmod', `echo "groupmod $*" >> "$OCM_STUB_LOG"\nexit 1`)
|
||||
const res = runScript(
|
||||
'align_container_user node || echo "uidChanged=$OCM_UID_CHANGED gidChanged=$OCM_GID_CHANGED"',
|
||||
{ OCM_STUB_NODE_UID: '1000', OCM_STUB_NODE_GID: '1000', PUID: '1001', PGID: '1002' },
|
||||
)
|
||||
const res = runScript('align_container_user node || echo "failed"', {
|
||||
OCM_STUB_NODE_UID: '1000', OCM_STUB_NODE_GID: '1000', PUID: '1001', PGID: '1002',
|
||||
})
|
||||
expect(res.status).toBe(0)
|
||||
expect(stubCalls()).toEqual(['groupmod -g 1002 node'])
|
||||
expect(res.stdout).toContain('uidChanged=0 gidChanged=0')
|
||||
expect(res.stdout).toContain('failed')
|
||||
})
|
||||
|
||||
it('propagates usermod failure without setting the uid change flag', () => {
|
||||
it('propagates usermod failure', () => {
|
||||
writeStub('usermod', `echo "usermod $*" >> "$OCM_STUB_LOG"\nexit 1`)
|
||||
const res = runScript(
|
||||
'align_container_user node || echo "uidChanged=$OCM_UID_CHANGED gidChanged=$OCM_GID_CHANGED"',
|
||||
{ OCM_STUB_NODE_UID: '1000', OCM_STUB_NODE_GID: '1000', PUID: '1001', PGID: '1002' },
|
||||
)
|
||||
const res = runScript('align_container_user node || echo "failed"', {
|
||||
OCM_STUB_NODE_UID: '1000', OCM_STUB_NODE_GID: '1000', PUID: '1001', PGID: '1002',
|
||||
})
|
||||
expect(res.status).toBe(0)
|
||||
expect(stubCalls()).toEqual(['groupmod -g 1002 node', 'usermod -u 1001 node'])
|
||||
expect(res.stdout).toContain('uidChanged=0 gidChanged=1')
|
||||
expect(res.stdout).toContain('failed')
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -49,23 +49,14 @@ describe('entrypoint library wiring', () => {
|
||||
expect(warnIndex).toBeLessThan(chownIndex)
|
||||
})
|
||||
|
||||
it('realigns /app only when ids changed', () => {
|
||||
it('does not re-chown /app when ids change', () => {
|
||||
const entrypoint = read(entrypointPath)
|
||||
|
||||
expect(entrypoint).toContain('OCM_UID_CHANGED')
|
||||
expect(entrypoint).toContain('OCM_GID_CHANGED')
|
||||
|
||||
const conditionalBlockMatch = entrypoint.match(
|
||||
/if \[ "\$OCM_UID_CHANGED" = "1" \] \|\| \[ "\$OCM_GID_CHANGED" = "1" \]; then[\s\S]*?chown -R node:node \/app\nfi/,
|
||||
)
|
||||
expect(conditionalBlockMatch, 'conditional /app realign block must exist').not.toBeNull()
|
||||
|
||||
const workspaceChownMatch = entrypoint.match(/chown -R node:node [^\n]*\/workspace/)
|
||||
expect(workspaceChownMatch, 'pre-existing unconditional workspace chown must remain').not.toBeNull()
|
||||
const conditionalChownIndex = entrypoint.indexOf('chown -R node:node /app\n', conditionalBlockMatch!.index!)
|
||||
const workspaceChownIndex = entrypoint.indexOf(workspaceChownMatch![0])
|
||||
expect(conditionalChownIndex).toBeGreaterThan(workspaceChownIndex)
|
||||
expect(entrypoint).not.toContain('OCM_UID_CHANGED')
|
||||
expect(entrypoint).not.toContain('OCM_GID_CHANGED')
|
||||
expect(entrypoint).not.toMatch(/chown -R node:node \/app(?:\s|\n|$)/)
|
||||
|
||||
expect(entrypoint).toContain('chown -R node:node /app/data /workspace /home/node')
|
||||
expect(entrypoint).toContain('mkdir -p /app/data /workspace /home/node/.cache /home/node/.opencode')
|
||||
})
|
||||
|
||||
|
||||
Reference in new issue
Block a user