cloud-init_firezone.tpl.yaml 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #cloud-config
  2. users:
  3. - name: ${firezone_vm_username}
  4. sudo: ALL=(ALL) NOPASSWD:ALL
  5. shell: /bin/bash
  6. ssh-authorized-keys:
  7. - "${firezone_ssh_key_pub}"
  8. write_files:
  9. - path: "/home/${firezone_vm_username}/.firezone/docker-compose.yml"
  10. permissions: "0600"
  11. content: |
  12. # Example compose file for production deployment on Linux.
  13. #
  14. # Note: This file is meant to serve as a template. Please modify it
  15. # according to your needs. Read more about Docker Compose:
  16. #
  17. # https://docs.docker.com/compose/compose-file/
  18. #
  19. #
  20. x-deploy: &default-deploy
  21. restart_policy:
  22. condition: unless-stopped
  23. delay: 5s
  24. window: 120s
  25. update_config:
  26. order: start-first
  27. version: '3.7'
  28. services:
  29. caddy:
  30. image: caddy:2
  31. volumes:
  32. - $${FZ_INSTALL_DIR:-.}/caddy:/data/caddy
  33. # See Caddy's documentation for customizing this line
  34. # https://caddyserver.com/docs/quick-starts/reverse-proxy
  35. command:
  36. - /bin/sh
  37. - -c
  38. - |
  39. cat <<EOF > /etc/caddy/Caddyfile && caddy run --config /etc/caddy/Caddyfile
  40. $${EXTERNAL_URL} {
  41. log
  42. reverse_proxy * 172.25.0.100:$${PHOENIX_PORT:-13000}
  43. }
  44. EOF
  45. network_mode: "host"
  46. deploy:
  47. <<: *default-deploy
  48. firezone:
  49. image: firezone/firezone:$${VERSION:-latest}
  50. ports:
  51. - $${WIREGUARD_PORT:-51820}:$${WIREGUARD_PORT:-51820}/udp
  52. env_file:
  53. # This should contain a list of env vars for configuring Firezone.
  54. # See https://www.firezone.dev/docs/reference/env-vars for more info.
  55. - $${FZ_INSTALL_DIR:-.}/.env
  56. volumes:
  57. # IMPORTANT: Persists WireGuard private key and other data. If
  58. # /var/firezone/private_key exists when Firezone starts, it is
  59. # used as the WireGuard private. Otherwise, one is generated.
  60. - $${FZ_INSTALL_DIR:-.}/firezone:/var/firezone
  61. cap_add:
  62. # Needed for WireGuard and firewall support.
  63. - NET_ADMIN
  64. - SYS_MODULE
  65. sysctls:
  66. # Needed for masquerading and NAT.
  67. - net.ipv6.conf.all.disable_ipv6=0
  68. - net.ipv4.ip_forward=1
  69. - net.ipv6.conf.all.forwarding=1
  70. networks:
  71. firezone-network:
  72. ipv4_address: 172.25.0.100
  73. ipv6_address: 2001:3990:3990::99
  74. deploy:
  75. <<: *default-deploy
  76. networks:
  77. firezone-network:
  78. enable_ipv6: true
  79. driver: bridge
  80. ipam:
  81. config:
  82. - subnet: 172.25.0.0/16
  83. - subnet: 2001:3990:3990::/64
  84. gateway: 2001:3990:3990::1
  85. - path: "/home/${firezone_vm_username}/.firezone/init.sh"
  86. permissions: "0740"
  87. content: |
  88. #!/bin/bash
  89. usermod -a -G docker ${firezone_vm_username}
  90. installDir="/home/${firezone_vm_username}/.firezone"
  91. dc="docker-compose"
  92. export FZ_INSTALL_DIR=$installDir
  93. tlsOpts="tls {
  94. on_demand
  95. }"
  96. docker run --rm firezone/firezone bin/gen-env > "$installDir/.env"
  97. sed -i.bak "s/DEFAULT_ADMIN_EMAIL=.*/DEFAULT_ADMIN_EMAIL=${firezone_admin_email}/" "$installDir/.env"
  98. sed -i.bak "s~EXTERNAL_URL=.*~EXTERNAL_URL=${firezone_url}~" "$installDir/.env"
  99. sed -i.bak "s/DEFAULT_ADMIN_PASSWORD=.*/DEFAULT_ADMIN_PASSWORD=${firezone_admin_password}/" "$installDir/.env"
  100. sed -i.bak "s/VERSION=.*/VERSION=${version}/" "$installDir/.env"
  101. echo "TELEMETRY_ENABLED=false" >> "$installDir/.env"
  102. echo "DATABASE_HOST=${db_host}" >> "$installDir/.env"
  103. echo "DATABASE_PORT=6432" >> "$installDir/.env"
  104. echo "DATABASE_NAME=${db_name}" >> "$installDir/.env"
  105. echo "DATABASE_USER=${db_user}" >> "$installDir/.env"
  106. sed -i.bak "s/DATABASE_PASSWORD=.*/DATABASE_PASSWORD=${db_pass}/" "$installDir/.env"
  107. echo "DATABASE_POOL_SIZE=10" >> "$installDir/.env"
  108. echo "DATABASE_SSL_ENABLED=false" >> "$installDir/.env"
  109. echo "WIREGUARD_PORT=${wg_port}" >> "$installDir/.env"
  110. echo "Migrating DB..."
  111. $dc -f $installDir/docker-compose.yml run -e --rm firezone bin/migrate
  112. echo "Creating admin..."
  113. $dc -f $installDir/docker-compose.yml run -e --rm firezone bin/create-or-reset-admin
  114. echo "Upping firezone services..."
  115. $dc -f $installDir/docker-compose.yml up -d firezone caddy
  116. runcmd:
  117. - sleep 1
  118. - sudo -i
  119. - /home/${firezone_vm_username}/.firezone/init.sh