From 5eb2531bc2ab28569343c35282fa2c9b2258107d Mon Sep 17 00:00:00 2001 From: ajosegun Date: Wed, 12 Jul 2023 21:23:50 +0000 Subject: [PATCH 1/9] Adding GCP Deployment Manager Template --- gcp/deployment/DEPLOY.md | 49 ++++++++++++ gcp/deployment/gcp_deploy_anything_llm.yaml | 83 +++++++++++++++++++++ gcp/deployment/generate.mjs | 61 +++++++++++++++ package copy.json | 23 ++++++ 4 files changed, 216 insertions(+) create mode 100644 gcp/deployment/DEPLOY.md create mode 100644 gcp/deployment/gcp_deploy_anything_llm.yaml create mode 100644 gcp/deployment/generate.mjs create mode 100644 package copy.json diff --git a/gcp/deployment/DEPLOY.md b/gcp/deployment/DEPLOY.md new file mode 100644 index 00000000000..5ada7f170ad --- /dev/null +++ b/gcp/deployment/DEPLOY.md @@ -0,0 +1,49 @@ +# How to deploy a private AnythingLLM instance on GCP + +With an AWS account you can easily deploy a private AnythingLLM instance on GCP. This will create a url that you can access from any browser over HTTP (HTTPS not supported). This single instance will run on your own keys and they will not be exposed - however if you want your instance to be protected it is highly recommend that you set the `AUTH_TOKEN` and `JWT_SECRET` variables in the `docker/` ENV. + +[Refer to .env.example](../../docker/HOW_TO_USE_DOCKER.md) for data format. + +The output of this cloudformation stack will be: +- 1 GCP VM +- 1 Security Group with 0.0.0.0/0 access on Ports 22 & 3001 +- 1 GCP VM Volume `gb2` of 10Gib minimum + +**Requirements** +- An GCP account with billing information. + - AnythingLLM (GUI + document processor) must use a n1-standard-1 minimum and 10Gib SSD hard disk volume +- `.env` file that is filled out with your settings and set up in the `docker/` folder + +## How to deploy on GCP +Open your terminal +1. Generate your specific cloudformation document by running `yarn generate:gcp_deployment` from the project root directory. +2. Thsi will create a new file (gcp_deploy_anything_llm_with_env.yaml) in the gcp/deployment folder. +3. Log in to your GCP account using the following command: + ''' gcloud auth login ''' + +4. After successful login, Run the following command to create a deployment using the Deployment Manager CLI: + + ''' gcloud deployment-manager deployments create anything-llm-deployment --config gcp/deployment/gcp_deploy_anything_llm_with_env.yaml ''' + +Once you execute these steps, the CLI will initiate the deployment process on GCP based on your configuration file. You can monitor the deployment status and view the outputs using the Google Cloud Console or the Deployment Manager CLI commands. + +''' gcloud compute instances get-serial-port-output anything-llm-instance ''' + +ssh into the instance + +''' gcloud compute ssh anything-llm-instance ''' + +Delete the deployment +''' gcloud deployment-manager deployments delete anything-llm-deployment ''' + +## Please read this notice before submitting issues about your deployment + +**Note:** +Your instance will not be available instantly. Depending on the instance size you launched with it can take anywhere from 10-20 minutes to fully boot up. + +If you want to check the instances progress, navigate to [your deployed EC2 instances](https://us-west-1.console.aws.amazon.com/ec2/home) and connect to your instance via SSH in browser. + +Once connected run `sudo tail -f /var/log/cloud-init-output.log` and wait for the file to conclude deployment of the docker image. + + +Additionally, your use of this deployment process means you are responsible for any costs of these GCP resources fully. \ No newline at end of file diff --git a/gcp/deployment/gcp_deploy_anything_llm.yaml b/gcp/deployment/gcp_deploy_anything_llm.yaml new file mode 100644 index 00000000000..61dd059db8b --- /dev/null +++ b/gcp/deployment/gcp_deploy_anything_llm.yaml @@ -0,0 +1,83 @@ +resources: + - name: anything-llm-instance + type: compute.v1.instance + properties: + zone: us-central1-a + machineType: zones/us-central1-a/machineTypes/n1-standard-1 + disks: + - deviceName: boot + type: PERSISTENT + boot: true + autoDelete: true + initializeParams: + sourceImage: projects/ubuntu-os-cloud/global/images/family/ubuntu-2004-lts + diskSizeGb: 10 + networkInterfaces: + - network: global/networks/default + accessConfigs: + - name: External NAT + type: ONE_TO_ONE_NAT + metadata: + items: + - key: startup-script + value: | + #!/bin/bash + # check output of userdata script with sudo tail -f /var/log/cloud-init-output.log + + sudo apt-get update + sudo apt-get install -y docker.io + sudo usermod -a -G docker ubuntu + + curl -L https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose + sudo chmod +x /usr/local/bin/docker-compose + sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose + + sudo systemctl enable docker + sudo systemctl start docker + + sudo apt-get install -y git + + git clone https://github.com/Mintplex-Labs/anything-llm.git /home/anything-llm + cd /home/anything-llm/docker + + cat >> .env << END + !SUB::USER::CONTENT! + UID="1000" + GID="1000" + NO_DEBUG="true" + END + + echo "Set .env file" + + cd ../frontend + sudo rm -rf .env.production + + sudo cat >> .env.production << END + GENERATE_SOURCEMAP=true + VITE_API_BASE="/api" + END + + echo "Set .env.production file" + + cd ../docker + sudo docker-compose up -d --build + echo "Container ID: $(sudo docker ps --latest --quiet)" + + sudo docker container exec -u 0 -t $(sudo docker ps --latest --quiet) mkdir -p /app/server/storage /app/server/storage/documents /app/server/storage/vector-cache /app/server/storage/lancedb + echo "Placeholder folders in storage created." + + sudo docker container exec -u 0 -t $(sudo docker ps --latest --quiet) touch /app/server/storage/anythingllm.db + echo "SQLite DB placeholder set." + + sudo docker container exec -u 0 -t $(sudo docker ps --latest --quiet) chown -R anythingllm:anythingllm /app/collector /app/server + echo "File permissions corrected." + + export ONLINE=$(curl -Is http://localhost:3001/api/ping | head -n 1|cut -d$' ' -f2) + echo "Health check: $ONLINE" + + if [ "$ONLINE" = 200 ]; then + echo "Running migrations..." && curl -Is http://localhost:3001/api/migrate | head -n 1 | cut -d$' ' -f2 + fi + + echo "Setup complete! AnythingLLM instance is now online!" + diff --git a/gcp/deployment/generate.mjs b/gcp/deployment/generate.mjs new file mode 100644 index 00000000000..2ac93bb4577 --- /dev/null +++ b/gcp/deployment/generate.mjs @@ -0,0 +1,61 @@ +import fs from 'fs'; +import { fileURLToPath } from 'url'; +import path, { dirname } from 'path'; +import { exit } from 'process'; +const __dirname = dirname(fileURLToPath(import.meta.url)); +const REPLACEMENT_KEY = '!SUB::USER::CONTENT!' + +const envPath = path.resolve(__dirname, `../../docker/.env`) +const envFileExists = fs.existsSync(envPath); + +const chalk = { + redBright: function (text) { + return `\x1b[31m${text}\x1b[0m` + }, + cyan: function (text) { + return `\x1b[36m${text}\x1b[0m` + }, + greenBright: function (text) { + return `\x1b[32m${text}\x1b[0m` + }, + blueBright: function (text) { + return `\x1b[34m${text}\x1b[0m` + } +} + +if (!envFileExists) { + console.log(chalk.redBright('[ABORT]'), 'You do not have an .env file in your ./docker/ folder. You need to create it first.'); + console.log('You can start by running', chalk.cyan('cp -n ./docker/.env.example ./docker/.env')) + exit(1); +} + +// Remove comments +// Remove UID,GID,etc +// Remove empty strings +// Split into array +const settings = fs.readFileSync(envPath, "utf8") + .replace(/^#.*\n?/gm, '') + .replace(/^UID.*\n?/gm, '') + .replace(/^GID.*\n?/gm, '') + .replace(/^CLOUD_BUILD.*\n?/gm, '') + .replace(/^\s*\n/gm, "") + .split('\n') + .filter((i) => !!i); +const formattedSettings = settings.map((i, index) => index === 0 ? i + '\n' : ' ' + i).join('\n'); + +// Read the existing GCP Deployment Manager template +const templatePath = path.resolve(__dirname, `gcp_deploy_anything_llm.yaml`); +const templateString = fs.readFileSync(templatePath, "utf8"); + +// Update the metadata section with the UserData content +const updatedTemplateString = templateString.replace(REPLACEMENT_KEY, formattedSettings); + +// Save the updated GCP Deployment Manager template +const output = path.resolve(__dirname, `gcp_deploy_anything_llm_with_env.yaml`); +fs.writeFileSync(output, updatedTemplateString, "utf8"); + +console.log(chalk.greenBright('[SUCCESS]'), 'Deploy AnythingLLM on GCP Deployment Manager using your template document.'); +console.log(chalk.greenBright('File Created:'), 'gcp_deploy_anything_llm_with_env.yaml in the output directory.'); +console.log(chalk.blueBright('[INFO]'), 'Refer to the GCP Deployment Manager documentation for how to use this file.'); + +exit(); diff --git a/package copy.json b/package copy.json new file mode 100644 index 00000000000..f51505fabc8 --- /dev/null +++ b/package copy.json @@ -0,0 +1,23 @@ +{ + "name": "anything-llm", + "version": "0.0.1-beta", + "description": "Turn anything into a chattable document through a simple UI", + "main": "index.js", + "author": "Timothy Carambat (Mintplex Labs)", + "license": "MIT", + "engines": { + "node": ">=18" + }, + "scripts": { + "lint": "cd server && yarn lint && cd .. && cd frontend && yarn lint", + "setup": "cd server && yarn && cd ../frontend && yarn && cd .. && yarn setup:envs && echo \"Please run yarn dev:server and yarn dev:frontend in separate terminal tabs.\"", + "setup:envs": "cp -n ./server/.env.example ./server/.env.development && cp -n ./collector/.env.example ./collector/.env && cp -n ./docker/.env.example ./docker/.env && echo \"All ENV files copied!\n\"", + "dev:server": "cd server && yarn dev", + "dev:frontend": "cd frontend && yarn start", + "prod:server": "cd server && yarn start", + "prod:frontend": "cd frontend && yarn build", + "generate:cloudformation": "node aws/cloudformation/generate.mjs", + "generate::gcp_deployment": "node gcp/deployment/generate.mjs" + }, + "private": false +} \ No newline at end of file From 630be0aad5089f655e55b61efc42338fd8f1b489 Mon Sep 17 00:00:00 2001 From: ajosegun Date: Wed, 12 Jul 2023 21:25:23 +0000 Subject: [PATCH 2/9] Adding GCP Deployment Manager Template --- package copy.json | 23 ----------------------- package.json | 3 ++- 2 files changed, 2 insertions(+), 24 deletions(-) delete mode 100644 package copy.json diff --git a/package copy.json b/package copy.json deleted file mode 100644 index f51505fabc8..00000000000 --- a/package copy.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "name": "anything-llm", - "version": "0.0.1-beta", - "description": "Turn anything into a chattable document through a simple UI", - "main": "index.js", - "author": "Timothy Carambat (Mintplex Labs)", - "license": "MIT", - "engines": { - "node": ">=18" - }, - "scripts": { - "lint": "cd server && yarn lint && cd .. && cd frontend && yarn lint", - "setup": "cd server && yarn && cd ../frontend && yarn && cd .. && yarn setup:envs && echo \"Please run yarn dev:server and yarn dev:frontend in separate terminal tabs.\"", - "setup:envs": "cp -n ./server/.env.example ./server/.env.development && cp -n ./collector/.env.example ./collector/.env && cp -n ./docker/.env.example ./docker/.env && echo \"All ENV files copied!\n\"", - "dev:server": "cd server && yarn dev", - "dev:frontend": "cd frontend && yarn start", - "prod:server": "cd server && yarn start", - "prod:frontend": "cd frontend && yarn build", - "generate:cloudformation": "node aws/cloudformation/generate.mjs", - "generate::gcp_deployment": "node gcp/deployment/generate.mjs" - }, - "private": false -} \ No newline at end of file diff --git a/package.json b/package.json index a6bab10e0d2..f51505fabc8 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,8 @@ "dev:frontend": "cd frontend && yarn start", "prod:server": "cd server && yarn start", "prod:frontend": "cd frontend && yarn build", - "generate:cloudformation": "node aws/cloudformation/generate.mjs" + "generate:cloudformation": "node aws/cloudformation/generate.mjs", + "generate::gcp_deployment": "node gcp/deployment/generate.mjs" }, "private": false } \ No newline at end of file From 5fcaa9de73a4dfe3e038639c312259eb05ae6c91 Mon Sep 17 00:00:00 2001 From: Olusegun Ajose <94995067+ajosegun@users.noreply.github.com> Date: Wed, 12 Jul 2023 23:28:37 +0200 Subject: [PATCH 3/9] Adding GCP Deployment Manager Template --- gcp/deployment/DEPLOY.md | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/gcp/deployment/DEPLOY.md b/gcp/deployment/DEPLOY.md index 5ada7f170ad..f8c0cc1bc13 100644 --- a/gcp/deployment/DEPLOY.md +++ b/gcp/deployment/DEPLOY.md @@ -19,7 +19,9 @@ Open your terminal 1. Generate your specific cloudformation document by running `yarn generate:gcp_deployment` from the project root directory. 2. Thsi will create a new file (gcp_deploy_anything_llm_with_env.yaml) in the gcp/deployment folder. 3. Log in to your GCP account using the following command: - ''' gcloud auth login ''' + ``` + gcloud auth login + ``` 4. After successful login, Run the following command to create a deployment using the Deployment Manager CLI: @@ -27,14 +29,20 @@ Open your terminal Once you execute these steps, the CLI will initiate the deployment process on GCP based on your configuration file. You can monitor the deployment status and view the outputs using the Google Cloud Console or the Deployment Manager CLI commands. -''' gcloud compute instances get-serial-port-output anything-llm-instance ''' +``` +gcloud compute instances get-serial-port-output anything-llm-instance +``` ssh into the instance -''' gcloud compute ssh anything-llm-instance ''' +``` +gcloud compute ssh anything-llm-instance +``` Delete the deployment -''' gcloud deployment-manager deployments delete anything-llm-deployment ''' +``` +gcloud deployment-manager deployments delete anything-llm-deployment +``` ## Please read this notice before submitting issues about your deployment @@ -46,4 +54,4 @@ If you want to check the instances progress, navigate to [your deployed EC2 inst Once connected run `sudo tail -f /var/log/cloud-init-output.log` and wait for the file to conclude deployment of the docker image. -Additionally, your use of this deployment process means you are responsible for any costs of these GCP resources fully. \ No newline at end of file +Additionally, your use of this deployment process means you are responsible for any costs of these GCP resources fully. From ffbd1adc67d12315ad76aba2efcec875c9ef5ef1 Mon Sep 17 00:00:00 2001 From: Olusegun Ajose <94995067+ajosegun@users.noreply.github.com> Date: Thu, 13 Jul 2023 12:26:56 +0200 Subject: [PATCH 4/9] Update gcp/deployment/DEPLOY.md Co-authored-by: David Blore <42894467+DavidBlore@users.noreply.github.com> --- gcp/deployment/DEPLOY.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcp/deployment/DEPLOY.md b/gcp/deployment/DEPLOY.md index f8c0cc1bc13..9b9fa7db1e4 100644 --- a/gcp/deployment/DEPLOY.md +++ b/gcp/deployment/DEPLOY.md @@ -1,6 +1,6 @@ # How to deploy a private AnythingLLM instance on GCP -With an AWS account you can easily deploy a private AnythingLLM instance on GCP. This will create a url that you can access from any browser over HTTP (HTTPS not supported). This single instance will run on your own keys and they will not be exposed - however if you want your instance to be protected it is highly recommend that you set the `AUTH_TOKEN` and `JWT_SECRET` variables in the `docker/` ENV. +With a GCP account you can easily deploy a private AnythingLLM instance on GCP. This will create a url that you can access from any browser over HTTP (HTTPS not supported). This single instance will run on your own keys and they will not be exposed - however if you want your instance to be protected it is highly recommend that you set the `AUTH_TOKEN` and `JWT_SECRET` variables in the `docker/` ENV. [Refer to .env.example](../../docker/HOW_TO_USE_DOCKER.md) for data format. From 3f91a90c7ca27c89c4e2cd0796a08d86903f101b Mon Sep 17 00:00:00 2001 From: Olusegun Ajose <94995067+ajosegun@users.noreply.github.com> Date: Thu, 13 Jul 2023 12:32:48 +0200 Subject: [PATCH 5/9] Update gcp/deployment/DEPLOY.md Co-authored-by: David Blore <42894467+DavidBlore@users.noreply.github.com> --- gcp/deployment/DEPLOY.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcp/deployment/DEPLOY.md b/gcp/deployment/DEPLOY.md index 9b9fa7db1e4..be68b92cd07 100644 --- a/gcp/deployment/DEPLOY.md +++ b/gcp/deployment/DEPLOY.md @@ -49,7 +49,7 @@ gcloud deployment-manager deployments delete anything-llm-deployment **Note:** Your instance will not be available instantly. Depending on the instance size you launched with it can take anywhere from 10-20 minutes to fully boot up. -If you want to check the instances progress, navigate to [your deployed EC2 instances](https://us-west-1.console.aws.amazon.com/ec2/home) and connect to your instance via SSH in browser. +If you want to check the instances progress, navigate to [your deployed instances](https://console.cloud.google.com/compute/instances) and connect to your instance via SSH in browser. Once connected run `sudo tail -f /var/log/cloud-init-output.log` and wait for the file to conclude deployment of the docker image. From 4a16b9d12cb1a0b47fc582cad578b32e576fd66b Mon Sep 17 00:00:00 2001 From: Olusegun Ajose <94995067+ajosegun@users.noreply.github.com> Date: Thu, 13 Jul 2023 12:38:57 +0200 Subject: [PATCH 6/9] Update gcp/deployment/DEPLOY.md Co-authored-by: David Blore <42894467+DavidBlore@users.noreply.github.com> --- gcp/deployment/DEPLOY.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcp/deployment/DEPLOY.md b/gcp/deployment/DEPLOY.md index be68b92cd07..e6b702b7b7a 100644 --- a/gcp/deployment/DEPLOY.md +++ b/gcp/deployment/DEPLOY.md @@ -17,7 +17,7 @@ The output of this cloudformation stack will be: ## How to deploy on GCP Open your terminal 1. Generate your specific cloudformation document by running `yarn generate:gcp_deployment` from the project root directory. -2. Thsi will create a new file (gcp_deploy_anything_llm_with_env.yaml) in the gcp/deployment folder. +2. This will create a new file (`gcp_deploy_anything_llm_with_env.yaml`) in the `gcp/deployment` folder. 3. Log in to your GCP account using the following command: ``` gcloud auth login From ccaf7fdf681936b88c01c7a925002874bd138088 Mon Sep 17 00:00:00 2001 From: Olusegun Ajose <94995067+ajosegun@users.noreply.github.com> Date: Thu, 13 Jul 2023 19:12:14 +0200 Subject: [PATCH 7/9] Update DEPLOY.md --- gcp/deployment/DEPLOY.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcp/deployment/DEPLOY.md b/gcp/deployment/DEPLOY.md index e6b702b7b7a..d60cfd2c811 100644 --- a/gcp/deployment/DEPLOY.md +++ b/gcp/deployment/DEPLOY.md @@ -25,7 +25,7 @@ Open your terminal 4. After successful login, Run the following command to create a deployment using the Deployment Manager CLI: - ''' gcloud deployment-manager deployments create anything-llm-deployment --config gcp/deployment/gcp_deploy_anything_llm_with_env.yaml ''' + ``` gcloud deployment-manager deployments create anything-llm-deployment --config gcp/deployment/gcp_deploy_anything_llm_with_env.yaml ``` Once you execute these steps, the CLI will initiate the deployment process on GCP based on your configuration file. You can monitor the deployment status and view the outputs using the Google Cloud Console or the Deployment Manager CLI commands. From 8074b7829b3cd8b30579ba48d063b6241c913736 Mon Sep 17 00:00:00 2001 From: Olusegun Ajose <94995067+ajosegun@users.noreply.github.com> Date: Thu, 13 Jul 2023 19:12:41 +0200 Subject: [PATCH 8/9] Update DEPLOY.md --- gcp/deployment/DEPLOY.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gcp/deployment/DEPLOY.md b/gcp/deployment/DEPLOY.md index d60cfd2c811..d75cd023e14 100644 --- a/gcp/deployment/DEPLOY.md +++ b/gcp/deployment/DEPLOY.md @@ -25,7 +25,9 @@ Open your terminal 4. After successful login, Run the following command to create a deployment using the Deployment Manager CLI: - ``` gcloud deployment-manager deployments create anything-llm-deployment --config gcp/deployment/gcp_deploy_anything_llm_with_env.yaml ``` + ``` + gcloud deployment-manager deployments create anything-llm-deployment --config gcp/deployment/gcp_deploy_anything_llm_with_env.yaml +``` Once you execute these steps, the CLI will initiate the deployment process on GCP based on your configuration file. You can monitor the deployment status and view the outputs using the Google Cloud Console or the Deployment Manager CLI commands. From c13d583ddddee0a38edf024701e73bcc3a002a6b Mon Sep 17 00:00:00 2001 From: Olusegun Ajose <94995067+ajosegun@users.noreply.github.com> Date: Thu, 13 Jul 2023 19:13:04 +0200 Subject: [PATCH 9/9] Update DEPLOY.md --- gcp/deployment/DEPLOY.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/gcp/deployment/DEPLOY.md b/gcp/deployment/DEPLOY.md index d75cd023e14..3628c435cf1 100644 --- a/gcp/deployment/DEPLOY.md +++ b/gcp/deployment/DEPLOY.md @@ -25,9 +25,11 @@ Open your terminal 4. After successful login, Run the following command to create a deployment using the Deployment Manager CLI: - ``` + ``` + gcloud deployment-manager deployments create anything-llm-deployment --config gcp/deployment/gcp_deploy_anything_llm_with_env.yaml -``` + + ``` Once you execute these steps, the CLI will initiate the deployment process on GCP based on your configuration file. You can monitor the deployment status and view the outputs using the Google Cloud Console or the Deployment Manager CLI commands.