SuperTux88's Diaspora Saltstack Formula
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

210 lines
6.6KB

  1. {%- from "diaspora/map.jinja" import diaspora with context %}
  2. {%- set environment = diaspora.configuration.server.rails_environment %}
  3. include:
  4. - diaspora.config
  5. {%- if grains.os == 'CentOS' and grains.osmajorrelease >= 8 %}
  6. diaspora_centos_enable_powertools_repo:
  7. file.replace:
  8. - name: /etc/yum.repos.d/CentOS-PowerTools.repo
  9. - pattern: '^enabled=[0,1]'
  10. - repl: 'enabled=1'
  11. - require_in:
  12. - pkg: diaspora_dependencies
  13. {%- endif %}
  14. {%- if grains.os_family == 'Arch' %}
  15. diaspora_arch_install_devel_group:
  16. pkg.group_installed:
  17. - name: base-devel
  18. - require_in:
  19. - pkg: diaspora_dependencies
  20. {%- endif %}
  21. diaspora_dependencies:
  22. pkg.installed:
  23. - pkgs: {{ diaspora.dependencies|json }}
  24. - require:
  25. - pkg: diaspora_database_dependency
  26. diaspora_database_dependency:
  27. pkg.installed:
  28. {%- if diaspora.database.type == "mysql" %}
  29. - name: {{ diaspora.mysql_package }}
  30. {%- else %}
  31. - name: {{ diaspora.postgresql_package }}
  32. {%- endif %}
  33. {%- if diaspora.install_redis %}
  34. redis_package:
  35. pkg.installed:
  36. - name: {{ diaspora.redis_package }}
  37. {%- endif %}
  38. {% set home = diaspora.user.get('home', '/home/' + diaspora.user.username) -%}
  39. diaspora_user:
  40. user.present:
  41. - name: {{ diaspora.user.username }}
  42. {%- if 'shell' in diaspora.user %}
  43. - shell: {{ diaspora.user.shell }}
  44. {%- endif %}
  45. - home: {{ home }}
  46. diaspora_rvm_gpg_key_mpapis:
  47. cmd.run:
  48. - name: gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
  49. - unless: gpg --list-keys 409B6B1796C275462A1703113804BB82D39DC0E3
  50. - runas: {{ diaspora.user.username }}
  51. - require:
  52. - user: diaspora_user
  53. diaspora_rvm_gpg_key_pkuczynski:
  54. cmd.run:
  55. - name: gpg --keyserver hkp://keys.gnupg.net --recv-keys 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
  56. - unless: gpg --list-keys 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
  57. - runas: {{ diaspora.user.username }}
  58. - require:
  59. - user: diaspora_user
  60. diaspora_rvm_ruby:
  61. rvm.installed:
  62. - name: ruby-{{ diaspora.ruby_version }}
  63. - user: {{ diaspora.user.username }}
  64. - default: True
  65. - require:
  66. - pkg: diaspora_dependencies
  67. - cmd: diaspora_rvm_gpg_key_mpapis
  68. - cmd: diaspora_rvm_gpg_key_pkuczynski
  69. diaspora_rvm_gemset:
  70. rvm.gemset_present:
  71. - name: diaspora
  72. - ruby: ruby-{{ diaspora.ruby_version }}
  73. - user: {{ diaspora.user.username }}
  74. - require:
  75. - rvm: diaspora_rvm_ruby
  76. diaspora_install_bundler:
  77. gem.installed:
  78. - name: bundler
  79. - user: {{ diaspora.user.username }}
  80. - ruby: ruby-{{ diaspora.ruby_version }}@diaspora
  81. - require:
  82. - rvm: diaspora_rvm_gemset
  83. diaspora_install_directory:
  84. file.directory:
  85. - name: {{ diaspora.install_path }}
  86. - user: {{ diaspora.user.username }}
  87. - mode: 755
  88. - require:
  89. - user: diaspora_user
  90. diaspora_git:
  91. git.latest:
  92. - name: {{ diaspora.repository }}
  93. - rev: {{ diaspora.version }}
  94. - target: {{ diaspora.install_path }}
  95. - user: {{ diaspora.user.username }}
  96. - force_fetch: True
  97. - require:
  98. - file: diaspora_install_directory
  99. - require_in:
  100. - file: {{ diaspora.install_path }}/config/database.yml
  101. diaspora_rvm_ruby_version_alias:
  102. cmd.run:
  103. - name: rvm alias create $(cat {{ diaspora.install_path }}/.ruby-version) ruby-{{ diaspora.ruby_version }}
  104. - runas: {{ diaspora.user.username }}
  105. - unless: rvm alias list | grep "$(cat {{ diaspora.install_path }}/.ruby-version) => ruby-{{ diaspora.ruby_version }}"
  106. - require:
  107. - rvm: diaspora_rvm_ruby
  108. - git: diaspora_git
  109. diaspora_rails_env_for_login_shell:
  110. file.replace:
  111. {%- if 'shell' in diaspora.user and diaspora.user.shell == "/bin/zsh" %}
  112. - name: {{ home }}/.zshrc
  113. {%- else %}
  114. - name: {{ home }}/.bashrc
  115. {%- endif %}
  116. - pattern: "export RAILS_ENV=\"[a-z]*\""
  117. - repl: "export RAILS_ENV=\"{{ environment }}\""
  118. - append_if_not_found: True
  119. - not_found_content: "\nexport RAILS_ENV=\"{{ environment }}\""
  120. - ignore_if_missing: True
  121. - require:
  122. - rvm: diaspora_rvm_ruby
  123. diaspora_configure_bundler:
  124. cmd.run:
  125. - name: rvm ruby-{{ diaspora.ruby_version }}@diaspora do script/configure_bundler
  126. - runas: {{ diaspora.user.username }}
  127. - cwd: {{ diaspora.install_path }}
  128. - env:
  129. - RAILS_ENV: {{ environment }}
  130. - require:
  131. - gem: diaspora_install_bundler
  132. - cmd: diaspora_rvm_ruby_version_alias
  133. - file: {{ diaspora.install_path }}/config/database.yml
  134. - onchanges:
  135. - git: diaspora_git
  136. diaspora_bundle_install:
  137. cmd.run:
  138. - name: rvm ruby-{{ diaspora.ruby_version }}@diaspora do bin/bundle install --full-index
  139. - runas: {{ diaspora.user.username }}
  140. - cwd: {{ diaspora.install_path }}
  141. - unless: bash -c 'cd {{ diaspora.install_path }}; RAILS_ENV={{ environment }} rvm ruby-{{ diaspora.ruby_version }}@diaspora do bin/bundle check'
  142. - env:
  143. - RAILS_ENV: {{ environment }}
  144. - require:
  145. - cmd: diaspora_configure_bundler
  146. diaspora_create_database:
  147. cmd.run:
  148. - name: rvm ruby-{{ diaspora.ruby_version }}@diaspora do bin/rake db:create db:migrate
  149. - runas: {{ diaspora.user.username }}
  150. - cwd: {{ diaspora.install_path }}
  151. - onlyif: >-
  152. bash -c 'cd {{ diaspora.install_path }}; RAILS_ENV={{ environment }}
  153. rvm ruby-{{ diaspora.ruby_version }}@diaspora do bin/rails runner "ActiveRecord::Base.connection"'
  154. |& grep -E "(Unknown database '{{ diaspora.database.database }}'|database \"{{ diaspora.database.database }}\" does not exist)"
  155. | grep "ActiveRecord::NoDatabaseError"
  156. - env:
  157. - RAILS_ENV: {{ environment }}
  158. - require:
  159. - cmd: diaspora_bundle_install
  160. - file: {{ diaspora.install_path }}/config/database.yml
  161. - file: {{ diaspora.install_path }}/config/diaspora.yml
  162. - onchanges:
  163. - git: diaspora_git
  164. diaspora_migrate_database:
  165. cmd.run:
  166. - name: rvm ruby-{{ diaspora.ruby_version }}@diaspora do bin/rake db:migrate
  167. - runas: {{ diaspora.user.username }}
  168. - cwd: {{ diaspora.install_path }}
  169. - onlyif: >-
  170. bash -c 'cd {{ diaspora.install_path }}; RAILS_ENV={{ environment }}
  171. rvm ruby-{{ diaspora.ruby_version }}@diaspora do bin/rake db:migrate:status' | grep -oE "^\s+down"
  172. - env:
  173. - RAILS_ENV: {{ environment }}
  174. - require:
  175. - cmd: diaspora_create_database
  176. - onchanges:
  177. - git: diaspora_git
  178. diaspora_precompile_assets:
  179. cmd.run:
  180. - name: rvm ruby-{{ diaspora.ruby_version }}@diaspora do bin/rake assets:precompile
  181. - runas: {{ diaspora.user.username }}
  182. - cwd: {{ diaspora.install_path }}
  183. - env:
  184. - RAILS_ENV: {{ environment }}
  185. - require:
  186. - cmd: diaspora_migrate_database
  187. - onchanges:
  188. - git: diaspora_git