Skip to content

Commit

Permalink
update image and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
howardchung committed Jan 13, 2024
1 parent eac3a96 commit cef6bc4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ An website for watching videos together.

- Clone this repo via `git clone [email protected]:howardchung/watchparty.git`
- Install npm dependencies for the project via `npm install`
- Start the server via `PORT=8080 npm run dev`
- Start the server via `npm run dev`
- Defaults to port 8080, customize with `PORT` env var
- Set `SSL_KEY_FILE` and `SSL_CRT_FILE` for HTTPS.
- Start the React application in a separate shell and port via `PORT=3000 npm run react`
- Start the React application in a separate shell and port via `npm run react`
- Point to server using `VITE_SERVER_HOST` env var if you customized it above
- If the above SSL vars are set, HTTPS will be used. This is required by the browser for some WebRTC features (camera, etc.)
- Set `SSL_KEY_FILE` and `SSL_CRT_FILE` for HTTPS.
- HTTPS is required by the browser for some WebRTC features (camera, etc.)
- Duplicate the `.env.example` file
- Rename it to `.env`
- Add config for the features you want as described in the advanced setup
Expand Down Expand Up @@ -60,12 +61,11 @@ For server verification of accounts you'll also need `FIREBASE_ADMIN_SDK_CONFIG`

### Virtual Browser Setup

This project supports creating virtual browsers (using https://github.com/m1k1o/neko) either on a cloud provider, or by spawning Docker containers on the development server. For local development, the Docker on local approach is preferred.
This project supports creating virtual browsers (using https://github.com/m1k1o/neko) either on a cloud provider, or by spawning Docker containers on the local server. For development, Docker is preferred.

- Install Docker: `curl -fsSL https://get.docker.com | sh`
- Make sure you have an SSH key pair set up on the server (`id_rsa` in `~/.ssh` directory)
- Add `DOCKER_VM_HOST=localhost` to your .env file (can substitute localhost for a public hostname)
- Add `NODE_ENV=development` to .env to enable create-on-demand behavior for VMs
- Configure Postgres by adding `DATABASE_URL` to your .env file (Postgres is required for virtual browser management)

### Room Persistence
Expand All @@ -79,4 +79,5 @@ This project supports creating virtual browsers (using https://github.com/m1k1o/
- TypeScript
- Node.js
- Redis
- PostgreSQL
- Docker
2 changes: 1 addition & 1 deletion server/ecosystem.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ module.exports = {
env: {
HETZNER_GATEWAY: 'gateway2.watchparty.me',
HETZNER_SSH_KEYS: '1570536',
HETZNER_IMAGE: '111607093',
HETZNER_IMAGE: '144567177',
SCW_GATEWAY: 'gateway1.watchparty.me',
SCW_IMAGE: '',
DO_GATEWAY: 'gateway4.watchparty.me',
Expand Down
16 changes: 7 additions & 9 deletions server/vm/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ export abstract class VMManager {
}
console.log('[RESET]', vmid);
await this.rebootVM(vmid);
// we could crash here and then record will remain in used state
// need to periocally reset stale VMs
// we could crash here and then row will remain in used state
// Once the heartbeat becomes stale cleanup will reset it

// We generally want to reuse if the provider has per-hour billing
// Since most user sessions are less than an hour
Expand Down Expand Up @@ -309,11 +309,10 @@ export abstract class VMManager {
};

const cleanupVMGroup = async () => {
// Clean up hanging VMs
// Reset hanging VMs
// It's possible we created a VM but lost track of it
// Take the list of VMs from API
// subtract VMs that have a heartbeat or available or staging
// delete the rest
let allVMs = [];
try {
allVMs = await this.listVMs(this.getTag());
Expand All @@ -332,16 +331,17 @@ export abstract class VMManager {
`,
[this.getPoolName()]
);
const dontDelete = new Set(rows.map((row: any) => row.vmid));
const inUse = new Set(rows.map((row: any) => row.vmid));
console.log(
'[CLEANUP] %s: found %s VMs, %s to keep',
this.getPoolName(),
allVMs.length,
dontDelete.size
inUse.size
);
for (let i = 0; i < allVMs.length; i++) {
const server = allVMs[i];
if (!dontDelete.has(server.id)) {
if (!inUse.has(server.id)) {
// TODO log how many cleanups we do
console.log('[CLEANUP]', server.id);
try {
await this.resetVM(server.id);
Expand Down Expand Up @@ -462,8 +462,6 @@ export abstract class VMManager {
this.getPoolName()
);

// TODO (howard) reset stale heartbeat VMs

setInterval(resizeVMGroupIncr, incrInterval);
setInterval(resizeVMGroupDecr, decrInterval);
setInterval(async () => {
Expand Down
9 changes: 6 additions & 3 deletions server/vm/docker.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
// This assumes an installation of Docker exists at the Docker VM host
// This assumes an installation of Docker exists at DOCKER_VM_HOST
// and that host is configured to accept our SSH key
import config from '../config';
import { VMManager, VM } from './base';
import { imageName } from './utils';
import fs from 'fs';
import { homedir } from 'os';
//@ts-ignore
import sshExec from 'ssh-exec';

const gatewayHost = config.DOCKER_VM_HOST;
const sshConfig = {
user: config.DOCKER_VM_HOST_SSH_USER || 'root',
host: gatewayHost,
// Defaults to ~/.ssh/id_rsa
// The private key the Docker host is configured to accept
key: config.DOCKER_VM_HOST_SSH_KEY_BASE64
? Buffer.from(config.DOCKER_VM_HOST_SSH_KEY_BASE64, 'base64')
: undefined,
: // Defaults to ~/.ssh/id_rsa on the local server
fs.readFileSync(homedir() + '/.ssh/id_rsa'),
};

export class Docker extends VMManager {
Expand Down

0 comments on commit cef6bc4

Please sign in to comment.