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.

145 lines
4.4KB

  1. {%- from "diaspora/map.jinja" import diaspora with context %}
  2. include:
  3. - diaspora.config
  4. diaspora_dependencies:
  5. pkg.installed:
  6. - pkgs: {{ diaspora.dependencies|json }}
  7. - require:
  8. - pkg: diaspora_database_dependency
  9. diaspora_database_dependency:
  10. pkg.installed:
  11. {%- if diaspora.database.type == "mysql" %}
  12. - name: {{ diaspora.mysql_package }}
  13. {%- else %}
  14. - name: {{ diaspora.postgresql_package }}
  15. {%- endif %}
  16. {%- if diaspora.install_redis %}
  17. redis_package:
  18. pkg.installed:
  19. - name: {{ diaspora.redis_package }}
  20. {%- endif %}
  21. diaspora_user:
  22. user.present:
  23. - name: {{ diaspora.user.username }}
  24. {%- if 'shell' in diaspora.user %}
  25. - shell: {{ diaspora.user.shell }}
  26. {%- endif %}
  27. {%- if 'home' in diaspora.user %}
  28. - home: {{ diaspora.user.home }}
  29. {%- endif %}
  30. diaspora_rvm_gpg_key:
  31. cmd.run:
  32. - name: gpg2 --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_ruby:
  38. rvm.installed:
  39. - name: ruby-{{ diaspora.ruby_version }}
  40. - user: {{ diaspora.user.username }}
  41. - default: True
  42. - require:
  43. - pkg: diaspora_dependencies
  44. - cmd: diaspora_rvm_gpg_key
  45. diaspora_rvm_gemset:
  46. rvm.gemset_present:
  47. - name: diaspora
  48. - ruby: ruby-{{ diaspora.ruby_version }}
  49. - user: {{ diaspora.user.username }}
  50. - require:
  51. - rvm: diaspora_rvm_ruby
  52. diaspora_install_bundler:
  53. gem.installed:
  54. - name: bundler
  55. - user: {{ diaspora.user.username }}
  56. - ruby: ruby-{{ diaspora.ruby_version }}@diaspora
  57. - require:
  58. - rvm: diaspora_rvm_gemset
  59. diaspora_install_directory:
  60. file.directory:
  61. - name: {{ diaspora.install_path }}
  62. - user: {{ diaspora.user.username }}
  63. - mode: 755
  64. - require:
  65. - user: diaspora_user
  66. diaspora_git:
  67. git.latest:
  68. - name: {{ diaspora.repository }}
  69. - rev: {{ diaspora.version }}
  70. - target: {{ diaspora.install_path }}
  71. - user: {{ diaspora.user.username }}
  72. - require:
  73. - file: diaspora_install_directory
  74. - require_in:
  75. - file: {{ diaspora.install_path }}/config/database.yml
  76. diaspora_rvm_ruby_version_alias:
  77. cmd.run:
  78. - name: rvm alias create $(cat {{ diaspora.install_path }}/.ruby-version) ruby-{{ diaspora.ruby_version }}
  79. - runas: diaspora
  80. - unless: rvm alias list | grep "$(cat {{ diaspora.install_path }}/.ruby-version) => ruby-{{ diaspora.ruby_version }}"
  81. - require:
  82. - git: diaspora_git
  83. diaspora_bundle_install:
  84. cmd.run:
  85. - name: rvm ruby-{{ diaspora.ruby_version }}@diaspora do bin/bundle install --jobs $(nproc) --deployment --without test development --with {{ diaspora.database.type }}
  86. - runas: diaspora
  87. - cwd: {{ diaspora.install_path }}
  88. - unless: rvm ruby-{{ diaspora.ruby_version }}@diaspora do bin/bundle check
  89. - env:
  90. - RAILS_ENV: {{ diaspora.environment }}
  91. - require:
  92. - git: diaspora_git
  93. diaspora_create_database:
  94. cmd.run:
  95. - name: rvm ruby-{{ diaspora.ruby_version }}@diaspora do bin/rake db:create db:schema:load
  96. - runas: diaspora
  97. - cwd: {{ diaspora.install_path }}
  98. - onlyif: rvm ruby-{{ diaspora.ruby_version }}@diaspora do bin/rails runner "ActiveRecord::Base.connection" |& grep "database \"{{ diaspora.database.database }}\" does not exist (ActiveRecord::NoDatabaseError)"
  99. - env:
  100. - RAILS_ENV: {{ diaspora.environment }}
  101. - require:
  102. - file: {{ diaspora.install_path }}/config/database.yml
  103. - file: {{ diaspora.install_path }}/config/diaspora.yml
  104. - onchanges:
  105. - git: diaspora_git
  106. diaspora_migrate_database:
  107. cmd.run:
  108. - name: rvm ruby-{{ diaspora.ruby_version }}@diaspora do bin/rake db:migrate
  109. - runas: diaspora
  110. - cwd: {{ diaspora.install_path }}
  111. - onlyif: rvm ruby-{{ diaspora.ruby_version }}@diaspora do bin/rake db:migrate:status | grep -oE "^\s+down"
  112. - env:
  113. - RAILS_ENV: {{ diaspora.environment }}
  114. - require:
  115. - cmd: diaspora_create_database
  116. - onchanges:
  117. - git: diaspora_git
  118. diaspora_precompile_assets:
  119. cmd.run:
  120. - name: rvm ruby-{{ diaspora.ruby_version }}@diaspora do bin/rake assets:precompile
  121. - runas: diaspora
  122. - cwd: {{ diaspora.install_path }}
  123. - env:
  124. - RAILS_ENV: {{ diaspora.environment }}
  125. - require:
  126. - cmd: diaspora_migrate_database
  127. - onchanges:
  128. - git: diaspora_git