SuperTux88's Diaspora Saltstack Formula
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

215 lines
6.7KB

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