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.

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