---
- name: Set up infrastructure related params
  template:
    src: "{{ playbook_dir }}/templates/.tpl.env.local"
    dest: "{{ ansistrano_release_path.stdout }}/.env.local"

- name: Install composer deps
  command: "{{ php_exec }} {{ composer }} install --no-dev"
  args:
    chdir: "{{ ansistrano_release_path.stdout }}"

- name: Run migrations
  command: "{{ php_exec }} bin/console doctrine:migrations:migrate --no-interaction --env=prod"
  args:
    chdir: "{{ ansistrano_release_path.stdout }}"

- name: Setup directory permissions for var/
  file:
    path: "{{ ansistrano_release_path.stdout }}/var"
    state: directory
    mode: 0775
    recurse: true
    follow: true

- name: Build symfony assets
  command: "{{ php_exec }} bin/console assets:install --symlink --relative ./assets"
  args:
    chdir: "{{ ansistrano_release_path.stdout }}"

- name: Install node dependencies
  command: yarn install
  args:
    chdir: "{{ ansistrano_release_path.stdout }}"

- name: Build node production
  command: yarn build
  args:
    chdir: "{{ ansistrano_release_path.stdout }}"

- name: Clear the cache
  command: "{{ php_exec }} bin/console cache:clear --env=prod"
  args:
    chdir: "{{ ansistrano_release_path.stdout }}"