-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Adding Digital Ocean Deployment using Terraform #148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
5eb2531
Adding GCP Deployment Manager Template
ajosegun 630be0a
Adding GCP Deployment Manager Template
ajosegun 5fcaa9d
Adding GCP Deployment Manager Template
ajosegun ffbd1ad
Update gcp/deployment/DEPLOY.md
ajosegun 3f91a90
Update gcp/deployment/DEPLOY.md
ajosegun 4a16b9d
Update gcp/deployment/DEPLOY.md
ajosegun ccaf7fd
Update DEPLOY.md
ajosegun 8074b78
Update DEPLOY.md
ajosegun c13d583
Update DEPLOY.md
ajosegun 83117cb
Merge branch 'Mintplex-Labs:master' into master
ajosegun 9db9b42
Adding Digital Ocean Deployment using Terraform
ajosegun d95e4c6
Adding Digital Ocean Deployment with Terraform
ajosegun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| # How to deploy a private AnythingLLM instance on DigitalOcean using Terraform | ||
|
|
||
| With a DigitalOcean account, you can easily deploy a private AnythingLLM instance using Terraform. 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 recommended 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 Terraform configuration will be: | ||
| - 1 DigitalOcean Droplet | ||
| - An IP address to access your application | ||
|
|
||
| **Requirements** | ||
| - An DigitalOcean account with billing information | ||
| - Terraform installed on your local machine | ||
| - Follow the instructions in the [official Terraform documentation](https://developer.hashicorp.com/terraform/tutorials/aws-get-started/install-cli) for your operating system. | ||
| - `.env` file that is filled out with your settings and set up in the `docker/` folder | ||
|
|
||
|
|
||
| ## How to deploy on DigitalOcean | ||
| Open your terminal and navigate to the `digitalocean/terraform` folder | ||
| 1. Replace the token value in the provider "digitalocean" block in main.tf with your DigitalOcean API token. | ||
| 2. Run the following commands to initialize Terraform, review the infrastructure changes, and apply them: | ||
| ``` | ||
| terraform init | ||
| terraform plan | ||
| terraform apply | ||
| ``` | ||
| Confirm the changes by typing yes when prompted. | ||
| 4. Once the deployment is complete, Terraform will output the public IP address of your droplet. You can access your application using this IP address. | ||
|
|
||
| ## How to deploy on DigitalOcean | ||
| To delete the resources created by Terraform, run the following command in the terminal: | ||
| ` | ||
| terraform destroy | ||
| ` | ||
|
|
||
| ## 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://cloud.digitalocean.com/droplets) 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 Digital Ocean resources fully. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| terraform { | ||
| required_version = ">= 1.0.0" | ||
|
|
||
| required_providers { | ||
| digitalocean = { | ||
| source = "digitalocean/digitalocean" | ||
| version = "~> 2.0" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| provider "digitalocean" { | ||
| # Add your DigitalOcean API token here | ||
| token = "DigitalOcean API token" | ||
| } | ||
|
|
||
|
|
||
| resource "digitalocean_droplet" "anything_llm_instance" { | ||
| image = "ubuntu-22-10-x64" | ||
| name = "anything-llm-instance" | ||
| region = "nyc3" | ||
| size = "s-1vcpu-1gb" | ||
|
|
||
| user_data = templatefile("user_data.tp1", { | ||
| env_content = local.formatted_env_content | ||
| }) | ||
| } | ||
|
|
||
| locals { | ||
| env_content = file("../../docker/.env") | ||
| formatted_env_content = join("\n", [ | ||
| for line in split("\n", local.env_content) : | ||
| line | ||
| if !( | ||
| ( | ||
| substr(line, 0, 1) == "#" | ||
| ) || | ||
| ( | ||
| substr(line, 0, 3) == "UID" | ||
| ) || | ||
| ( | ||
| substr(line, 0, 3) == "GID" | ||
| ) || | ||
| ( | ||
| substr(line, 0, 11) == "CLOUD_BUILD" | ||
| ) || | ||
| ( | ||
| line == "" | ||
| ) | ||
| ) | ||
| ]) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| output "ip_address" { | ||
| value = digitalocean_droplet.anything_llm_instance.ipv4_address | ||
| description = "The public IP address of your droplet application." | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| #!/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 | ||
| ${env_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!" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hello, when trying to use this I am getting the following error
Error: Invalid function argument
│
│ on main.tf line 33, in locals:
│ 33: env_content = file("../../docker/.env")
│ ├────────────────
│ │ while calling file(path)
│
│ Invalid value for "path" parameter: no file exists at "../../docker/.env"; this function works only with files that are distributed as part
│ of the configuration source code, so if this file will be created by a resource in this configuration you must instead obtain this result
│ from an attribute of that resource.
╵
Am I missing something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are not running the terraform template from inside the directory the template is in - as you can see it looks two directories up for the
dockerfolder. Change that line if the .env is in the same directory