Automation and setup for sites I own.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 

135 lignes
3.9 KiB

  1. # gitea is a PITA to automate installation of, watch this pr for when it'll be
  2. # fully setup-able from the cli https://github.com/go-gitea/gitea/issues/9210
  3. variable "gitea_db_passwd" {
  4. type = string
  5. }
  6. resource "null_resource" "functionalidiot_com_setup_new_gitea" {
  7. depends_on = [ null_resource.gitea_install ]
  8. count = fileexists("${path.module}/attic/gitea.txz") ? 0 : 1
  9. connection {
  10. host = linode_instance.prod.ip_address
  11. user = "root"
  12. private_key = file("~/.ssh/id_rsa")
  13. }
  14. provisioner "file" {
  15. source = "setup_gitea.sh"
  16. destination = "/tmp/setup_gitea.sh"
  17. }
  18. provisioner "remote-exec" {
  19. inline = [<<FIN
  20. install -m755 /tmp/setup_gitea.sh /usr/local/bin/setup_gitea
  21. rm -f /tmp/setup_gitea.sh
  22. rc-update add gitea default
  23. skey=$(su - gitea -c "gitea generate secret SECRET_KEY")
  24. itoken=$(su - gitea -c "gitea generate secret INTERNAL_TOKEN")
  25. SECRET_KEY=$skey INTERNAL_TOKEN=$itoken /usr/local/bin/setup_gitea
  26. rc-service gitea restart
  27. sleep 3
  28. chown gitea:www-data /var/lib/gitea/db/gitea.db
  29. su - gitea -c "gitea migrate --config /etc/gitea/app.ini"
  30. su - gitea -c "gitea admin create-user --username mitchty --password ${var.gitea_db_passwd} --email git@functionalidiot.com --admin --config /etc/gitea/app.ini"
  31. FIN
  32. ]
  33. }
  34. }
  35. resource "null_resource" "functionalidiot_com_setup_saved_gitea" {
  36. depends_on = [ null_resource.gitea_install ]
  37. count = fileexists("${path.module}/attic/gitea.txz") ? 1 : 0
  38. connection {
  39. host = linode_instance.prod.ip_address
  40. user = "root"
  41. private_key = file("~/.ssh/id_rsa")
  42. }
  43. provisioner "file" {
  44. source = "${path.module}/attic/gitea.txz"
  45. destination = "/tmp/gitea.txz"
  46. }
  47. # TODO: Finish post untar setup
  48. provisioner "remote-exec" {
  49. inline = [<<FIN
  50. cd /
  51. tar xvJf /tmp/gitea.txz
  52. rc-update add gitea default
  53. rc-service gitea restart
  54. FIN
  55. ]
  56. }
  57. }
  58. resource "null_resource" "functionalidiot_com_setup_saved_uacme" {
  59. depends_on = [ null_resource.uacme_install ]
  60. count = fileexists("${path.module}/attic/uacme.txz") ? 1 : 0
  61. connection {
  62. host = linode_instance.prod.ip_address
  63. user = "root"
  64. private_key = file("~/.ssh/id_rsa")
  65. }
  66. provisioner "file" {
  67. source = "${path.module}/attic/uacme.txz"
  68. destination = "/tmp/uacme.txz"
  69. }
  70. # TODO: Finish post untar setup
  71. provisioner "remote-exec" {
  72. inline = [<<FIN
  73. cd /
  74. tar xvJf /tmp/uacme.txz
  75. FIN
  76. ]
  77. }
  78. }
  79. # FIXME: This nginx setup isn't idempotent if its a new setup vs saved
  80. # uacme ssl setup.
  81. #
  82. # Maybe use the dns uacme crap instead of this stupid http bs?
  83. #
  84. # https://www.terraform.io/docs/providers/acme/r/certificate.html
  85. # https://www.terraform.io/docs/providers/acme/dns_providers/cloudflare.html
  86. resource "null_resource" "functionalidiot_com_setup_new_nginx" {
  87. depends_on = [
  88. null_resource.nginx_install,
  89. null_resource.functionalidiot_com_setup_new_gitea,
  90. null_resource.functionalidiot_com_setup_saved_gitea,
  91. null_resource.functionalidiot_com_setup_saved_uacme,
  92. null_resource.functionalidiot_com_setup_saved_uacme
  93. ]
  94. connection {
  95. host = linode_instance.prod.ip_address
  96. user = "root"
  97. private_key = file("~/.ssh/id_rsa")
  98. }
  99. provisioner "file" {
  100. source = "http-default.conf"
  101. destination = "/tmp/http-default.conf"
  102. }
  103. provisioner "file" {
  104. source = "https-functionalidiot.com.conf"
  105. destination = "/tmp/https-functionalidiot.com.conf"
  106. }
  107. provisioner "remote-exec" {
  108. inline = [<<FIN
  109. [ -e /etc/nginx/conf.d/default.conf ] && mv /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.disable
  110. install -m644 /tmp/http-default.conf /etc/nginx/conf.d/http-default.conf
  111. install -m644 /tmp/https-functionalidiot.com.conf /etc/nginx/conf.d/https-functionalidiot.com.conf
  112. rm -fr /tmp/*.conf
  113. install -dm755 /var/www/default/htdocs /var/www/.well-known/acme-challenge
  114. echo todo write more stuff > /var/www/default/htdocs/index.html
  115. rc-service nginx restart
  116. FIN
  117. ]
  118. }
  119. }