SuperTux88's Diaspora Saltstack Formula
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

189 Zeilen
5.9KB

  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:
  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_ruby:
  41. rvm.installed:
  42. - name: ruby-{{ diaspora.ruby_version }}
  43. - user: {{ diaspora.user.username }}
  44. - default: True
  45. - require:
  46. - pkg: diaspora_dependencies
  47. - cmd: diaspora_rvm_gpg_key
  48. diaspora_rvm_gemset:
  49. rvm.gemset_present:
  50. - name: diaspora
  51. - ruby: ruby-{{ diaspora.ruby_version }}
  52. - user: {{ diaspora.user.username }}
  53. - require:
  54. - rvm: diaspora_rvm_ruby
  55. diaspora_install_bundler:
  56. gem.installed:
  57. - name: bundler
  58. - user: {{ diaspora.user.username }}
  59. - ruby: ruby-{{ diaspora.ruby_version }}@diaspora
  60. - require:
  61. - rvm: diaspora_rvm_gemset
  62. diaspora_install_directory:
  63. file.directory:
  64. - name: {{ diaspora.install_path }}
  65. - user: {{ diaspora.user.username }}
  66. - mode: 755
  67. - require:
  68. - user: diaspora_user
  69. diaspora_reset_schema.rb:
  70. cmd.run:
  71. - name: git checkout db/schema.rb
  72. - runas: {{ diaspora.user.username }}
  73. - cwd: {{ diaspora.install_path }}
  74. - onlyif: git ls-files --error-unmatch db/schema.rb && git rev-parse && ! git diff --name-only --exit-code db/schema.rb
  75. diaspora_git:
  76. git.latest:
  77. - name: {{ diaspora.repository }}
  78. - rev: {{ diaspora.version }}
  79. - target: {{ diaspora.install_path }}
  80. - user: {{ diaspora.user.username }}
  81. - force_fetch: True
  82. - require:
  83. - file: diaspora_install_directory
  84. - cmd: diaspora_reset_schema.rb
  85. - require_in:
  86. - file: {{ diaspora.install_path }}/config/database.yml
  87. diaspora_rvm_ruby_version_alias:
  88. cmd.run:
  89. - name: rvm alias create $(cat {{ diaspora.install_path }}/.ruby-version) ruby-{{ diaspora.ruby_version }}
  90. - runas: {{ diaspora.user.username }}
  91. - unless: rvm alias list | grep "$(cat {{ diaspora.install_path }}/.ruby-version) => ruby-{{ diaspora.ruby_version }}"
  92. - require:
  93. - rvm: diaspora_rvm_ruby
  94. - git: diaspora_git
  95. diaspora_rails_env_for_login_shell:
  96. file.replace:
  97. {%- if 'shell' in diaspora.user and diaspora.user.shell == "/bin/zsh" %}
  98. - name: {{ home }}/.zshrc
  99. {%- else %}
  100. - name: {{ home }}/.bashrc
  101. {%- endif %}
  102. - pattern: "export RAILS_ENV=\"[a-z]*\""
  103. - repl: "export RAILS_ENV=\"{{ environment }}\""
  104. - append_if_not_found: True
  105. - not_found_content: "\nexport RAILS_ENV=\"{{ environment }}\""
  106. - ignore_if_missing: True
  107. - require:
  108. - rvm: diaspora_rvm_ruby
  109. diaspora_configure_bundler:
  110. cmd.run:
  111. - name: rvm ruby-{{ diaspora.ruby_version }}@diaspora do script/configure_bundler
  112. - runas: {{ diaspora.user.username }}
  113. - cwd: {{ diaspora.install_path }}
  114. - env:
  115. - RAILS_ENV: {{ environment }}
  116. - require:
  117. - gem: diaspora_install_bundler
  118. - cmd: diaspora_rvm_ruby_version_alias
  119. - file: {{ diaspora.install_path }}/config/database.yml
  120. - onchanges:
  121. - git: diaspora_git
  122. diaspora_bundle_install:
  123. cmd.run:
  124. - name: rvm ruby-{{ diaspora.ruby_version }}@diaspora do bin/bundle install --full-index
  125. - runas: {{ diaspora.user.username }}
  126. - cwd: {{ diaspora.install_path }}
  127. - unless: rvm ruby-{{ diaspora.ruby_version }}@diaspora do bin/bundle check
  128. - env:
  129. - RAILS_ENV: {{ environment }}
  130. - require:
  131. - cmd: diaspora_configure_bundler
  132. diaspora_create_database:
  133. cmd.run:
  134. - name: rvm ruby-{{ diaspora.ruby_version }}@diaspora do bin/rake db:create db:migrate
  135. - runas: {{ diaspora.user.username }}
  136. - cwd: {{ diaspora.install_path }}
  137. - onlyif: rvm ruby-{{ diaspora.ruby_version }}@diaspora do bin/rails runner "ActiveRecord::Base.connection" |& grep "database \"{{ diaspora.database.database }}\" does not exist (ActiveRecord::NoDatabaseError)"
  138. - env:
  139. - RAILS_ENV: {{ environment }}
  140. - require:
  141. - cmd: diaspora_bundle_install
  142. - file: {{ diaspora.install_path }}/config/database.yml
  143. - file: {{ diaspora.install_path }}/config/diaspora.yml
  144. - onchanges:
  145. - git: diaspora_git
  146. diaspora_migrate_database:
  147. cmd.run:
  148. - name: rvm ruby-{{ diaspora.ruby_version }}@diaspora do bin/rake db:migrate
  149. - runas: {{ diaspora.user.username }}
  150. - cwd: {{ diaspora.install_path }}
  151. - onlyif: rvm ruby-{{ diaspora.ruby_version }}@diaspora do bin/rake db:migrate:status | grep -oE "^\s+down"
  152. - env:
  153. - RAILS_ENV: {{ environment }}
  154. - require:
  155. - cmd: diaspora_create_database
  156. - onchanges:
  157. - git: diaspora_git
  158. diaspora_precompile_assets:
  159. cmd.run:
  160. - name: rvm ruby-{{ diaspora.ruby_version }}@diaspora do bin/rake assets:precompile
  161. - runas: {{ diaspora.user.username }}
  162. - cwd: {{ diaspora.install_path }}
  163. - env:
  164. - RAILS_ENV: {{ environment }}
  165. - require:
  166. - cmd: diaspora_migrate_database
  167. - onchanges:
  168. - git: diaspora_git