Remove docker

This commit is contained in:
Ben Allfree 2022-12-24 06:04:22 -08:00
parent 7e46094537
commit 15c2d91e37
36 changed files with 131 additions and 410 deletions

2
.data/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*
!.gitignore

View File

@ -1,8 +0,0 @@
**/node_modules
**/.svelte-kit
**/.parcel-cache
**/dist
**/dist-server
**/*.log
docker/mount/cache
**/build

View File

@ -3,14 +3,13 @@ PUBLIC_APP_DOMAIN=pockethost.test
PUBLIC_PB_PROTOCOL=https
PUBLIC_PB_DOMAIN=pockethost.test
PUBLIC_PB_SUBDOMAIN=pockethost-central
DAEMON_PB_BIN_DIR=/src/packages/pocketbase/dist
DAEMON_PB_DATA_DIR=/data
DAEMON_PB_BIN_DIR=`pwd`/packages/pocketbase/dist
DAEMON_PB_DATA_DIR=`pwd`/.data
DAEMON_PB_USERNAME=#ADDME
DAEMON_PB_PASSWORD=#FIXME
DAEMON_PB_PORT=8090
DAEMON_IDLE_TTL=5000
DAEMON_PB_BACKUP_SLEEP=100
DAEMON_PB_BACKUP_PAGE_COUNT=5
GOPATH=/go
YARN_CACHE=/usr/local/share/.cache/yarn/v6
SHELL=/bin/bash
SSL_KEY=`pwd`/ssl/pockethost.test.key
SSL_CERT=`pwd`/ssl/pockethost.test.crt

View File

@ -1,5 +0,0 @@
.git
node_modules
.svelte-kit
*.log
attic

View File

@ -1,9 +0,0 @@
supportedArchitectures:
os:
- 'current'
- 'darwin'
- 'linux'
- 'win32'
cpu:
- 'current'
- 'arm64'

View File

@ -1,4 +0,0 @@
FROM node:18-alpine as pockethost-buildbox
COPY --from=golang:1.19.3-alpine /usr/local/go/ /usr/local/go/
ENV PATH="/usr/local/go/bin:${PATH}"
RUN apk add python3 py3-pip make gcc musl-dev g++ bash sqlite

View File

@ -1,8 +0,0 @@
FROM node:18-alpine as pockethost-buildbox
COPY --from=golang:1.19-alpine /usr/local/go/ /usr/local/go/
ENV PATH="/usr/local/go/bin:${PATH}"
RUN apk add python3 py3-pip make gcc musl-dev g++ bash
WORKDIR /src
COPY . .
RUN yarn --verbose
RUN yarn build --verbose

View File

@ -1,17 +0,0 @@
PUBLIC_APP_PROTOCOL=https
PUBLIC_APP_DOMAIN=pockethost.io
PUBLIC_PB_PROTOCOL=https
PUBLIC_PB_DOMAIN=pockethost.io
PUBLIC_PB_SUBDOMAIN=pockethost-central
DAEMON_PB_BIN_DIR=/src/packages/pocketbase/dist
DAEMON_PB_DATA_DIR=/data
DAEMON_PB_USERNAME=#ADDME
DAEMON_PB_PASSWORD=#FIXME
DAEMON_PB_PORT=8090
DAEMON_PB_BACKUP_SLEEP=100
DAEMON_PB_BACKUP_PAGE_COUNT=5
# 30 minutes
DAEMON_PB_IDLE_TTL=1800000
GOPATH=/go
YARN_CACHE=/usr/local/share/.cache/yarn/v6
SHELL=/bin/bash

3
docker/.gitignore vendored
View File

@ -1,3 +0,0 @@
.env.*
mount/daemon
mount/cache

View File

@ -1,16 +0,0 @@
version: '3'
services:
build:
env_file:
- .env.local
build:
context: ..
dockerfile: Dockerfile
container_name: build
working_dir: /src
command: bash -c "rm -rf node_modules && yarn && yarn build"
volumes:
- ./mount/cache/go:/go
- ./mount/cache/yarn:/usr/local/share/.cache/yarn/v6
- ..:/src

View File

@ -1,59 +0,0 @@
version: '3'
services:
www:
env_file:
- .env.local
build:
context: ..
dockerfile: Dockerfile
container_name: www
restart: unless-stopped
working_dir: /src
command: bash -c "yarn dev:www --host=www"
volumes:
- ..:/src
networks:
- app-network
ports:
- '9000:5173'
depends_on:
daemon:
condition: service_started
daemon:
env_file:
- .env.local
build:
context: ..
dockerfile: Dockerfile
container_name: daemon
working_dir: /src
command: bash -c "yarn dev:daemon"
restart: unless-stopped
volumes:
- ./mount/daemon/instances:/data
- ..:/src
networks:
- app-network
ports:
- '9001:3000'
nginx:
image: nginx:mainline-alpine
container_name: nginx
restart: unless-stopped
depends_on:
- www
- daemon
ports:
- '80:80'
- '443:443'
volumes:
- ./mount/nginx/conf.d/local:/etc/nginx/conf.d
- ./mount/nginx/logs:/mount/nginx/logs
- ./mount/nginx/ssl:/mount/nginx/ssl
networks:
- app-network
networks:
app-network:
driver: bridge

View File

@ -1,16 +0,0 @@
version: '3'
services:
prepbox:
env_file:
- .env.local
build:
context: ..
dockerfile: Dockerfile
container_name: prepbox
working_dir: /src
command: bash -c "rm -rf node_modules && yarn"
volumes:
- ./mount/cache/go:/go
- ./mount/cache/yarn:/usr/local/share/.cache/yarn/v6
- ..:/src

View File

@ -1,17 +0,0 @@
version: '3'
services:
prepbox:
env_file:
- .env.local
build:
context: ..
dockerfile: Dockerfile
container_name: prepbox
working_dir: /src
command: bash -c "yarn migrate"
volumes:
- ./mount/daemon/instances:/data
- ./mount/cache/go:/go
- ./mount/cache/yarn:/usr/local/share/.cache/yarn/v6
- ..:/src

View File

@ -1,17 +0,0 @@
version: '3'
services:
prepbox:
env_file:
- .env.local
build:
context: ..
dockerfile: Dockerfile
container_name: prepbox
working_dir: /src
command: bash -c "yarn migrate"
volumes:
- /home/pockethost/data:/data
- ./mount/cache/go:/go
- ./mount/cache/yarn:/usr/local/share/.cache/yarn/v6
- ..:/src

View File

@ -1,2 +0,0 @@
daemon
logs/*

View File

@ -1,2 +0,0 @@
yarn
go

View File

@ -1,64 +0,0 @@
server {
listen 80 default_server;
server_name _;
return 301 https://$host$request_uri;
}
server {
server_name www.pockethost.test;
return 301 $scheme://pockethost.test$request_uri;
}
server {
listen 443 ssl;
server_name pockethost.test;
ssl_certificate /mount/nginx/ssl/pockethost.test.crt;
ssl_certificate_key /mount/nginx/ssl/pockethost.test.key;
access_log /mount/nginx/logs/access.log;
error_log /mount/nginx/logs/error.log;
location / {
proxy_read_timeout 180s;
# WebSocket support
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://www:5173;
}
}
server {
listen 443 ssl;
server_name *.pockethost.test;
ssl_certificate /mount/nginx/ssl/pockethost.test.crt;
ssl_certificate_key /mount/nginx/ssl/pockethost.test.key;
access_log /mount/nginx/logs/access.log;
error_log /mount/nginx/logs/error.log;
location / {
proxy_read_timeout 180s;
# WebSocket support
proxy_buffering off; # For realtime
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://daemon:3000;
}
}

View File

@ -1,66 +0,0 @@
server {
listen 80 default_server;
server_name _;
return 301 https://$host$request_uri;
}
server {
server_name www.pockethost.io;
return 301 $scheme://pockethost.io$request_uri;
}
server {
listen 443 ssl;
server_name pockethost.io;
ssl_certificate /mount/nginx/ssl/fullchain.pem;
ssl_certificate_key /mount/nginx/ssl/privkey.pem;
access_log /mount/nginx/logs/access.log;
error_log /mount/nginx/logs/error.log;
location / {
proxy_read_timeout 180s;
# WebSocket support
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://www:3000;
}
}
server {
listen 443 ssl;
server_name *.pockethost.io;
ssl_certificate /mount/nginx/ssl/fullchain.pem;
ssl_certificate_key /mount/nginx/ssl/privkey.pem;
access_log /mount/nginx/logs/access.log;
error_log /mount/nginx/logs/error.log;
location / {
proxy_read_timeout 180s;
# WebSocket support
proxy_buffering off; # For realtime
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://daemon:3000;
}
}

View File

@ -1 +0,0 @@
*.log

View File

@ -1,61 +0,0 @@
version: '3'
services:
www:
env_file:
- .env.local
build:
context: ..
dockerfile: Dockerfile
container_name: www
restart: unless-stopped
working_dir: /src
command: bash -c "yarn start:www --host=www"
volumes:
- ..:/src
networks:
- app-network
ports:
- '9000:5173'
depends_on:
daemon:
condition: service_started
daemon:
env_file:
- .env.local
build:
context: ..
dockerfile: Dockerfile
container_name: daemon
working_dir: /src
command: bash -c "yarn start:daemon"
restart: unless-stopped
environment:
- SHELL=/bin/bash
volumes:
- /home/pockethost/data:/data
- ..:/src
networks:
- app-network
ports:
- '9001:3000'
nginx:
image: nginx:mainline-alpine
container_name: nginx
restart: unless-stopped
depends_on:
- www
- daemon
ports:
- '80:80'
- '443:443'
volumes:
- ./mount/nginx/conf.d/prod:/etc/nginx/conf.d
- ./mount/nginx/logs:/mount/nginx/logs
- ./mount/nginx/ssl:/mount/nginx/ssl
networks:
- app-network
networks:
app-network:
driver: bridge

View File

@ -11,9 +11,12 @@
"build:pocketbase": "cd packages/pocketbase && yarn build",
"build:daemon": "cd packages/daemon && yarn build",
"build:www": "cd packages/pockethost.io && yarn build",
"dev": "concurrently 'yarn:dev:*'",
"dev:proxy": "cd packages/proxy && yarn dev",
"dev:www": "cd packages/pockethost.io && yarn dev",
"dev:daemon": "cd packages/daemon && yarn dev",
"start": "concurrently 'yarn start:www' 'yarn start:daemon'",
"start": "concurrently 'yarn:start:*'",
"start:proxy": "cd packages/proxy && yarn start",
"start:www": "cd packages/pockethost.io && yarn start",
"start:daemon": "cd packages/daemon && yarn start",
"migrate": "yarn migrate:daemon",
@ -45,4 +48,4 @@
"dependencies": {
"postinstall-postinstall": "^2.1.0"
}
}
}

View File

@ -21,6 +21,9 @@ export const RELEASES = {
'0.9.2',
'0.10.0',
'0.10.1',
'0.10.2',
'0.10.3',
'0.10.4',
],
},
}

View File

@ -5,7 +5,7 @@
"scripts": {
"build": "echo 'Build complete' `date`",
"dev": "DEBUG=1 tsx watch src/server.ts",
"start": "tsx src/server.ts",
"start": "tsx src/server.ts",
"migrate": "tsx src/migrate/migrate.ts"
},
"dependencies": {

View File

@ -1,4 +1,5 @@
import { binFor } from '@pockethost/common'
import getPort from 'get-port'
import {
DAEMON_PB_PASSWORD,
DAEMON_PB_PORT_BASE,
@ -18,7 +19,8 @@ import { spawnInstance } from './util/spawnInstance'
// npm install eventsource --save
global.EventSource = require('eventsource')
;(async () => {
const coreInternalUrl = mkInternalUrl(DAEMON_PB_PORT_BASE)
const port = await getPort({ port: DAEMON_PB_PORT_BASE })
const coreInternalUrl = mkInternalUrl(port)
/**
* Launch central database
@ -26,7 +28,7 @@ global.EventSource = require('eventsource')
const mainProcess = await spawnInstance({
subdomain: PUBLIC_PB_SUBDOMAIN,
slug: PUBLIC_PB_SUBDOMAIN,
port: DAEMON_PB_PORT_BASE,
port,
bin: binFor('lollipop'),
})
@ -46,7 +48,10 @@ global.EventSource = require('eventsource')
const rpcService = await createRpcService({ client })
const instanceService = await createInstanceService({ client, rpcService })
const proxyService = await createProxyService(instanceService)
const proxyService = await createProxyService({
instanceManager: instanceService,
coreInternalUrl,
})
const backupService = await createBackupService(client, rpcService)
process.once('SIGUSR2', async () => {

View File

@ -2,20 +2,21 @@ import { createServer } from 'http'
import httpProxy from 'http-proxy'
import { AsyncReturnType } from 'type-fest'
import {
DAEMON_PB_PORT_BASE,
PUBLIC_APP_DOMAIN,
PUBLIC_APP_PROTOCOL,
PUBLIC_PB_SUBDOMAIN,
} from '../constants'
import { mkInternalUrl } from '../util/internal'
import { dbg, error, info } from '../util/logger'
import { InstanceServiceApi } from './InstanceService'
export type ProxyServiceApi = AsyncReturnType<typeof createProxyService>
export const createProxyService = async (
export type ProxyServiceConfig = {
coreInternalUrl: string
instanceManager: InstanceServiceApi
) => {
}
export const createProxyService = async (config: ProxyServiceConfig) => {
const { instanceManager, coreInternalUrl } = config
const proxy = httpProxy.createProxyServer({})
const server = createServer(async (req, res) => {
@ -39,7 +40,7 @@ export const createProxyService = async (
}
try {
if (subdomain === PUBLIC_PB_SUBDOMAIN) {
const target = mkInternalUrl(DAEMON_PB_PORT_BASE)
const target = coreInternalUrl
dbg(`Forwarding proxy request for ${req.url} to instance ${target}`)
proxy.web(req, res, { target })
return

View File

@ -10,7 +10,7 @@
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
"lint": "prettier --check .",
"format": "prettier --write .",
"start": "node dist-server/index.js",
"start": "HOST=localhost PORT=5173 node dist-server/index.js",
"watch": "chokidar 'src/**' -c 'yarn build' --initial"
},
"devDependencies": {

View File

@ -0,0 +1,15 @@
{
"name": "@pockethost/proxy",
"version": "0.0.1",
"main": "index.js",
"license": "MIT",
"scripts": {
"dev": "tsx watch src/index.ts",
"start": "tsx src/index.ts"
},
"dependencies": {
"@types/node": "^18.11.17",
"http-proxy": "^1.18.1",
"tsx": "^3.12.1"
}
}

View File

@ -0,0 +1,44 @@
import { readFileSync } from 'fs'
import http from 'http'
import httpProxy from 'http-proxy'
import { createServer } from 'https'
const options = {
key: readFileSync(process.env.SSL_KEY || ''),
cert: readFileSync(process.env.SSL_CERT || ''),
}
const proxy = httpProxy.createProxyServer({})
const server = createServer(options, async (req, res) => {
const headers = {
'Access-Control-Allow-Origin': '*' /* @dev First, read about security */,
'Access-Control-Allow-Methods': 'OPTIONS, POST, GET',
'Access-Control-Max-Age': 2592000, // 30 days
'Access-Control-Allow-Headers': `authorization,content-type`,
}
if (req.method === 'OPTIONS') {
res.writeHead(204, headers)
res.end()
return
}
console.log(req.headers.host)
const { host } = req.headers
if (host === process.env.PUBLIC_APP_DOMAIN) {
proxy.web(req, res, { target: `http://localhost:5173` })
} else {
proxy.web(req, res, { target: `http://localhost:3000` })
}
})
server.listen(443)
const httpServer = http.createServer((req, res) => {
res.writeHead(301, { Location: `https://${req.headers.host}${req.url}` })
res.end()
})
httpServer.listen(80)
console.log(`Listening 80->443`)

View File

@ -0,0 +1,18 @@
{
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"strict": true,
"module": "ESNext",
"target": "ESNext",
"moduleResolution": "node",
"noUncheckedIndexedAccess": true,
"strictNullChecks": true
},
"include": ["./src"]
}

7
scripts/build.sh Executable file
View File

@ -0,0 +1,7 @@
#!/bin/bash
set -a
source .env
set +a
yarn build

View File

@ -1,5 +1,7 @@
#!/bin/bash
set -a
source .env
set +a
docker-compose -f docker/docker-compose-dev.yaml build
docker-compose -f docker/docker-compose-dev.yaml up --remove-orphans
yarn dev

7
scripts/prod.sh Executable file
View File

@ -0,0 +1,7 @@
#!/bin/bash
set -a
source .env
set +a
yarn start

View File

@ -958,10 +958,10 @@
"@types/node" "*"
rxjs "^6.5.1"
"@types/node@*", "@types/node@^18.11.9", "@types/node@^18.8.2":
version "18.11.9"
resolved "https://registry.yarnpkg.com/@types/node/-/node-18.11.9.tgz#02d013de7058cea16d36168ef2fc653464cfbad4"
integrity sha512-CRpX21/kGdzjOpFsZSkcrXMGIBWMGNIHXXBVFSH+ggkftxg+XYP20TESbh+zFvFj3EQOl5byk0HTRn1IL6hbqg==
"@types/node@*", "@types/node@^18.11.17", "@types/node@^18.11.9", "@types/node@^18.8.2":
version "18.11.17"
resolved "https://registry.yarnpkg.com/@types/node/-/node-18.11.17.tgz#5c009e1d9c38f4a2a9d45c0b0c493fe6cdb4bcb5"
integrity sha512-HJSUJmni4BeDHhfzn6nF0sVmd1SMezP7/4F0Lq+aXzmp2xm9O7WXrUtHW/CHlYVtZUbByEvWidHqRtcJXGF2Ng==
"@types/parse-json@^4.0.0":
version "4.0.0"
@ -2791,11 +2791,6 @@ msgpackr@^1.5.4:
optionalDependencies:
msgpackr-extract "^2.2.0"
nanoevents@^7.0.1:
version "7.0.1"
resolved "https://registry.yarnpkg.com/nanoevents/-/nanoevents-7.0.1.tgz#181580b47787688d8cac775b977b1cf24e26e570"
integrity sha512-o6lpKiCxLeijK4hgsqfR6CNToPyRU3keKyyI6uwuHRvpRTbZ0wXw51WRgyldVugZqoJfkGFrjrIenYH3bfEO3Q==
nanoid@^3.3.4:
version "3.3.4"
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.4.tgz#730b67e3cd09e2deacf03c027c81c9d9dbc5e8ab"
@ -3700,7 +3695,7 @@ svelte-preprocess@^4.0.0, svelte-preprocess@^4.10.6:
sorcery "^0.10.0"
strip-indent "^3.0.0"
svelte@^3.44.0, svelte@^3.51.0:
svelte@^3.44.0:
version "3.53.1"
resolved "https://registry.yarnpkg.com/svelte/-/svelte-3.53.1.tgz#db9d7df7a8f570e8e22547444c149208b1914442"
integrity sha512-Q4/hHkktZogGhN5iqxqSi9sjEVoe/NbIxX4hXEHoasTxj+TxEQVAq66LnDMdAZxjmsodkoI5F3slqsS68U7FNw==
@ -3809,11 +3804,6 @@ tree-kill@^1.2.2:
resolved "https://registry.yarnpkg.com/tree-kill/-/tree-kill-1.2.2.tgz#4ca09a9092c88b73a7cdc5e8a01b507b0790a0cc"
integrity sha512-L0Orpi8qGpRG//Nd+H90vFB+3iHnue1zSSGmNOOCh1GLJ7rUKVwV2HvijphGQS2UmhUZewS9VgvxYIdgr+fG1A==
ts-brand@^0.0.2:
version "0.0.2"
resolved "https://registry.yarnpkg.com/ts-brand/-/ts-brand-0.0.2.tgz#b6cbca6ac94df1050a05844e23944eaeda1738a0"
integrity sha512-UhSzWY4On9ZHIj6DKkRYVN/8OaprbLAZ3b/Y2AJwdl6oozSABsQ0PvwDh4vOVdkvOtWQOkIrjctZ1kj8YfF3jA==
tslib@^1.9.0:
version "1.14.1"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"
@ -3824,7 +3814,7 @@ tslib@^2.1.0, tslib@^2.3.0, tslib@^2.3.1, tslib@^2.4.0:
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.4.1.tgz#0d0bfbaac2880b91e22df0768e55be9753a5b17e"
integrity sha512-tGyy4dAjRIEwI7BzsB0lynWgOpfqjUdq91XXAlIWD2OwKBH7oCl/GZG/HT4BOHrTlPMOASlMQ7veyTqpmRcrNA==
tsx@^3.11.0:
tsx@^3.11.0, tsx@^3.12.1:
version "3.12.1"
resolved "https://registry.yarnpkg.com/tsx/-/tsx-3.12.1.tgz#d07532004c573bfea50a4ac687aa7270b3e34277"
integrity sha512-Rcg1x+rNe7qwlP8j7kx4VjP/pJo/V57k+17hlrn6a7FuQLNwkaw5W4JF75tYornNVCxkXdSUnqlIT8JY/ttvIw==