docs: solidify DOCKER_SOCK and ROOT_API_KEY usage

This commit is contained in:
Aarnav Tale
2024-05-22 12:43:42 -04:00
parent 694b22f205
commit c7e59b137c
7 changed files with 68 additions and 23 deletions
+34 -4
View File
@@ -25,7 +25,8 @@ export interface HeadplaneContext {
}
docker?: {
sock: string
url: string
sock: boolean
container: string
}
@@ -163,19 +164,48 @@ async function checkAcl(config?: HeadscaleConfig) {
}
async function checkDocker() {
const path = process.env.DOCKER_SOCK ?? '/var/run/docker.sock'
const path = process.env.DOCKER_SOCK ?? 'unix:///var/run/docker.sock'
let url: URL | undefined
try {
await access(path, constants.R_OK)
url = new URL(path)
} catch {
return
}
// The API is available as an HTTP endpoint
if (url.protocol === 'tcp:') {
url.protocol = 'http:'
}
// Check if the socket is accessible
if (url.protocol === 'unix:') {
try {
await access(path, constants.R_OK)
} catch {
return
}
}
if (url.protocol === 'http:') {
try {
await fetch(new URL('/v1.30/version', url).href)
} catch {
return
}
}
if (url.protocol !== 'http:' && url.protocol !== 'unix:') {
return
}
if (!process.env.HEADSCALE_CONTAINER) {
return
}
return {
sock: path,
url: url.href,
sock: url.protocol === 'unix:',
container: process.env.HEADSCALE_CONTAINER,
}
}