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

168 lines
5.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.home if 'home' in diaspora.user else '/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_git:
  70. git.latest:
  71. - name: {{ diaspora.repository }}
  72. - rev: {{ diaspora.version }}
  73. - target: {{ diaspora.install_path }}
  74. - user: {{ diaspora.user.username }}
  75. - require:
  76. - file: diaspora_install_directory
  77. - require_in:
  78. - file: {{ diaspora.install_path }}/config/database.yml
  79. diaspora_rvm_ruby_version_alias:
  80. cmd.run:
  81. - name: rvm alias create $(cat {{ diaspora.install_path }}/.ruby-version) ruby-{{ diaspora.ruby_version }}
  82. - runas: diaspora
  83. - unless: rvm alias list | grep "$(cat {{ diaspora.install_path }}/.ruby-version) => ruby-{{ diaspora.ruby_version }}"
  84. - require:
  85. - rvm: diaspora_rvm_ruby
  86. - git: diaspora_git
  87. diaspora_rails_env_for_login_shell:
  88. file.replace:
  89. {%- if 'shell' in diaspora.user and diaspora.user.shell == "/bin/zsh" %}
  90. - name: {{ home }}/.zshrc
  91. {%- else %}
  92. - name: {{ home }}/.bashrc
  93. {%- endif %}
  94. - pattern: "export RAILS_ENV=\"[a-z]*\""
  95. - repl: "export RAILS_ENV=\"{{ environment }}\""
  96. - append_if_not_found: True
  97. - not_found_content: "\nexport RAILS_ENV=\"{{ environment }}\""
  98. - ignore_if_missing: True
  99. - require:
  100. - rvm: diaspora_rvm_ruby
  101. diaspora_bundle_install:
  102. cmd.run:
  103. - name: rvm ruby-{{ diaspora.ruby_version }}@diaspora do bin/bundle install --jobs $(nproc) --deployment --without test development --with {{ diaspora.database.type }}
  104. - runas: diaspora
  105. - cwd: {{ diaspora.install_path }}
  106. - unless: rvm ruby-{{ diaspora.ruby_version }}@diaspora do bin/bundle check
  107. - env:
  108. - RAILS_ENV: {{ environment }}
  109. - require:
  110. - rvm: diaspora_rvm_gemset
  111. - cmd: diaspora_rvm_ruby_version_alias
  112. - git: diaspora_git
  113. diaspora_create_database:
  114. cmd.run:
  115. - name: rvm ruby-{{ diaspora.ruby_version }}@diaspora do bin/rake db:create db:schema:load
  116. - runas: diaspora
  117. - cwd: {{ diaspora.install_path }}
  118. - onlyif: rvm ruby-{{ diaspora.ruby_version }}@diaspora do bin/rails runner "ActiveRecord::Base.connection" |& grep "database \"{{ diaspora.database.database }}\" does not exist (ActiveRecord::NoDatabaseError)"
  119. - env:
  120. - RAILS_ENV: {{ environment }}
  121. - require:
  122. - cmd: diaspora_bundle_install
  123. - file: {{ diaspora.install_path }}/config/database.yml
  124. - file: {{ diaspora.install_path }}/config/diaspora.yml
  125. - onchanges:
  126. - git: diaspora_git
  127. diaspora_migrate_database:
  128. cmd.run:
  129. - name: rvm ruby-{{ diaspora.ruby_version }}@diaspora do bin/rake db:migrate
  130. - runas: diaspora
  131. - cwd: {{ diaspora.install_path }}
  132. - onlyif: rvm ruby-{{ diaspora.ruby_version }}@diaspora do bin/rake db:migrate:status | grep -oE "^\s+down"
  133. - env:
  134. - RAILS_ENV: {{ environment }}
  135. - require:
  136. - cmd: diaspora_create_database
  137. - onchanges:
  138. - git: diaspora_git
  139. diaspora_precompile_assets:
  140. cmd.run:
  141. - name: rvm ruby-{{ diaspora.ruby_version }}@diaspora do bin/rake assets:precompile
  142. - runas: diaspora
  143. - cwd: {{ diaspora.install_path }}
  144. - env:
  145. - RAILS_ENV: {{ environment }}
  146. - require:
  147. - cmd: diaspora_migrate_database
  148. - onchanges:
  149. - git: diaspora_git