|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- {%- from "diaspora/map.jinja" import diaspora with context %}
- {%- set environment = diaspora.configuration.server.rails_environment %}
-
- include:
- - diaspora.config
-
- diaspora_dependencies:
- pkg.installed:
- - pkgs: {{ diaspora.dependencies|json }}
- - require:
- - pkg: diaspora_database_dependency
-
- diaspora_database_dependency:
- pkg.installed:
- {%- if diaspora.database.type == "mysql" %}
- - name: {{ diaspora.mysql_package }}
- {%- else %}
- - name: {{ diaspora.postgresql_package }}
- {%- endif %}
-
- {%- if diaspora.install_redis %}
- redis_package:
- pkg.installed:
- - name: {{ diaspora.redis_package }}
-
- redis_service:
- service.running:
- - name: {{ diaspora.redis_service }}
- {%- endif %}
-
- {% set home = diaspora.user.get('home', '/home/' + diaspora.user.username) -%}
- diaspora_user:
- user.present:
- - name: {{ diaspora.user.username }}
- {%- if 'shell' in diaspora.user %}
- - shell: {{ diaspora.user.shell }}
- {%- endif %}
- - home: {{ home }}
-
- diaspora_rvm_gpg_key:
- cmd.run:
- - name: gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
- - unless: gpg --list-keys 409B6B1796C275462A1703113804BB82D39DC0E3
- - runas: {{ diaspora.user.username }}
- - require:
- - user: diaspora_user
-
- diaspora_rvm_ruby:
- rvm.installed:
- - name: ruby-{{ diaspora.ruby_version }}
- - user: {{ diaspora.user.username }}
- - default: True
- - require:
- - pkg: diaspora_dependencies
- - cmd: diaspora_rvm_gpg_key
-
- diaspora_rvm_gemset:
- rvm.gemset_present:
- - name: diaspora
- - ruby: ruby-{{ diaspora.ruby_version }}
- - user: {{ diaspora.user.username }}
- - require:
- - rvm: diaspora_rvm_ruby
-
- diaspora_install_bundler:
- gem.installed:
- - name: bundler
- - user: {{ diaspora.user.username }}
- - ruby: ruby-{{ diaspora.ruby_version }}@diaspora
- - require:
- - rvm: diaspora_rvm_gemset
-
- diaspora_install_directory:
- file.directory:
- - name: {{ diaspora.install_path }}
- - user: {{ diaspora.user.username }}
- - mode: 755
- - require:
- - user: diaspora_user
-
- diaspora_reset_schema.rb:
- cmd.run:
- - name: git checkout db/schema.rb
- - runas: {{ diaspora.user.username }}
- - cwd: {{ diaspora.install_path }}
- - onlyif: git ls-files --error-unmatch db/schema.rb && git rev-parse && ! git diff --name-only --exit-code db/schema.rb
-
- diaspora_git:
- git.latest:
- - name: {{ diaspora.repository }}
- - rev: {{ diaspora.version }}
- - target: {{ diaspora.install_path }}
- - user: {{ diaspora.user.username }}
- - force_fetch: True
- - require:
- - file: diaspora_install_directory
- - cmd: diaspora_reset_schema.rb
- - require_in:
- - file: {{ diaspora.install_path }}/config/database.yml
-
- diaspora_rvm_ruby_version_alias:
- cmd.run:
- - name: rvm alias create $(cat {{ diaspora.install_path }}/.ruby-version) ruby-{{ diaspora.ruby_version }}
- - runas: {{ diaspora.user.username }}
- - unless: rvm alias list | grep "$(cat {{ diaspora.install_path }}/.ruby-version) => ruby-{{ diaspora.ruby_version }}"
- - require:
- - rvm: diaspora_rvm_ruby
- - git: diaspora_git
-
- diaspora_rails_env_for_login_shell:
- file.replace:
- {%- if 'shell' in diaspora.user and diaspora.user.shell == "/bin/zsh" %}
- - name: {{ home }}/.zshrc
- {%- else %}
- - name: {{ home }}/.bashrc
- {%- endif %}
- - pattern: "export RAILS_ENV=\"[a-z]*\""
- - repl: "export RAILS_ENV=\"{{ environment }}\""
- - append_if_not_found: True
- - not_found_content: "\nexport RAILS_ENV=\"{{ environment }}\""
- - ignore_if_missing: True
- - require:
- - rvm: diaspora_rvm_ruby
-
- diaspora_configure_bundler:
- cmd.run:
- - name: rvm ruby-{{ diaspora.ruby_version }}@diaspora do script/configure_bundler
- - runas: {{ diaspora.user.username }}
- - cwd: {{ diaspora.install_path }}
- - env:
- - RAILS_ENV: {{ environment }}
- - require:
- - gem: diaspora_install_bundler
- - cmd: diaspora_rvm_ruby_version_alias
- - file: {{ diaspora.install_path }}/config/database.yml
- - onchanges:
- - git: diaspora_git
-
- diaspora_bundle_install:
- cmd.run:
- - name: rvm ruby-{{ diaspora.ruby_version }}@diaspora do bin/bundle install --full-index
- - runas: {{ diaspora.user.username }}
- - cwd: {{ diaspora.install_path }}
- - unless: rvm ruby-{{ diaspora.ruby_version }}@diaspora do bin/bundle check
- - env:
- - RAILS_ENV: {{ environment }}
- - require:
- - cmd: diaspora_configure_bundler
-
- diaspora_create_database:
- cmd.run:
- - name: rvm ruby-{{ diaspora.ruby_version }}@diaspora do bin/rake db:create db:migrate
- - runas: {{ diaspora.user.username }}
- - cwd: {{ diaspora.install_path }}
- - onlyif: rvm ruby-{{ diaspora.ruby_version }}@diaspora do bin/rails runner "ActiveRecord::Base.connection" |& grep "database \"{{ diaspora.database.database }}\" does not exist (ActiveRecord::NoDatabaseError)"
- - env:
- - RAILS_ENV: {{ environment }}
- - require:
- - cmd: diaspora_bundle_install
- - file: {{ diaspora.install_path }}/config/database.yml
- - file: {{ diaspora.install_path }}/config/diaspora.yml
- - onchanges:
- - git: diaspora_git
-
- diaspora_migrate_database:
- cmd.run:
- - name: rvm ruby-{{ diaspora.ruby_version }}@diaspora do bin/rake db:migrate
- - runas: {{ diaspora.user.username }}
- - cwd: {{ diaspora.install_path }}
- - onlyif: rvm ruby-{{ diaspora.ruby_version }}@diaspora do bin/rake db:migrate:status | grep -oE "^\s+down"
- - env:
- - RAILS_ENV: {{ environment }}
- - require:
- - cmd: diaspora_create_database
- - onchanges:
- - git: diaspora_git
-
- diaspora_precompile_assets:
- cmd.run:
- - name: rvm ruby-{{ diaspora.ruby_version }}@diaspora do bin/rake assets:precompile
- - runas: {{ diaspora.user.username }}
- - cwd: {{ diaspora.install_path }}
- - env:
- - RAILS_ENV: {{ environment }}
- - require:
- - cmd: diaspora_migrate_database
- - onchanges:
- - git: diaspora_git
|