|
- # gitea is a PITA to automate installation of, watch this pr for when it'll be
- # fully setup-able from the cli https://github.com/go-gitea/gitea/issues/9210
- variable "gitea_db_passwd" {
- type = string
- }
-
- resource "null_resource" "functionalidiot_com_setup_new_gitea" {
- depends_on = [ null_resource.gitea_install ]
- count = fileexists("${path.module}/attic/gitea.txz") ? 0 : 1
- connection {
- host = linode_instance.prod.ip_address
- user = "root"
- private_key = file("~/.ssh/id_rsa")
- }
- provisioner "file" {
- source = "setup_gitea.sh"
- destination = "/tmp/setup_gitea.sh"
- }
- provisioner "remote-exec" {
- inline = [<<FIN
- install -m755 /tmp/setup_gitea.sh /usr/local/bin/setup_gitea
-
- rm -f /tmp/setup_gitea.sh
-
- rc-update add gitea default
-
- skey=$(su - gitea -c "gitea generate secret SECRET_KEY")
- itoken=$(su - gitea -c "gitea generate secret INTERNAL_TOKEN")
-
- SECRET_KEY=$skey INTERNAL_TOKEN=$itoken /usr/local/bin/setup_gitea
-
- rc-service gitea restart
-
- sleep 3
-
- chown gitea:www-data /var/lib/gitea/db/gitea.db
-
- su - gitea -c "gitea migrate --config /etc/gitea/app.ini"
-
- su - gitea -c "gitea admin create-user --username mitchty --password ${var.gitea_db_passwd} --email git@functionalidiot.com --admin --config /etc/gitea/app.ini"
- FIN
- ]
- }
- }
-
- resource "null_resource" "functionalidiot_com_setup_saved_gitea" {
- depends_on = [ null_resource.gitea_install ]
- count = fileexists("${path.module}/attic/gitea.txz") ? 1 : 0
- connection {
- host = linode_instance.prod.ip_address
- user = "root"
- private_key = file("~/.ssh/id_rsa")
- }
- provisioner "file" {
- source = "${path.module}/attic/gitea.txz"
- destination = "/tmp/gitea.txz"
- }
- # TODO: Finish post untar setup
- provisioner "remote-exec" {
- inline = [<<FIN
- cd /
- tar xvJf /tmp/gitea.txz
- rc-update add gitea default
- rc-service gitea restart
- FIN
- ]
- }
- }
-
- resource "null_resource" "functionalidiot_com_setup_saved_uacme" {
- depends_on = [ null_resource.uacme_install ]
- count = fileexists("${path.module}/attic/uacme.txz") ? 1 : 0
- connection {
- host = linode_instance.prod.ip_address
- user = "root"
- private_key = file("~/.ssh/id_rsa")
- }
- provisioner "file" {
- source = "${path.module}/attic/uacme.txz"
- destination = "/tmp/uacme.txz"
- }
- # TODO: Finish post untar setup
- provisioner "remote-exec" {
- inline = [<<FIN
- cd /
- tar xvJf /tmp/uacme.txz
- FIN
- ]
- }
- }
-
- # FIXME: This nginx setup isn't idempotent if its a new setup vs saved
- # uacme ssl setup.
- #
- # Maybe use the dns uacme crap instead of this stupid http bs?
- #
- # https://www.terraform.io/docs/providers/acme/r/certificate.html
- # https://www.terraform.io/docs/providers/acme/dns_providers/cloudflare.html
- resource "null_resource" "functionalidiot_com_setup_new_nginx" {
- depends_on = [
- null_resource.nginx_install,
- null_resource.functionalidiot_com_setup_new_gitea,
- null_resource.functionalidiot_com_setup_saved_gitea,
- null_resource.functionalidiot_com_setup_saved_uacme,
- null_resource.functionalidiot_com_setup_saved_uacme
- ]
- connection {
- host = linode_instance.prod.ip_address
- user = "root"
- private_key = file("~/.ssh/id_rsa")
- }
- provisioner "file" {
- source = "http-default.conf"
- destination = "/tmp/http-default.conf"
- }
- provisioner "file" {
- source = "https-functionalidiot.com.conf"
- destination = "/tmp/https-functionalidiot.com.conf"
- }
- provisioner "remote-exec" {
- inline = [<<FIN
- [ -e /etc/nginx/conf.d/default.conf ] && mv /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.disable
- install -m644 /tmp/http-default.conf /etc/nginx/conf.d/http-default.conf
- install -m644 /tmp/https-functionalidiot.com.conf /etc/nginx/conf.d/https-functionalidiot.com.conf
- rm -fr /tmp/*.conf
-
- install -dm755 /var/www/default/htdocs /var/www/.well-known/acme-challenge
- echo todo write more stuff > /var/www/default/htdocs/index.html
-
- rc-service nginx restart
- FIN
- ]
- }
- }
|