2024-06-17 07:05:06 -04:00
|
|
|
const hostAdminUrl = Cypress.env('ADMIN_CLIENT_URL') || 'http://host-admin'
|
|
|
|
|
2024-05-30 03:12:56 -04:00
|
|
|
export async function dockerCompose(cmd: string, ...args: string[]) {
|
2024-06-17 07:05:06 -04:00
|
|
|
return await fetchJSON(`${hostAdminUrl}/docker/compose/${cmd}`, {
|
2024-05-30 03:12:56 -04:00
|
|
|
method: 'POST',
|
|
|
|
body: JSON.stringify({
|
|
|
|
args,
|
|
|
|
}),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function reconfigure({
|
|
|
|
pro = false,
|
|
|
|
version = 'latest',
|
|
|
|
vars = {},
|
2024-06-11 07:01:21 -04:00
|
|
|
withDataDir = false,
|
2024-07-10 10:00:41 -04:00
|
|
|
resetData = false,
|
2024-05-30 03:12:56 -04:00
|
|
|
}) {
|
2024-06-17 07:05:06 -04:00
|
|
|
return await fetchJSON(`${hostAdminUrl}/reconfigure`, {
|
2024-05-30 03:12:56 -04:00
|
|
|
method: 'POST',
|
|
|
|
body: JSON.stringify({
|
|
|
|
pro,
|
|
|
|
version,
|
|
|
|
vars,
|
2024-06-11 07:01:21 -04:00
|
|
|
withDataDir,
|
2024-07-10 10:00:41 -04:00
|
|
|
resetData,
|
2024-05-30 03:12:56 -04:00
|
|
|
}),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
async function fetchJSON(
|
|
|
|
input: RequestInfo,
|
|
|
|
init?: RequestInit
|
|
|
|
): Promise<{ stdout: string; stderr: string }> {
|
|
|
|
if (init?.body) {
|
|
|
|
init.headers = { 'Content-Type': 'application/json' }
|
|
|
|
}
|
|
|
|
const res = await fetch(input, init)
|
|
|
|
const { error, stdout, stderr } = await res.json()
|
|
|
|
if (error) {
|
|
|
|
console.error(input, init, 'failed:', error)
|
2024-05-30 03:13:24 -04:00
|
|
|
if (stdout) console.log(stdout)
|
|
|
|
if (stderr) console.warn(stderr)
|
2024-05-30 03:12:56 -04:00
|
|
|
const err = new Error(error.message)
|
|
|
|
Object.assign(err, error)
|
|
|
|
throw err
|
|
|
|
}
|
|
|
|
return { stdout, stderr }
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function runScript({
|
|
|
|
cwd,
|
|
|
|
script,
|
|
|
|
args = [],
|
|
|
|
}: {
|
|
|
|
cwd: string
|
|
|
|
script: string
|
|
|
|
args?: string[]
|
|
|
|
}) {
|
2024-06-17 07:05:06 -04:00
|
|
|
return await fetchJSON(`${hostAdminUrl}/run/script`, {
|
2024-05-30 03:12:56 -04:00
|
|
|
method: 'POST',
|
|
|
|
body: JSON.stringify({
|
|
|
|
cwd,
|
|
|
|
script,
|
|
|
|
args,
|
|
|
|
}),
|
|
|
|
})
|
|
|
|
}
|
2024-06-25 07:03:05 -04:00
|
|
|
|
|
|
|
export async function getRedisKeys() {
|
|
|
|
const { stdout } = await fetchJSON(`${hostAdminUrl}/redis/keys`, {
|
|
|
|
method: 'GET',
|
|
|
|
})
|
|
|
|
return stdout.split('\n')
|
|
|
|
}
|