mirror of
https://github.com/Mintplex-Labs/anything-llm.git
synced 2024-11-19 20:50:09 +01:00
Adding GCP Deployment Template (#142)
* Adding GCP Deployment Manager Template * Adding GCP Deployment Manager Template * Adding GCP Deployment Manager Template * Update gcp/deployment/DEPLOY.md Co-authored-by: David Blore <42894467+DavidBlore@users.noreply.github.com> * Update gcp/deployment/DEPLOY.md Co-authored-by: David Blore <42894467+DavidBlore@users.noreply.github.com> * Update gcp/deployment/DEPLOY.md Co-authored-by: David Blore <42894467+DavidBlore@users.noreply.github.com> * Update DEPLOY.md * Update DEPLOY.md * Update DEPLOY.md --------- Co-authored-by: David Blore <42894467+DavidBlore@users.noreply.github.com>
This commit is contained in:
parent
c6d030f390
commit
284fe6f356
61
gcp/deployment/DEPLOY.md
Normal file
61
gcp/deployment/DEPLOY.md
Normal file
@ -0,0 +1,61 @@
|
||||
# How to deploy a private AnythingLLM instance on GCP
|
||||
|
||||
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.
|
||||
|
||||
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. 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
|
||||
```
|
||||
|
||||
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 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.
|
||||
|
||||
|
||||
Additionally, your use of this deployment process means you are responsible for any costs of these GCP resources fully.
|
83
gcp/deployment/gcp_deploy_anything_llm.yaml
Normal file
83
gcp/deployment/gcp_deploy_anything_llm.yaml
Normal file
@ -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!"
|
||||
|
61
gcp/deployment/generate.mjs
Normal file
61
gcp/deployment/generate.mjs
Normal file
@ -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();
|
@ -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
|
||||
}
|
Loading…
Reference in New Issue
Block a user