marketplace-image.pkr.hcl 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. packer {
  2. required_plugins {
  3. digitalocean = {
  4. version = ">= 1.2.0"
  5. source = "github.com/digitalocean/digitalocean"
  6. }
  7. }
  8. }
  9. variable "digitalocean_token" {
  10. default = "${env("DIGITALOCEAN_TOKEN")}"
  11. type = string
  12. }
  13. variable "image_name" {
  14. default = ""
  15. type = string
  16. }
  17. locals {
  18. timestamp = regex_replace(timestamp(), "[- TZ:]", "")
  19. image_name = var.image_name == "" ? "mastodon-digitalocean-${local.timestamp}" : var.image_name
  20. }
  21. source "digitalocean" "debian" {
  22. api_token = var.digitalocean_token
  23. image = "debian-12-x64"
  24. region = "nyc3"
  25. size = "s-1vcpu-2gb"
  26. snapshot_name = local.image_name
  27. ssh_username = "root"
  28. }
  29. build {
  30. sources = ["source.digitalocean.debian"]
  31. provisioner "shell" {
  32. scripts = ["scripts/01-prepare.sh"]
  33. }
  34. provisioner "shell" {
  35. execute_command = "chmod +x {{ .Path }}; su -c '{{ .Vars }} {{ .Path }}' - mastodon"
  36. scripts = ["scripts/02-install.sh"]
  37. }
  38. provisioner "file" {
  39. destination = "/etc/"
  40. source = "files/etc/"
  41. }
  42. provisioner "file" {
  43. destination = "/var/"
  44. source = "files/var/"
  45. }
  46. provisioner "file" {
  47. destination = "/opt/"
  48. source = "files/opt/"
  49. }
  50. provisioner "file" {
  51. destination = "/home/"
  52. source = "files/home/"
  53. }
  54. provisioner "shell" {
  55. scripts = ["scripts/03-finalize.sh"]
  56. }
  57. provisioner "shell" {
  58. scripts = [
  59. "scripts/90-cleanup.sh",
  60. "scripts/99-img_check.sh"
  61. ]
  62. }
  63. }