Skip to content
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

deploy: optimise resources #1678

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions docker/production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,15 @@ services:
networks:
- cloud
deploy:
replicas: 3
<<: *x-update-config
replicas: 2
resources:
limits:
cpus: '0.5'
memory: 512M
reservations:
cpus: '0.1'
memory: 256M
placement:
max_replicas_per_node: 1
constraints:
Expand All @@ -84,7 +91,14 @@ services:
deploy:
<<: *x-update-config
mode: replicated
replicas: 8
replicas: 6
resources:
limits:
cpus: '0.8'
memory: 1G
reservations:
cpus: '0.1'
memory: 512M
placement:
max_replicas_per_node: 2
constraints:
Expand Down
18 changes: 16 additions & 2 deletions docker/stage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,15 @@ services:
networks:
- cloud
deploy:
replicas: 3
<<: *x-update-config
replicas: 1
resources:
limits:
cpus: '0.3'
memory: 256M
reservations:
cpus: '0.1'
memory: 128M
placement:
max_replicas_per_node: 1
constraints:
Expand All @@ -78,7 +85,14 @@ services:
deploy:
<<: *x-update-config
mode: replicated
replicas: 8
replicas: 3
resources:
limits:
cpus: '0.5'
memory: 512M
reservations:
cpus: '0.1'
memory: 256M
placement:
max_replicas_per_node: 2
constraints:
Expand Down
10 changes: 5 additions & 5 deletions terraform/environments/production/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ module "droplets" {
region = "fra1"
environment = "prd"
base_image = "docker-20-04"
worker_size = "s-2vcpu-2gb-amd"
worker_count = 6
worker_size = "s-1vcpu-2gb-amd"
worker_count = 4
subnet_range = "10.117.0.0/20"
manager_size = "s-2vcpu-2gb-amd"
manager_count = 2
manager_size = "s-1vcpu-2gb-amd"
manager_count = 1

digitalocean_project_name = "Production - Homepage"
}
}
10 changes: 5 additions & 5 deletions terraform/environments/staging/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ module "droplets" {
environment = "stg"
base_image = "docker-20-04"
subnet_range = "10.116.0.0/20"
worker_size = "s-1vcpu-2gb"
worker_count = 4
manager_size = "s-1vcpu-2gb"
manager_count = 2
worker_size = "s-1vcpu-1gb"
worker_count = 2
manager_size = "s-1vcpu-1gb"
manager_count = 1

digitalocean_project_name = "Staging - Homepage"
}
}
10 changes: 7 additions & 3 deletions terraform/modules/digitalocean/droplets.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ resource "digitalocean_project" "homepage" {
purpose = "Web Application"
environment = "Development"
resources = flatten([
digitalocean_droplet.leader.urn,
digitalocean_droplet.leader.urn,
digitalocean_droplet.manager[*].urn,
digitalocean_droplet.worker[*].urn,
digitalocean_droplet.nfs.urn
Expand Down Expand Up @@ -167,6 +167,10 @@ resource "digitalocean_droplet" "worker" {
"docker swarm join --token ${data.external.swarm_join_token.result.worker} ${digitalocean_droplet.leader.ipv4_address_private}:2377"
])
}

lifecycle {
create_before_destroy = true
}
}

resource "digitalocean_droplet" "nfs" {
Expand All @@ -191,12 +195,12 @@ resource "digitalocean_droplet" "nfs" {
inline = [
"ufw allow 2049",
"ufw reload",
"sudo apt update",
"sudo apt update",
"sudo apt install -y nfs-kernel-server",
"mkdir -p ${local.mount_nfs}",
"echo '${local.mount_nfs} ${var.subnet_range}(rw,sync,no_root_squash,no_subtree_check)' >> /etc/exports",
"exportfs -arvf",
"systemctl restart nfs-kernel-server",
]
}
}
}
Loading