-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added terraform for Vultr * Fixed terraform format Fixed typo for container name * Minor changes Added ENABLE_PRIMITIVE option Fixed md linter errors * Fixed another md linter errors Co-authored-by: Oleksii Titov <[email protected]>
- Loading branch information
Showing
5 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,33 @@ | ||
# Vultr deployment | ||
|
||
## Requirements | ||
|
||
* Vultr account | ||
* API token | ||
* `terraform` | ||
|
||
## Deploy | ||
|
||
```bash | ||
export VULTR_API_KEY="Your Vultr API Key" | ||
terraform init | ||
terraform plan -var "key=<path_to_ssh_key>" -var "num_inst=<number of instances to create>" | ||
terraform apply -var "key=<path_to_ssh_key>" -var "num_inst=<number of instances to create>" | ||
``` | ||
|
||
## Destroy | ||
|
||
To delete all the resources that were created run | ||
|
||
```bash | ||
terraform destroy | ||
``` | ||
|
||
## Tips | ||
|
||
Deploy script installs vnstat util that is useful for monitoring server network performance. | ||
Example, get network statistics for the last 5 hours: | ||
|
||
```bash | ||
ssh root@ip vnstat -h 5 | ||
``` |
This file contains 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,32 @@ | ||
terraform { | ||
required_providers { | ||
vultr = { | ||
source = "vultr/vultr" | ||
version = "2.10.0" | ||
} | ||
} | ||
} | ||
|
||
resource "vultr_ssh_key" "ssh_key" { | ||
name = "my-ssh-key" | ||
ssh_key = file("${var.key}.pub") | ||
} | ||
|
||
resource "vultr_instance" "my_instance" { | ||
count = var.num_inst | ||
plan = var.plan | ||
region = var.region | ||
app_id = var.app | ||
ssh_key_ids = [vultr_ssh_key.ssh_key.id] | ||
|
||
provisioner "remote-exec" { | ||
script = "scripts/deploy.sh" | ||
|
||
connection { | ||
host = self.main_ip | ||
private_key = file("${var.key}") | ||
} | ||
} | ||
} | ||
|
||
|
This file contains 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,3 @@ | ||
output "ip" { | ||
value = vultr_instance.my_instance[*].main_ip | ||
} |
This file contains 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,11 @@ | ||
#! /bin/bash | ||
|
||
apt install -y vnstat | ||
|
||
container_name="db1000n" | ||
docker_cmd="docker run -d -it --rm --name=${container_name} -e ENABLE_PRIMITIVE=false --pull always ghcr.io/arriven/db1000n" | ||
|
||
${docker_cmd} | ||
|
||
echo "0 */2 * * * docker kill ${container_name} || true && ${docker_cmd}" >> cronjob | ||
crontab cronjob |
This file contains 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,22 @@ | ||
|
||
variable "region" { | ||
default = "icn" # Seoul, South Korea | ||
} | ||
|
||
variable "plan" { | ||
default = "vc2-1c-1gb" | ||
} | ||
|
||
variable "app" { | ||
description = "Docker Ubuntu 20.04" | ||
default = "37" | ||
} | ||
|
||
variable "key" { | ||
description = "Path to SSH key" | ||
type = string | ||
} | ||
|
||
variable "num_inst" { | ||
type = number | ||
} |