mirror of
https://github.com/tale/headplane.git
synced 2026-08-09 05:39:22 +00:00
feat: support readonly config and no docker sock
This commit is contained in:
+3
-16
@@ -141,7 +141,6 @@ export async function patchConfig(partial: Record<string, unknown>) {
|
||||
}
|
||||
|
||||
type Context = {
|
||||
isDocker: boolean;
|
||||
hasDockerSock: boolean;
|
||||
hasConfigWrite: boolean;
|
||||
}
|
||||
@@ -151,7 +150,6 @@ export let context: Context
|
||||
export async function getContext() {
|
||||
if (!context) {
|
||||
context = {
|
||||
isDocker: await checkDocker(),
|
||||
hasDockerSock: await checkSock(),
|
||||
hasConfigWrite: await checkConfigWrite()
|
||||
}
|
||||
@@ -177,20 +175,9 @@ async function checkSock() {
|
||||
return true
|
||||
} catch {}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
async function checkDocker() {
|
||||
try {
|
||||
await stat('/.dockerenv')
|
||||
return true
|
||||
} catch {}
|
||||
|
||||
try {
|
||||
const data = await readFile('/proc/self/cgroup', 'utf8')
|
||||
return data.includes('docker')
|
||||
} catch {}
|
||||
if (!process.env.HEADSCALE_CONTAINER) {
|
||||
return false
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
@@ -5,9 +5,15 @@ import { setTimeout } from 'node:timers/promises'
|
||||
|
||||
import { Client } from 'undici'
|
||||
|
||||
import { getContext } from './config'
|
||||
import { pull } from './headscale'
|
||||
|
||||
export async function restartHeadscale() {
|
||||
const context = await getContext()
|
||||
if (!context.hasDockerSock) {
|
||||
return
|
||||
}
|
||||
|
||||
if (!process.env.HEADSCALE_CONTAINER) {
|
||||
throw new Error('HEADSCALE_CONTAINER is not set')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user