commit 68f8cad35403437b6199fc91ec6a7d208bb5ab12 Author: Brandon Rozek Date: Sat May 9 10:30:13 2020 -0400 Minetest Deployment diff --git a/config b/config new file mode 100644 index 0000000..f1a58e2 --- /dev/null +++ b/config @@ -0,0 +1,10 @@ +base_system_image = "ubuntu-20-04-x64" +region = "nyc3" +size = "512mb" +domain = "brandonrozek.com" +subdomain = "minetest" + +# Secrets +do_token = "DO-TOKEN-HERE" +key_name = "SSH-NAME-ON-DO-HERE" + diff --git a/packer/do.pkr.hcl b/packer/do.pkr.hcl new file mode 100644 index 0000000..cf9a24f --- /dev/null +++ b/packer/do.pkr.hcl @@ -0,0 +1,29 @@ +source "digitalocean" "web" { + api_token = var.do_token + image = var.base_system_image + region = var.region + size = var.size + ssh_username = "root" + snapshot_name = "packer-docker" +} + + +build { + sources = [ + "source.digitalocean.web", + ] + + provisioner "file" { + source = "docker-compose.yml" + destination = "/root/docker-compose.yml" + } + + provisioner "file" { + source = "docker-compose.service" + destination = "/etc/systemd/system/docker-compose.service" + } + + provisioner "shell" { + scripts = [ "setup.sh" ] + } +} diff --git a/packer/docker-compose.service b/packer/docker-compose.service new file mode 100644 index 0000000..194279c --- /dev/null +++ b/packer/docker-compose.service @@ -0,0 +1,16 @@ +[Unit] +Description=Docker Compose Application Service +Requires=docker.service +After=docker.service + +[Service] +Type=oneshot +RemainAfterExit=yes +WorkingDirectory=/root +ExecStart=/usr/bin/docker-compose up -d +ExecStop=/usr/bin/docker-compose down +TimeoutStartSec=0 + +[Install] +WantedBy=multi-user.target + diff --git a/packer/docker-compose.yml b/packer/docker-compose.yml new file mode 100644 index 0000000..b87dadc --- /dev/null +++ b/packer/docker-compose.yml @@ -0,0 +1,14 @@ +version: "2.1" +services: + minetest: + image: linuxserver/minetest + container_name: minetest + environment: + - PUID=1000 + - PGID=1000 + - TZ=US/Eastern + volumes: + - /volumes/minetest/config/.minetest:/config/.minetest + ports: + - 30000:30000/udp + restart: unless-stopped diff --git a/packer/setup.sh b/packer/setup.sh new file mode 100755 index 0000000..2938ef2 --- /dev/null +++ b/packer/setup.sh @@ -0,0 +1,13 @@ +#!/bin/bash +apt update +apt upgrade -y + +apt install -y docker.io docker-compose +systemctl enable docker-compose +systemctl start docker-compose + +ufw allow OpenSSH +# Add any firewall rules you need +# for your application here +ufw allow 30000/udp +ufw --force enable diff --git a/packer/variables.auto.pkrvars.hcl b/packer/variables.auto.pkrvars.hcl new file mode 120000 index 0000000..3ca249e --- /dev/null +++ b/packer/variables.auto.pkrvars.hcl @@ -0,0 +1 @@ +../config \ No newline at end of file diff --git a/packer/variables.pkr.hcl b/packer/variables.pkr.hcl new file mode 120000 index 0000000..942f09d --- /dev/null +++ b/packer/variables.pkr.hcl @@ -0,0 +1 @@ +../variables.hcl \ No newline at end of file diff --git a/terraform/do.tf b/terraform/do.tf new file mode 100644 index 0000000..8f244ca --- /dev/null +++ b/terraform/do.tf @@ -0,0 +1,38 @@ +provider "digitalocean" { + token = var.do_token +} + +data "digitalocean_ssh_key" laptop { + name = var.key_name +} + +data "digitalocean_droplet_snapshot" "packer_snapshot" { + name = "packer-docker" + most_recent = true +} + +# Create a droplet +resource "digitalocean_droplet" "web" { + name = "tf-1" + image = data.digitalocean_droplet_snapshot.packer_snapshot.id + region = var.region + size = var.size + ssh_keys = [data.digitalocean_ssh_key.laptop.id] + backups = false +} + +# Attach a subdomain +resource "digitalocean_record" "www" { + domain = var.domain + type = "A" + name = var.subdomain + value = digitalocean_droplet.web.ipv4_address +} + +output "ip" { + value = digitalocean_droplet.web.ipv4_address +} + +output "domain" { + value = "${digitalocean_record.www.name}.${digitalocean_record.www.domain}" +} diff --git a/terraform/terraform.tfvars b/terraform/terraform.tfvars new file mode 120000 index 0000000..3ca249e --- /dev/null +++ b/terraform/terraform.tfvars @@ -0,0 +1 @@ +../config \ No newline at end of file diff --git a/terraform/variables.tf b/terraform/variables.tf new file mode 120000 index 0000000..942f09d --- /dev/null +++ b/terraform/variables.tf @@ -0,0 +1 @@ +../variables.hcl \ No newline at end of file diff --git a/variables.hcl b/variables.hcl new file mode 100644 index 0000000..d5fb233 --- /dev/null +++ b/variables.hcl @@ -0,0 +1,29 @@ +variable "do_token" { + type = string +} + +variable "base_system_image" { + type = string +} + +variable "domain" { + type = string +} + +variable "key_name" { + type = string +} + +variable "subdomain" { + type = string +} + +variable "region" { + type = string +} + +variable "size" { + type = string +} + +