diff --git a/src/packages/server/compute/cloud/install.ts b/src/packages/server/compute/cloud/install.ts index bd426a04a9..0aea618c40 100644 --- a/src/packages/server/compute/cloud/install.ts +++ b/src/packages/server/compute/cloud/install.ts @@ -107,6 +107,35 @@ set -v `; } +// if installHttpsProxy runs, it has to be after installNode +// TODO: A problem with this is for some reason it fails to run below, +// it won't be reported. Also, maybe this should be in some sort +// of official systemd daemon. +// Todo: maybe also nail down the version or tag better. I suspect +// the proxy will get very stable soon. +// This could also just merge with the @cocalc/compute-server package. +export function installHttpsProxy({ + IMAGES, + image, +}: { + IMAGES: Images; + image: string; +}) { + const proxy = IMAGES[image]?.proxy; + if (proxy === false) { + return ""; + } + + return ` +set +v +NVM_DIR=/cocalc/nvm source /cocalc/nvm/nvm.sh +set -v + +DEBUG=proxy:* PROXY_CONFIG=/cocalc/conf/proxy.json PROXY_AUTH_TOKEN_FILE=/cocalc/conf/auth_token npx -y @cocalc/compute-server-proxy@latest > /var/log/cocalc-proxy.log 2> /var/log/cocalc-proxy.err & + +`; +} + export function installMicroK8s({ image, IMAGES, diff --git a/src/packages/server/compute/cloud/startup-script.ts b/src/packages/server/compute/cloud/startup-script.ts index cf60566f98..14752ee1a1 100644 --- a/src/packages/server/compute/cloud/startup-script.ts +++ b/src/packages/server/compute/cloud/startup-script.ts @@ -4,6 +4,7 @@ import { installDocker, installNode, installCoCalc, + installHttpsProxy, installConf, installMicroK8s, installUser, @@ -122,6 +123,9 @@ if [ $? -ne 0 ]; then exit 1 fi +setState install install-proxy '' 60 55 +${installHttpsProxy({ IMAGES, image })} + setState install install-user '' 60 60 ${doInstallUser ? installUser() : ""} if [ $? -ne 0 ]; then diff --git a/src/packages/util/db-schema/compute-servers.ts b/src/packages/util/db-schema/compute-servers.ts index 68e578d4d9..9b80a44144 100644 --- a/src/packages/util/db-schema/compute-servers.ts +++ b/src/packages/util/db-schema/compute-servers.ts @@ -63,6 +63,18 @@ export interface Image { disabled?: boolean; // priority -- optional integer used for sorting options to display to user. The bigger the higher. priority?: number; + // proxy: if false, do NOT run https proxy server on host VM + // if nothing given, runs proxy server with no default config (so does nothing) + // if given, is array of proxy config. + proxy?: + | false + | { + path: string; + target: string; + ws?: boolean; + options?: any; + wsOptions?: any; + }[]; } export type Images = { [name: string]: Image };