Skip to content

Commit

Permalink
compute server: run https proxy on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
williamstein committed Mar 16, 2024
1 parent 0b185ab commit a23d2f1
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/packages/server/compute/cloud/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions src/packages/server/compute/cloud/startup-script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
installDocker,
installNode,
installCoCalc,
installHttpsProxy,
installConf,
installMicroK8s,
installUser,
Expand Down Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions src/packages/util/db-schema/compute-servers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down

0 comments on commit a23d2f1

Please sign in to comment.