Merge branch 'v0/main' of github.com:benallfree/pockethost into v0/main

This commit is contained in:
Ben Allfree 2024-07-31 08:31:09 +00:00
commit ff70824b6b
14 changed files with 118 additions and 203 deletions

View File

@ -23,14 +23,9 @@ module.exports = {
script: 'pnpm prod:cli mothership serve', script: 'pnpm prod:cli mothership serve',
}, },
{ {
name: `updater`, name: `gobot`,
restart_delay: 60 * 60 * 1000, // 1 hour restart_delay: 60 * 60 * 1000, // 1 hour
script: 'pnpm prod:cli mothership update', script: 'pnpm prod:cli gobot update',
},
{
name: `downloader`,
restart_delay: 60 * 60 * 1000, // 1 hour
script: 'pnpm gobot:download',
}, },
{ {
name: `health`, name: `health`,

View File

@ -1,10 +1,10 @@
import { writeFileSync } from 'fs' import { writeFileSync } from 'fs'
import { gobot } from 'gobot'
import { import {
LoggerService,
MOTHERSHIP_DATA_ROOT, MOTHERSHIP_DATA_ROOT,
MOTHERSHIP_HOOKS_DIR,
stringify, stringify,
} from '../../../../core' } from '../../../../../core'
import { GobotService } from '../../../../services/GobotService'
function compareSemVer(a: string, b: string): number { function compareSemVer(a: string, b: string): number {
// Consider wildcards as higher than any version number, hence represented by a large number for comparison // Consider wildcards as higher than any version number, hence represented by a large number for comparison
@ -54,12 +54,27 @@ function expandAndSortSemVers(semvers: string[]): string[] {
} }
export async function freshenPocketbaseVersions() { export async function freshenPocketbaseVersions() {
const { info } = LoggerService().create(`freshenPocketbaseVersions`)
const { gobot } = await GobotService()
info(`Updating pocketbase`)
const bot = await gobot(`pocketbase`) const bot = await gobot(`pocketbase`)
await bot.update() await bot.update()
await bot.download()
const rawVersions = await bot.versions() const rawVersions = await bot.versions()
const versions = expandAndSortSemVers(rawVersions) const versions = expandAndSortSemVers(rawVersions)
const cjs = `module.exports = ${stringify(versions, null, 2)}` const cjs = `module.exports = ${stringify(versions, null, 2)}`
writeFileSync(MOTHERSHIP_DATA_ROOT(`pb_hooks`, `versions.cjs`), cjs)
writeFileSync(MOTHERSHIP_HOOKS_DIR(`versions.cjs`), cjs) {
const path = MOTHERSHIP_DATA_ROOT(`pb_hooks`, `versions.cjs`)
info(`Writing to ${path}`)
writeFileSync(path, cjs)
}
{
const path = bot.cachePath(`versions.cjs`)
info(`Writing to ${path}`)
writeFileSync(path, cjs)
}
return cjs return cjs
} }

View File

@ -0,0 +1,11 @@
import { Command } from 'commander'
import { freshenPocketbaseVersions } from './freshenPocketbaseVersions'
export const UpdateCommand = () => {
const cmd = new Command(`update`)
.description(`Update all Gobot dependencies`)
.action(async (options) => {
await freshenPocketbaseVersions()
})
return cmd
}

View File

@ -0,0 +1,9 @@
import { Command } from 'commander'
import { UpdateCommand } from './UpdateCommand'
export const GobotCommand = () => {
const cmd = new Command(`gobot`).description(`Gobot commands`)
cmd.addCommand(UpdateCommand())
return cmd
}

View File

@ -0,0 +1,11 @@
import { Command } from 'commander'
import { schema } from './schema'
export const SchemaCommand = () => {
const cmd = new Command(`schema`)
.description(`Create snapshot of the current PocketHost mothership schema`)
.action(async (options) => {
await schema()
})
return cmd
}

View File

@ -0,0 +1,40 @@
import { GobotOptions } from 'gobot'
import {
IS_DEV,
LoggerService,
MOTHERSHIP_DATA_ROOT,
MOTHERSHIP_MIGRATIONS_DIR,
MOTHERSHIP_SEMVER,
} from '../../../../../core'
import { GobotService } from '../../../../services/GobotService'
export async function schema() {
const logger = LoggerService().create(`MothershipSchema`)
const { dbg, error, info, warn } = logger
info(`Starting`)
const options: Partial<GobotOptions> = {
version: MOTHERSHIP_SEMVER(),
}
dbg(`gobot options`, options)
const { gobot } = GobotService()
const bot = await gobot(`pocketbase`, options)
const args = [
`migrate`,
`collections`,
`--automigrate`,
`0`,
`--hooksDir`,
`foo`,
`--dir`,
MOTHERSHIP_DATA_ROOT(`pb_data`),
`--migrationsDir`,
MOTHERSHIP_MIGRATIONS_DIR(),
]
if (IS_DEV()) {
args.push(`--dev`)
}
dbg(`args`, args)
bot.run(args)
}

View File

@ -56,8 +56,18 @@ export async function mothership(cfg: MothershipConfig) {
LS_WEBHOOK_SECRET: LS_WEBHOOK_SECRET(), LS_WEBHOOK_SECRET: LS_WEBHOOK_SECRET(),
} }
dbg(env) dbg(env)
const options: Partial<GobotOptions> = {
version: MOTHERSHIP_SEMVER(),
env,
}
dbg(`options`, options)
const { gobot } = GobotService()
const bot = await gobot(`pocketbase`, options)
await rimraf(MOTHERSHIP_DATA_ROOT(`pb_hooks`)) await rimraf(MOTHERSHIP_DATA_ROOT(`pb_hooks`))
await _copy(MOTHERSHIP_HOOKS_DIR(`**/*`), MOTHERSHIP_DATA_ROOT(`pb_hooks`)) await _copy(MOTHERSHIP_HOOKS_DIR(`**/*`), MOTHERSHIP_DATA_ROOT(`pb_hooks`))
await _copy(bot.cachePath(`versions.cjs`), MOTHERSHIP_DATA_ROOT(`pb_hooks`))
await rimraf(MOTHERSHIP_DATA_ROOT(`pb_migrations`)) await rimraf(MOTHERSHIP_DATA_ROOT(`pb_migrations`))
await _copy( await _copy(
MOTHERSHIP_MIGRATIONS_DIR(`**/*`), MOTHERSHIP_MIGRATIONS_DIR(`**/*`),
@ -80,13 +90,6 @@ export async function mothership(cfg: MothershipConfig) {
if (IS_DEV()) { if (IS_DEV()) {
args.push(`--dev`) args.push(`--dev`)
} }
const options: Partial<GobotOptions> = {
version: MOTHERSHIP_SEMVER(),
env,
}
dbg(`args`, args) dbg(`args`, args)
dbg(`options`, options)
const { gobot } = GobotService()
const bot = await gobot(`pocketbase`, options)
bot.run(args, { env }) bot.run(args, { env })
} }

View File

@ -1,14 +0,0 @@
import { Command } from 'commander'
import { freshenPocketbaseVersions } from '../freshenPocketbaseVersions'
type Options = {}
export const UpdateCommand = () => {
const cmd = new Command(`update`)
.description(`Update known PocketBase versions`)
.action(async (options: Options) => {
const cjs = await freshenPocketbaseVersions()
console.log(cjs)
})
return cmd
}

View File

@ -1,6 +1,6 @@
import { Command } from 'commander' import { Command } from 'commander'
import { SchemaCommand } from './SchemaCommand'
import { ServeCommand } from './ServeCommand' import { ServeCommand } from './ServeCommand'
import { UpdateCommand } from './UpdateCommand'
type Options = { type Options = {
debug: boolean debug: boolean
@ -10,6 +10,6 @@ export const MothershipCommand = () => {
const cmd = new Command(`mothership`) const cmd = new Command(`mothership`)
.description(`Mothership commands`) .description(`Mothership commands`)
.addCommand(ServeCommand()) .addCommand(ServeCommand())
.addCommand(UpdateCommand()) .addCommand(SchemaCommand())
return cmd return cmd
} }

View File

@ -14,6 +14,7 @@ import {
import { GobotService } from '../services/GobotService' import { GobotService } from '../services/GobotService'
import { EdgeCommand } from './commands/EdgeCommand' import { EdgeCommand } from './commands/EdgeCommand'
import { FirewallCommand } from './commands/FirewallCommand' import { FirewallCommand } from './commands/FirewallCommand'
import { GobotCommand } from './commands/GobotCommand'
import { HealthCommand } from './commands/HealthCommand' import { HealthCommand } from './commands/HealthCommand'
import { MothershipCommand } from './commands/MothershipCommand' import { MothershipCommand } from './commands/MothershipCommand'
import { SendMailCommand } from './commands/SendMailCommand' import { SendMailCommand } from './commands/SendMailCommand'
@ -43,6 +44,7 @@ export const main = async () => {
.addCommand(FirewallCommand()) .addCommand(FirewallCommand())
.addCommand(SendMailCommand()) .addCommand(SendMailCommand())
.addCommand(ServeCommand()) .addCommand(ServeCommand())
.addCommand(GobotCommand())
await program.parseAsync() await program.parseAsync()
} }

View File

@ -1,166 +0,0 @@
module.exports = [
"0.22.*",
"0.22.18",
"0.22.17",
"0.22.16",
"0.22.15",
"0.22.14",
"0.22.14-rc",
"0.22.13",
"0.22.12",
"0.22.11",
"0.22.10",
"0.22.9",
"0.22.8",
"0.22.7",
"0.22.6",
"0.22.5",
"0.22.4",
"0.22.3",
"0.22.2",
"0.22.1",
"0.22.0",
"0.21.*",
"0.21.3",
"0.21.2",
"0.21.1",
"0.21.0",
"0.20.*",
"0.20.7",
"0.20.6",
"0.20.5",
"0.20.4",
"0.20.3",
"0.20.2",
"0.20.1",
"0.20.0",
"0.20.0-rc3",
"0.20.0-rc2",
"0.20.0-rc",
"0.19.*",
"0.19.4",
"0.19.3",
"0.19.2",
"0.19.1",
"0.19.0",
"0.18.*",
"0.18.10",
"0.18.9",
"0.18.8",
"0.18.7",
"0.18.6",
"0.18.5",
"0.18.4",
"0.18.3",
"0.18.2",
"0.18.1",
"0.18.0",
"0.17.*",
"0.17.7",
"0.17.6",
"0.17.5",
"0.17.4",
"0.17.3",
"0.17.2",
"0.17.1",
"0.17.0",
"0.16.*",
"0.16.10",
"0.16.9",
"0.16.8",
"0.16.7",
"0.16.6",
"0.16.5",
"0.16.4",
"0.16.3",
"0.16.2",
"0.16.1",
"0.16.0",
"0.15.*",
"0.15.3",
"0.15.2",
"0.15.1",
"0.15.0",
"0.14.*",
"0.14.5",
"0.14.4",
"0.14.3",
"0.14.2",
"0.14.1",
"0.14.0",
"0.13.*",
"0.13.4",
"0.13.3",
"0.13.2",
"0.13.1",
"0.13.0",
"0.12.*",
"0.12.3",
"0.12.2",
"0.12.1",
"0.12.0",
"0.11.*",
"0.11.4",
"0.11.3",
"0.11.2",
"0.11.1",
"0.11.0",
"0.10.*",
"0.10.4",
"0.10.3",
"0.10.2",
"0.10.1",
"0.10.0",
"0.9.*",
"0.9.2",
"0.9.1",
"0.9.0",
"0.8.*",
"0.8.0",
"0.8.0-rc4",
"0.8.0-rc3",
"0.8.0-rc2",
"0.8.0-rc1",
"0.7.*",
"0.7.10",
"0.7.9",
"0.7.8",
"0.7.7",
"0.7.6",
"0.7.5",
"0.7.4",
"0.7.3",
"0.7.2",
"0.7.1",
"0.7.0",
"0.6.*",
"0.6.0",
"0.5.*",
"0.5.2",
"0.5.1",
"0.5.0",
"0.4.*",
"0.4.2",
"0.4.1",
"0.4.0",
"0.3.*",
"0.3.4",
"0.3.3",
"0.3.2",
"0.3.1",
"0.3.0",
"0.2.*",
"0.2.8",
"0.2.7",
"0.2.6",
"0.2.5",
"0.2.4",
"0.2.3",
"0.2.2",
"0.2.1",
"0.2.0",
"0.1.*",
"0.1.2",
"0.1.1",
"0.1.0"
]

View File

@ -1,10 +1,19 @@
import { default as env } from 'env-var'
import { GobotOptions, gobot } from 'gobot' import { GobotOptions, gobot } from 'gobot'
import { mkSingleton } from '../common' import { mkSingleton } from '../common'
import { PH_GOBOT_ROOT } from '../constants' import { PH_GOBOT_ROOT } from '../constants'
export const PH_GOBOT_VERBOSITY = () =>
env.get(`PH_GOBOT_VERBOSITY`).default(1).asIntPositive()
export const GobotService = mkSingleton(() => { export const GobotService = mkSingleton(() => {
return { return {
gobot: (name: string, options?: Partial<GobotOptions>) => gobot: (name: string, options?: Partial<GobotOptions>) => {
gobot(name, { ...options, cachePath: PH_GOBOT_ROOT(`cache`, name) }), // verbosity(PH_GOBOT_VERBOSITY())
return gobot(name, {
...options,
cachePath: PH_GOBOT_ROOT(`cache`, name),
})
},
} }
}) })