SuperTux88's Diaspora Saltstack Formula
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

154 lines
4.6KB

  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. diaspora_user:
  26. user.present:
  27. - name: {{ diaspora.user.username }}
  28. {%- if 'shell' in diaspora.user %}
  29. - shell: {{ diaspora.user.shell }}
  30. {%- endif %}
  31. {%- if 'home' in diaspora.user %}
  32. - home: {{ diaspora.user.home }}
  33. {%- endif %}
  34. diaspora_rvm_gpg_key:
  35. cmd.run:
  36. - name: gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
  37. - unless: gpg --list-keys 409B6B1796C275462A1703113804BB82D39DC0E3
  38. - runas: {{ diaspora.user.username }}
  39. - require:
  40. - user: diaspora_user
  41. diaspora_rvm_ruby:
  42. rvm.installed:
  43. - name: ruby-{{ diaspora.ruby_version }}
  44. - user: {{ diaspora.user.username }}
  45. - default: True
  46. - require:
  47. - pkg: diaspora_dependencies
  48. - cmd: diaspora_rvm_gpg_key
  49. diaspora_rvm_gemset:
  50. rvm.gemset_present:
  51. - name: diaspora
  52. - ruby: ruby-{{ diaspora.ruby_version }}
  53. - user: {{ diaspora.user.username }}
  54. - require:
  55. - rvm: diaspora_rvm_ruby
  56. diaspora_install_bundler:
  57. gem.installed:
  58. - name: bundler
  59. - user: {{ diaspora.user.username }}
  60. - ruby: ruby-{{ diaspora.ruby_version }}@diaspora
  61. - require:
  62. - rvm: diaspora_rvm_gemset
  63. diaspora_install_directory:
  64. file.directory:
  65. - name: {{ diaspora.install_path }}
  66. - user: {{ diaspora.user.username }}
  67. - mode: 755
  68. - require:
  69. - user: diaspora_user
  70. diaspora_git:
  71. git.latest:
  72. - name: {{ diaspora.repository }}
  73. - rev: {{ diaspora.version }}
  74. - target: {{ diaspora.install_path }}
  75. - user: {{ diaspora.user.username }}
  76. - require:
  77. - file: diaspora_install_directory
  78. - require_in:
  79. - file: {{ diaspora.install_path }}/config/database.yml
  80. diaspora_rvm_ruby_version_alias:
  81. cmd.run:
  82. - name: rvm alias create $(cat {{ diaspora.install_path }}/.ruby-version) ruby-{{ diaspora.ruby_version }}
  83. - runas: diaspora
  84. - unless: rvm alias list | grep "$(cat {{ diaspora.install_path }}/.ruby-version) => ruby-{{ diaspora.ruby_version }}"
  85. - require:
  86. - rvm: diaspora_rvm_ruby
  87. - git: diaspora_git
  88. diaspora_bundle_install:
  89. cmd.run:
  90. - name: rvm ruby-{{ diaspora.ruby_version }}@diaspora do bin/bundle install --jobs $(nproc) --deployment --without test development --with {{ diaspora.database.type }}
  91. - runas: diaspora
  92. - cwd: {{ diaspora.install_path }}
  93. - unless: rvm ruby-{{ diaspora.ruby_version }}@diaspora do bin/bundle check
  94. - env:
  95. - RAILS_ENV: {{ environment }}
  96. - require:
  97. - rvm: diaspora_rvm_gemset
  98. - cmd: diaspora_rvm_ruby_version_alias
  99. - git: diaspora_git
  100. diaspora_create_database:
  101. cmd.run:
  102. - name: rvm ruby-{{ diaspora.ruby_version }}@diaspora do bin/rake db:create db:schema:load
  103. - runas: diaspora
  104. - cwd: {{ diaspora.install_path }}
  105. - onlyif: rvm ruby-{{ diaspora.ruby_version }}@diaspora do bin/rails runner "ActiveRecord::Base.connection" |& grep "database \"{{ diaspora.database.database }}\" does not exist (ActiveRecord::NoDatabaseError)"
  106. - env:
  107. - RAILS_ENV: {{ environment }}
  108. - require:
  109. - cmd: diaspora_bundle_install
  110. - file: {{ diaspora.install_path }}/config/database.yml
  111. - file: {{ diaspora.install_path }}/config/diaspora.yml
  112. - onchanges:
  113. - git: diaspora_git
  114. diaspora_migrate_database:
  115. cmd.run:
  116. - name: rvm ruby-{{ diaspora.ruby_version }}@diaspora do bin/rake db:migrate
  117. - runas: diaspora
  118. - cwd: {{ diaspora.install_path }}
  119. - onlyif: rvm ruby-{{ diaspora.ruby_version }}@diaspora do bin/rake db:migrate:status | grep -oE "^\s+down"
  120. - env:
  121. - RAILS_ENV: {{ environment }}
  122. - require:
  123. - cmd: diaspora_create_database
  124. - onchanges:
  125. - git: diaspora_git
  126. diaspora_precompile_assets:
  127. cmd.run:
  128. - name: rvm ruby-{{ diaspora.ruby_version }}@diaspora do bin/rake assets:precompile
  129. - runas: diaspora
  130. - cwd: {{ diaspora.install_path }}
  131. - env:
  132. - RAILS_ENV: {{ environment }}
  133. - require:
  134. - cmd: diaspora_migrate_database
  135. - onchanges:
  136. - git: diaspora_git