mirror of
https://github.com/pockethost/pockethost.git
synced 2025-03-30 15:08:30 +00:00
enh: pockethost hooks foundation
This commit is contained in:
parent
3bb1da666e
commit
faabb394cd
@ -20,4 +20,7 @@ SSL_CERT=/path/to/pockethost.crt
|
||||
PH_FTP_PASV_IP=0.0.0.0
|
||||
PH_FTP_PASV_PORT_MIN=10000
|
||||
PH_FTP_PASV_PORT_MAX=20000
|
||||
MOTHERSHIP_SEMVER=
|
||||
MOTHERSHIP_SEMVER=
|
||||
|
||||
INSTANCE_APP_MIGRATIONS_DIR=/path/to/dist/instance-app/migrations
|
||||
INSTANCE_APP_HOOKS_DIR=/path/to/dist/instance-app/pb_hooks
|
||||
|
@ -77,6 +77,15 @@ export const SETTINGS = {
|
||||
EDGE_APEX_DOMAIN: mkString(`pockethost.lvh.me`),
|
||||
EDGE_MAX_ACTIVE_INSTANCES: mkNumber(20),
|
||||
EDGE_SECRET_KEY: mkString(),
|
||||
|
||||
INSTANCE_APP_HOOKS_DIR: mkPath(
|
||||
join(_PH_BUILD_ROOT, `instance-app`, `pb_hooks`),
|
||||
{ create: true },
|
||||
),
|
||||
INSTANCE_APP_MIGRATIONS_DIR: mkPath(
|
||||
join(_PH_BUILD_ROOT, `instance-app`, `migrations`),
|
||||
{ create: true },
|
||||
),
|
||||
}
|
||||
;(() => {
|
||||
let passed = true
|
||||
@ -189,6 +198,10 @@ export const EDGE_MAX_ACTIVE_INSTANCES = () =>
|
||||
settings().EDGE_MAX_ACTIVE_INSTANCES
|
||||
export const EDGE_SECRET_KEY = () => settings().EDGE_SECRET_KEY
|
||||
|
||||
export const INSTANCE_APP_HOOK_DIR = () => settings().INSTANCE_APP_HOOKS_DIR
|
||||
export const INSTANCE_APP_MIGRATIONS_DIR = () =>
|
||||
settings().INSTANCE_APP_MIGRATIONS_DIR
|
||||
|
||||
/**
|
||||
* Helpers
|
||||
*/
|
||||
|
6
src/instance-app/jsconfig.json
Normal file
6
src/instance-app/jsconfig.json
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"baseUrl": ".",
|
||||
"typeRoots": ["./types"]
|
||||
}
|
||||
}
|
49
src/instance-app/types/goja.d.ts
vendored
Normal file
49
src/instance-app/types/goja.d.ts
vendored
Normal file
@ -0,0 +1,49 @@
|
||||
interface Require {
|
||||
(id: string): any
|
||||
}
|
||||
declare var require: Require
|
||||
|
||||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console) */
|
||||
interface Console {
|
||||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/assert) */
|
||||
assert(condition?: boolean, ...data: any[]): void
|
||||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/clear) */
|
||||
clear(): void
|
||||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/count) */
|
||||
count(label?: string): void
|
||||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/countReset) */
|
||||
countReset(label?: string): void
|
||||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/debug) */
|
||||
debug(...data: any[]): void
|
||||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/dir) */
|
||||
dir(item?: any, options?: any): void
|
||||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/dirxml) */
|
||||
dirxml(...data: any[]): void
|
||||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/error) */
|
||||
error(...data: any[]): void
|
||||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/group) */
|
||||
group(...data: any[]): void
|
||||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/groupCollapsed) */
|
||||
groupCollapsed(...data: any[]): void
|
||||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/groupEnd) */
|
||||
groupEnd(): void
|
||||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/info) */
|
||||
info(...data: any[]): void
|
||||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log) */
|
||||
log(...data: any[]): void
|
||||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/table) */
|
||||
table(tabularData?: any, properties?: string[]): void
|
||||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/time) */
|
||||
time(label?: string): void
|
||||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/timeEnd) */
|
||||
timeEnd(label?: string): void
|
||||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/timeLog) */
|
||||
timeLog(label?: string, ...data: any[]): void
|
||||
timeStamp(label?: string): void
|
||||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/trace) */
|
||||
trace(...data: any[]): void
|
||||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/warn) */
|
||||
warn(...data: any[]): void
|
||||
}
|
||||
|
||||
declare var console: Console
|
18321
src/instance-app/types/types.d.ts
vendored
Normal file
18321
src/instance-app/types/types.d.ts
vendored
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,8 @@
|
||||
import {
|
||||
APEX_DOMAIN,
|
||||
DEBUG,
|
||||
INSTANCE_APP_HOOK_DIR,
|
||||
INSTANCE_APP_MIGRATIONS_DIR,
|
||||
mkInstanceDataPath,
|
||||
MOTHERSHIP_HOOKS_DIR,
|
||||
MOTHERSHIP_MIGRATIONS_DIR,
|
||||
@ -16,8 +19,9 @@ import { assert, asyncExitHook, mkInternalUrl, tryFetch } from '$util'
|
||||
import { map } from '@s-libs/micro-dash'
|
||||
import Docker, { Container, ContainerCreateOptions } from 'dockerode'
|
||||
import { existsSync } from 'fs'
|
||||
import { globSync } from 'glob'
|
||||
import MemoryStream from 'memorystream'
|
||||
import { dirname } from 'path'
|
||||
import { basename, dirname, join } from 'path'
|
||||
import { gte } from 'semver'
|
||||
import { AsyncReturnType } from 'type-fest'
|
||||
import { PocketbaseReleaseVersionService } from '../PocketbaseReleaseVersionService'
|
||||
@ -146,10 +150,39 @@ export const createPocketbaseService = async (
|
||||
})
|
||||
}
|
||||
stderr.on('data', _stdErrData)
|
||||
const Binds = [
|
||||
`${dirname(binPath)}:/host_bin:ro`,
|
||||
`${mkInstanceDataPath(slug)}:/host_data`,
|
||||
]
|
||||
const hooksDir = isMothership
|
||||
? MOTHERSHIP_HOOKS_DIR()
|
||||
: mkInstanceDataPath(slug, `pb_hooks`)
|
||||
Binds.push(`${hooksDir}:/host_data/pb_hooks`)
|
||||
|
||||
const migrationsDir = isMothership
|
||||
? MOTHERSHIP_MIGRATIONS_DIR()
|
||||
: mkInstanceDataPath(slug, `pb_migrations`)
|
||||
Binds.push(`${migrationsDir}:/host_data/pb_migrations`)
|
||||
|
||||
if (!isMothership) {
|
||||
globSync(join(INSTANCE_APP_MIGRATIONS_DIR(), '*.js')).forEach((file) => {
|
||||
Binds.push(`${file}:/host_data/pb_migrations/${basename(file)}:ro`)
|
||||
})
|
||||
globSync(join(INSTANCE_APP_HOOK_DIR(), '*.js')).forEach((file) => {
|
||||
Binds.push(`${file}:/host_data/pb_hooks/${basename(file)}:ro`)
|
||||
})
|
||||
}
|
||||
|
||||
const createOptions: ContainerCreateOptions = {
|
||||
Image: `benallfree/pockethost-instance`,
|
||||
Cmd: args,
|
||||
Env: map(env, (v, k) => `${k}=${v}`),
|
||||
Env: map(
|
||||
{
|
||||
...env,
|
||||
PH_APEX_DOMAIN: APEX_DOMAIN(),
|
||||
},
|
||||
(v, k) => `${k}=${v}`,
|
||||
),
|
||||
name: `${name}-${+new Date()}`,
|
||||
HostConfig: {
|
||||
AutoRemove: true,
|
||||
@ -157,20 +190,7 @@ export const createPocketbaseService = async (
|
||||
PortBindings: {
|
||||
'8090/tcp': [{ HostPort: `${port}` }],
|
||||
},
|
||||
Binds: [
|
||||
`${dirname(binPath)}:/host_bin:ro`,
|
||||
`${mkInstanceDataPath(slug)}:/host_data`,
|
||||
`${
|
||||
isMothership
|
||||
? MOTHERSHIP_MIGRATIONS_DIR()
|
||||
: mkInstanceDataPath(slug, `pb_migrations`)
|
||||
}:/host_data/pb_migrations`,
|
||||
`${
|
||||
isMothership
|
||||
? MOTHERSHIP_HOOKS_DIR()
|
||||
: mkInstanceDataPath(slug, `pb_hooks`)
|
||||
}:/host_data/pb_hooks`,
|
||||
],
|
||||
Binds,
|
||||
},
|
||||
Tty: false,
|
||||
ExposedPorts: {
|
||||
|
Loading…
x
Reference in New Issue
Block a user