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.

151 lines
4.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. 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. - git: diaspora_git
  87. diaspora_bundle_install:
  88. cmd.run:
  89. - name: rvm ruby-{{ diaspora.ruby_version }}@diaspora do bin/bundle install --jobs $(nproc) --deployment --without test development --with {{ diaspora.database.type }}
  90. - runas: diaspora
  91. - cwd: {{ diaspora.install_path }}
  92. - unless: rvm ruby-{{ diaspora.ruby_version }}@diaspora do bin/bundle check
  93. - env:
  94. - RAILS_ENV: {{ environment }}
  95. - require:
  96. - git: diaspora_git
  97. diaspora_create_database:
  98. cmd.run:
  99. - name: rvm ruby-{{ diaspora.ruby_version }}@diaspora do bin/rake db:create db:schema:load
  100. - runas: diaspora
  101. - cwd: {{ diaspora.install_path }}
  102. - onlyif: rvm ruby-{{ diaspora.ruby_version }}@diaspora do bin/rails runner "ActiveRecord::Base.connection" |& grep "database \"{{ diaspora.database.database }}\" does not exist (ActiveRecord::NoDatabaseError)"
  103. - env:
  104. - RAILS_ENV: {{ environment }}
  105. - require:
  106. - cmd: diaspora_bundle_install
  107. - file: {{ diaspora.install_path }}/config/database.yml
  108. - file: {{ diaspora.install_path }}/config/diaspora.yml
  109. - onchanges:
  110. - git: diaspora_git
  111. diaspora_migrate_database:
  112. cmd.run:
  113. - name: rvm ruby-{{ diaspora.ruby_version }}@diaspora do bin/rake db:migrate
  114. - runas: diaspora
  115. - cwd: {{ diaspora.install_path }}
  116. - onlyif: rvm ruby-{{ diaspora.ruby_version }}@diaspora do bin/rake db:migrate:status | grep -oE "^\s+down"
  117. - env:
  118. - RAILS_ENV: {{ environment }}
  119. - require:
  120. - cmd: diaspora_create_database
  121. - onchanges:
  122. - git: diaspora_git
  123. diaspora_precompile_assets:
  124. cmd.run:
  125. - name: rvm ruby-{{ diaspora.ruby_version }}@diaspora do bin/rake assets:precompile
  126. - runas: diaspora
  127. - cwd: {{ diaspora.install_path }}
  128. - env:
  129. - RAILS_ENV: {{ environment }}
  130. - require:
  131. - cmd: diaspora_migrate_database
  132. - onchanges:
  133. - git: diaspora_git