SuperTux88's Diaspora Saltstack Formula
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

195 行
6.1KB

  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_git:
  78. git.latest:
  79. - name: {{ diaspora.repository }}
  80. - rev: {{ diaspora.version }}
  81. - target: {{ diaspora.install_path }}
  82. - user: {{ diaspora.user.username }}
  83. - force_fetch: True
  84. - require:
  85. - file: diaspora_install_directory
  86. - require_in:
  87. - file: {{ diaspora.install_path }}/config/database.yml
  88. diaspora_rvm_ruby_version_alias:
  89. cmd.run:
  90. - name: rvm alias create $(cat {{ diaspora.install_path }}/.ruby-version) ruby-{{ diaspora.ruby_version }}
  91. - runas: {{ diaspora.user.username }}
  92. - unless: rvm alias list | grep "$(cat {{ diaspora.install_path }}/.ruby-version) => ruby-{{ diaspora.ruby_version }}"
  93. - require:
  94. - rvm: diaspora_rvm_ruby
  95. - git: diaspora_git
  96. diaspora_rails_env_for_login_shell:
  97. file.replace:
  98. {%- if 'shell' in diaspora.user and diaspora.user.shell == "/bin/zsh" %}
  99. - name: {{ home }}/.zshrc
  100. {%- else %}
  101. - name: {{ home }}/.bashrc
  102. {%- endif %}
  103. - pattern: "export RAILS_ENV=\"[a-z]*\""
  104. - repl: "export RAILS_ENV=\"{{ environment }}\""
  105. - append_if_not_found: True
  106. - not_found_content: "\nexport RAILS_ENV=\"{{ environment }}\""
  107. - ignore_if_missing: True
  108. - require:
  109. - rvm: diaspora_rvm_ruby
  110. diaspora_configure_bundler:
  111. cmd.run:
  112. - name: rvm ruby-{{ diaspora.ruby_version }}@diaspora do script/configure_bundler
  113. - runas: {{ diaspora.user.username }}
  114. - cwd: {{ diaspora.install_path }}
  115. - env:
  116. - RAILS_ENV: {{ environment }}
  117. - require:
  118. - gem: diaspora_install_bundler
  119. - cmd: diaspora_rvm_ruby_version_alias
  120. - file: {{ diaspora.install_path }}/config/database.yml
  121. - onchanges:
  122. - git: diaspora_git
  123. diaspora_bundle_install:
  124. cmd.run:
  125. - name: rvm ruby-{{ diaspora.ruby_version }}@diaspora do bin/bundle install --full-index
  126. - runas: {{ diaspora.user.username }}
  127. - cwd: {{ diaspora.install_path }}
  128. - unless: bash -c 'cd {{ diaspora.install_path }}; RAILS_ENV={{ environment }} rvm ruby-{{ diaspora.ruby_version }}@diaspora do bin/bundle check'
  129. - env:
  130. - RAILS_ENV: {{ environment }}
  131. - require:
  132. - cmd: diaspora_configure_bundler
  133. diaspora_create_database:
  134. cmd.run:
  135. - name: rvm ruby-{{ diaspora.ruby_version }}@diaspora do bin/rake db:create db:migrate
  136. - runas: {{ diaspora.user.username }}
  137. - cwd: {{ diaspora.install_path }}
  138. - onlyif: >-
  139. bash -c 'cd {{ diaspora.install_path }}; RAILS_ENV={{ environment }}
  140. rvm ruby-{{ diaspora.ruby_version }}@diaspora do bin/rails runner "ActiveRecord::Base.connection"
  141. |& grep "database \"{{ diaspora.database.database }}\" does not exist (ActiveRecord::NoDatabaseError)"'
  142. - env:
  143. - RAILS_ENV: {{ environment }}
  144. - require:
  145. - cmd: diaspora_bundle_install
  146. - file: {{ diaspora.install_path }}/config/database.yml
  147. - file: {{ diaspora.install_path }}/config/diaspora.yml
  148. - onchanges:
  149. - git: diaspora_git
  150. diaspora_migrate_database:
  151. cmd.run:
  152. - name: rvm ruby-{{ diaspora.ruby_version }}@diaspora do bin/rake 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/rake db:migrate:status | grep -oE "^\s+down"'
  158. - env:
  159. - RAILS_ENV: {{ environment }}
  160. - require:
  161. - cmd: diaspora_create_database
  162. - onchanges:
  163. - git: diaspora_git
  164. diaspora_precompile_assets:
  165. cmd.run:
  166. - name: rvm ruby-{{ diaspora.ruby_version }}@diaspora do bin/rake assets:precompile
  167. - runas: {{ diaspora.user.username }}
  168. - cwd: {{ diaspora.install_path }}
  169. - env:
  170. - RAILS_ENV: {{ environment }}
  171. - require:
  172. - cmd: diaspora_migrate_database
  173. - onchanges:
  174. - git: diaspora_git