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.

176 lines
5.5KB

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