mirror of
https://github.com/pockethost/pockethost.git
synced 2025-05-31 03:06:41 +00:00
proxy: run different versions of pocketbase
This commit is contained in:
parent
6c0e49fba7
commit
106c02e8b1
@ -3,7 +3,7 @@
|
||||
"version": "0.0.1",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"build": "mkdir -p dist && esbuild src/server.ts --bundle --platform=node > dist/server.js",
|
||||
"build": "mkdir -p dist && esbuild src/server.ts --bundle --platform=node > dist/server.js && echo 'Build complete' `date`",
|
||||
"watch": "chokidar 'src/**' -c 'yarn build' --initial",
|
||||
"serve": "node dist/server.js"
|
||||
},
|
||||
|
@ -31,11 +31,11 @@ const tryFetch = (url: string) =>
|
||||
console.log(`Trying to connect to instance ${url} `)
|
||||
fetch(url)
|
||||
.then(() => {
|
||||
console.log(`Connection successful`)
|
||||
console.log(`Connection to ${url} successful`)
|
||||
resolve()
|
||||
})
|
||||
.catch((e) => {
|
||||
console.error(`Could not connect`)
|
||||
console.error(`Could not connect to ${url}`)
|
||||
setTimeout(tryFetch, 1000)
|
||||
})
|
||||
}
|
||||
@ -48,9 +48,13 @@ const mkInternalUrl = (port: number) => `http://${mkInternalAddress(port)}`
|
||||
export const createInstanceManger = async () => {
|
||||
const instances: { [_: string]: Instance } = {}
|
||||
|
||||
const _spawn = async (cfg: { subdomain: string; port: number }) => {
|
||||
const { subdomain, port } = cfg
|
||||
const cmd = `${BIN_ROOT}/pocketbase`
|
||||
const _spawn = async (cfg: {
|
||||
subdomain: string
|
||||
port: number
|
||||
bin: string
|
||||
}) => {
|
||||
const { subdomain, port, bin } = cfg
|
||||
const cmd = `${BIN_ROOT}/${bin}`
|
||||
const args = [
|
||||
`serve`,
|
||||
`--dir`,
|
||||
@ -91,6 +95,7 @@ export const createInstanceManger = async () => {
|
||||
const mainProcess = await _spawn({
|
||||
subdomain: CORE_PB_SUBDOMAIN,
|
||||
port: CORE_PB_PORT,
|
||||
bin: 'pocketbase',
|
||||
})
|
||||
instances[CORE_PB_SUBDOMAIN] = {
|
||||
process: mainProcess,
|
||||
@ -100,10 +105,14 @@ export const createInstanceManger = async () => {
|
||||
}
|
||||
await tryFetch(coreInternalUrl)
|
||||
try {
|
||||
await client.adminAuthViaEmail(CORE_PB_USERNAME, CORE_PB_PASSWORD)}
|
||||
catch(e) {
|
||||
console.error(`***WARNING*** CANNOT AUTHENTICATE TO https://${CORE_PB_SUBDOMAIN}.${APP_DOMAIN}/_/`)
|
||||
console.error(`***WARNING*** LOG IN MANUALLY, ADJUST .env, AND RESTART DOCKER`)
|
||||
await client.adminAuthViaEmail(CORE_PB_USERNAME, CORE_PB_PASSWORD)
|
||||
} catch (e) {
|
||||
console.error(
|
||||
`***WARNING*** CANNOT AUTHENTICATE TO https://${CORE_PB_SUBDOMAIN}.${APP_DOMAIN}/_/`
|
||||
)
|
||||
console.error(
|
||||
`***WARNING*** LOG IN MANUALLY, ADJUST .env, AND RESTART DOCKER`
|
||||
)
|
||||
}
|
||||
|
||||
const limiter = new Bottleneck({ maxConcurrent: 1 })
|
||||
@ -111,18 +120,20 @@ export const createInstanceManger = async () => {
|
||||
const getInstance = (subdomain: string) =>
|
||||
limiter.schedule(async () => {
|
||||
console.log(`Getting instance ${subdomain}`)
|
||||
const instance = instances[subdomain]
|
||||
if (instance) {
|
||||
console.log(`Found in cache: ${subdomain}`)
|
||||
instance.heartbeat()
|
||||
return instance
|
||||
{
|
||||
const instance = instances[subdomain]
|
||||
if (instance) {
|
||||
console.log(`Found in cache: ${subdomain}`)
|
||||
instance.heartbeat()
|
||||
return instance
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`Checking ${subdomain} for permission`)
|
||||
|
||||
const recs = await client.getInstanceBySubdomain(subdomain)
|
||||
const [item] = recs.items
|
||||
if (!item) {
|
||||
const [instance] = recs.items
|
||||
if (!instance) {
|
||||
console.log(`${subdomain} not found`)
|
||||
return
|
||||
}
|
||||
@ -134,13 +145,17 @@ export const createInstanceManger = async () => {
|
||||
port: 8090,
|
||||
exclude,
|
||||
}).catch((e) => {
|
||||
console.error(`Failed to get port`)
|
||||
console.error(`Failed to get port for ${subdomain}`)
|
||||
throw e
|
||||
})
|
||||
console.log(`Found port for ${subdomain}: ${newPort}`)
|
||||
|
||||
await client.updateInstanceStatus(subdomain, InstanceStatus.Starting)
|
||||
const childProcess = await _spawn({ subdomain, port: newPort })
|
||||
const childProcess = await _spawn({
|
||||
subdomain,
|
||||
port: newPort,
|
||||
bin: instance.bin || 'pocketbase',
|
||||
})
|
||||
|
||||
const internalUrl = mkInternalUrl(newPort)
|
||||
|
||||
|
2
packages/pocketbase/.gitignore
vendored
2
packages/pocketbase/.gitignore
vendored
@ -1 +1 @@
|
||||
pocketbase
|
||||
dist
|
@ -3,7 +3,13 @@
|
||||
"version": "0.0.1",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"build:arm64": "GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build",
|
||||
"build:386": "GOOS=linux GOARCH=386 CGO_ENABLED=0 go build"
|
||||
"build:arm64": "cd src && GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build -o ../dist/pocketbase && echo 'Build complete' `date`",
|
||||
"build:beta:arm64": "cd src && GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build -o ../dist/pocketbase-beta && echo 'Build complete' `date`",
|
||||
"build:386": "cd src && GOOS=linux GOARCH=386 CGO_ENABLED=0 go build -o ../dist/pocketbase && echo 'Build complete' `date`",
|
||||
"build:beta:386": "cd src && GOOS=linux GOARCH=386 CGO_ENABLED=0 go build -o ../dist/pocketbase-beta && echo 'Build complete' `date`",
|
||||
"watch:beta:386": "chokidar 'src/**/*' -c 'yarn build:beta:386' --initial"
|
||||
},
|
||||
"devDependencies": {
|
||||
"chokidar-cli": "^3.0.0"
|
||||
}
|
||||
}
|
@ -46,7 +46,7 @@ Join us in the discussion area.
|
||||
### 0.2.1
|
||||
|
||||
- Idle/running status for PB instance now shows in green
|
||||
- Ability to run separate versions of PocketBase per instance for beta/dev purposes
|
||||
- Ability to run separate versions of PocketBase per instance for custom cases including beta/dev
|
||||
|
||||
### 0.2.0
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user