SuperTux88's Diaspora Saltstack Formula
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

198 rindas
6.2KB

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