Skip to content

Commit

Permalink
bump instance size, add certificate renewal stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
AmrikSD committed Dec 16, 2024
1 parent 7df2f03 commit 74d168d
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 21 deletions.
27 changes: 26 additions & 1 deletion infra/gcp/01-project.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ resource "google_compute_address" "frappe-static" {

resource "google_compute_instance" "frappe" {
name = "frappe"
machine_type = "e2-small"
machine_type = "e2-medium"

tags = ["https-server", "http-server", "milestone-medical", "terraform"]

Expand Down Expand Up @@ -39,6 +39,8 @@ resource "google_compute_instance" "frappe" {
systemctl enable --now /home/asbotehg/docker.service
systemctl enable --now /home/asbotehg/docker-compose.app.service
systemctl enable --now /home/asbotehg/renew.service
systemctl enable --now /home/asbotehg/renew.timer
EOT
}

Expand Down Expand Up @@ -110,6 +112,29 @@ resource "google_compute_instance" "frappe" {
}
}

provisioner "file" {
source = "${path.module}/frappe/renew.timer"
destination = "renew.timer"
connection {
type = "ssh"
host = self.network_interface[0].access_config[0].nat_ip
user = data.sops_file.gcp-secret.data["google.ssh.user"]
private_key = data.sops_file.gcp-secret.data["google.ssh.private_key"]
timeout = "4m"
}
}
provisioner "file" {
source = "${path.module}/frappe/renew.service"
destination = "renew.service"
connection {
type = "ssh"
host = self.network_interface[0].access_config[0].nat_ip
user = data.sops_file.gcp-secret.data["google.ssh.user"]
private_key = data.sops_file.gcp-secret.data["google.ssh.private_key"]
timeout = "4m"
}
}

}

resource "google_compute_firewall" "default-ssh" {
Expand Down
33 changes: 33 additions & 0 deletions infra/gcp/frappe/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Restoring backups

First, get the backup from s3, or r2, or wherever you put it.


SCP the files onto the box.
```bash
scp 20241214_131900_20241214_131900* <url>:~/backups/
```

SSH onto to box.
```bash
ssh <url>.xyz
```

Get a shell on a container with "bench" running
```bash
cd ~/backups
docker compose run -it -v $(pwd):/backup frontend sh

whoami
#this should return frappe, just doulbe check ur actually in the container...
```

Run the restore command
```bash
bench restore /backup/20241214_131900_20241214_131900-frontend-database.sql.gz --with-public-files /backup/20241214_131900_20241214_131900-frontend-files.tar --with-private-files
/backup/20241214_131900_20241214_131900-frontend-private-files.tar
```

> [!NOTE]
> This last command may look like it hangs, give it some time.
20 changes: 0 additions & 20 deletions infra/gcp/frappe/docker-compose.yaml.old

This file was deleted.

13 changes: 13 additions & 0 deletions infra/gcp/frappe/renew.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[Unit]
Description=Runs the renew script
Requires=docker-compose.app.service
After=docker-compose.app.service

[Service]
WorkingDirectory=/home/asbotehg
ExecStart=/usr/bin/docker-compose run certbot renew
Restart=on-failure # Restart only on errors, not clean exits
TimeoutStartSec=0

[Install]
WantedBy=multi-user.target
10 changes: 10 additions & 0 deletions infra/gcp/frappe/renew.timer
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[Unit]
Description="Run renew.service every 24hours"

[Timer]
OnUnitActiveSec=24h
OnCalendar=Mon..Sun *-*-* 10:00:*
Unit=renew.service

[Install]
WantedBy=multi-user.target

0 comments on commit 74d168d

Please sign in to comment.