Skip to content

Commit

Permalink
terraform for frappe
Browse files Browse the repository at this point in the history
  • Loading branch information
AmrikSD committed Dec 12, 2024
1 parent 1023df6 commit fa83dba
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 8 deletions.
1 change: 1 addition & 0 deletions infra/gcp/00-providers.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ data "sops_file" "gcp-secret" {
provider "google" {
project = "milestone-medical"
credentials = data.sops_file.gcp-secret.data["google.credentials"]
zone = "us-central1-a"
}
96 changes: 91 additions & 5 deletions infra/gcp/01-project.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,112 @@ resource "google_service_account" "frappe" {
display_name = "Custom SA for frappe Instance"
}

resource "google_compute_address" "frappe-static" {
name = "frappe-static"
}

resource "google_compute_instance" "frappe" {
name = "frappe"
machine_type = "e2-small"
zone = "us-central1"

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

boot_disk {
initialize_params {
image = "debian-cloud/debian-12"
}
}

// Local SSD disk
scratch_disk {
interface = "NVME"
metadata = {
ssh-keys = format("%s:%s", data.sops_file.gcp-secret.data["google.ssh.user"], data.sops_file.gcp-secret.data["google.ssh.public_key"])
startup-script = <<-EOT
#!/bin/bash
apt-get update
apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
software-properties-common
curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -
add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable"
apt-get update
apt-get install -y docker-ce docker-compose
systemctl enable --now /home/asbotehg/docker.service
systemctl enable --now /home/asbotehg/docker-compose.app.service
EOT
}



network_interface {
network = "default"
access_config {
nat_ip = google_compute_address.frappe-static.address
}
}

provisioner "file" {
source = "${path.module}/frappe/docker.service"
destination = "docker.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"
}
}

provisioner "file" {
source = "${path.module}/frappe/nginx.conf"
destination = "nginx.conf"
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/docker-compose.app.service"
destination = "docker-compose.app.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"
}
}

provisioner "file" {
source = "${path.module}/frappe/docker-compose.yaml"
destination = "docker-compose.yaml"
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" {
name = "allow-ssh"
network = "default"
allow {
protocol = "tcp"
ports = ["22"]
}
source_ranges = [
"213.78.238.32/32"
]
}
13 changes: 13 additions & 0 deletions infra/gcp/frappe/docker-compose.app.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[Unit]
Description=My Docker Compose Application
Requires=docker.service
After=docker.service

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

[Install]
WantedBy=multi-user.target
9 changes: 9 additions & 0 deletions infra/gcp/frappe/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
services:
webserver:
image: nginx:latest
ports:
- 80:80
- 443:443
restart: always
volumes:
- ./nginx.conf:/etc/nginx/conf.d/nginx.conf:ro
17 changes: 17 additions & 0 deletions infra/gcp/frappe/docker.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target

[Service]
Type=notify
ExecStart=/usr/bin/dockerd
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutStartSec=0
Restart=always
StartLimitBurst=3
StartLimitInterval=60s

[Install]
WantedBy=multi-user.target
15 changes: 15 additions & 0 deletions infra/gcp/frappe/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
server {
listen 80;
listen [::]:80;

server_name amrik.xyz www.amrik.xyz;
server_tokens off;

location /.well-known/acme-challenge/ {
root /var/www/certbot;
}

location / {
return 301 https://amrik.xyz$request_uri;
}
}
8 changes: 6 additions & 2 deletions infra/gcp/gcp.sops.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
google:
project_id: ENC[AES256_GCM,data:wduDriJrbYei6oxWVha+6ng=,iv:ecTwYb+/Vju9G+nk8Oe5mwWSQp6cUrGALcQDCfnn8fE=,tag:uHHWw8b0eR0f6mG6qmbEYg==,type:str]
credentials: ENC[AES256_GCM,data:mK8U07p6scoFz1ri7vi7RFq6b8pUGXetny3kjK8PvGacf1uT/NjQegPuD6wO7c6UJp9dzKhwb9G/gn5G1qcMbMezyurBtRDPOAC9quI06uyKi8S0ivxJUosBDBup75Y7fcM1x95Wpqp0CONTaG2w60uKHsqvg8Hz5avqKOVq9GJB0BvSJl8bKtOoUc2FKSP0r+xzeO0YNB9BNaQTnEOWv+s+Es9lbzAytBuTjIlD5OyhKPZRi1arFHY9G7QRe/0d1wIOCh3q92EqZtsqIseKwZpRZ4iwA1DZewTmx9qgCjiFh8lsIK95w3khTon1epY30yePA/BEwOoT6RaSakEp8kyaU3rmY9X0KODuHE/MetOXjTnEVguvYd/13YIE6MK3QhkTOfTeoFNxJPbwoGl2iebdEubeMvRbMpNO7XunP3MNl+adbjfqluZ7kJqoUuSccoKZDgmmPl8b17tGkTa0qOMQVrtlHkVm6+PW7qhfgZOwGwNTs6m99TRfqMAlgjqQuNtRRiHVUfDnO9OiNQaXosV1+cAvV8+NjMG2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U9L/dPma8HmIVNvqM2Yz2vsdEoK/3hT7ypDRiovV2rW,iv:OJBsHQ5am0rcIWKG2FKHt+IFsvnXS/ToLPPn+S4mVmc=,tag:7mR/XoIfagt6CrYi7fFR9g==,type:str]
public_key: ENC[AES256_GCM,data:o4yQ1pqTPe8cAMWjYECge9A3g+8Xk2+KL1NA6l2Vqx4DLP5Al2p2NNa/uQmsGo3IqHXsM6ytdTHdgBb/XML1pT1V6wSOVPBe5alx1lcozec=,iv:3dK0GB8uvPDmj+Ja+1inALhqA/4o71eZxrvhwLQ4zMo=,tag:tD2ldgT6bj20N27Kb44tOQ==,type:str]
sops:
kms: []
gcp_kms: []
Expand All @@ -16,8 +20,8 @@ sops:
M0RFak9kUE1mNTlVMEM4cFZSZHNqT2sKUZDxGrvUIiITyvCqK1/vQVPHgociBgOj
kLJAczj7Scgd20WvEeNebDUsiqj6SMxdqK/zU0pme1OE9ECeE1dUbA==
-----END AGE ENCRYPTED FILE-----
lastmodified: "2024-12-12T15:04:24Z"
mac: ENC[AES256_GCM,data:PjJ0bsLurkphlSlIYOMY6yKr9fDaKDLryeJPBzv0lbE6s7i52ts8wNE1G1XmRziL1HA2Ez1VejVwYnv3lAbCnEecGI5g4GaujdAFukS21OgwgYpPgdZpclBThoLsA6QhnAz1vFu0I1cPICgtzSo3hn/Vpax35lZIRnfP8o2xQ1Y=,iv:GKdBgtbxmh2nfcpzSHik/zfg2Q9soPqJlzguHqGdZj4=,tag:rd1hMH/+KiAg/XeHKoY8cg==,type:str]
lastmodified: "2024-12-12T19:38:32Z"
mac: ENC[AES256_GCM,data:n25cZqWq571SXM3FNJUDBICKhdYejE1oWj670IL1Xu1SZTMNjmHHxtEcjbvUMA8agBp5y+EHXxhw/99shcrtAYcwtuwRgfRvy97KzU/hfBFV8aZcEM/GtSSYCVCEZZxgypLe2a9izOGl9+2vGSmaq47hsJZT++cYBenR4KJVL4w=,iv:r0NVlGe9NxIQUX9A5B1FDgUJd+iPy0GPe0L/nkKETpQ=,tag:04R7RZCy9c7fZX3V4rOgKQ==,type:str]
pgp: []
unencrypted_suffix: _unencrypted
version: 3.9.1
1 change: 0 additions & 1 deletion infra/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,3 @@ module "truenas" {
}
]
}

0 comments on commit fa83dba

Please sign in to comment.