Skip to content

Instantly share code, notes, and snippets.

@dadamssg
Last active December 29, 2015 16:47
Show Gist options
  • Save dadamssg/d706b6c0d599ed6222df to your computer and use it in GitHub Desktop.
Save dadamssg/d706b6c0d599ed6222df to your computer and use it in GitHub Desktop.
---
- name: Define release name.
set_fact: app_project_release={{ lookup('pipe', 'date +%Y%m%d%H%M%S') }}
- name: Set current release directory.
set_fact: app_current_release_dir={{app_project_root}}/releases/{{app_project_release}}
- name: Set shared directory.
set_fact: app_shared_dir={{app_project_root}}/shared
- name: Set app console.
set_fact: app_console={{app_current_release_dir}}/app/cli.php
- name: Prepare necessary directories for release and shared data.
file: state=directory path={{item.path}}
with_items:
- { path: "{{app_current_release_dir}}" }
- { path: "{{app_shared_dir}}/var/logs" }
become: yes
become_user: deployer
- name: Ensure .env file is in place
copy: content="{{ app_env_config }}" dest={{app_shared_dir}}/.env
become: yes
become_user: deployer
- name: Pull sources from the repository.
git: repo={{app_project_repo}} dest={{app_current_release_dir}} version={{app_project_branch}} accept_hostkey=yes depth=1
become: yes
become_user: deployer
- name: Ensure linked directories are not present.
file: state=absent path={{item.path}}
with_items:
- { path: "{{app_current_release_dir}}/var" }
become: yes
become_user: deployer
- name: Create symlinks to shared directories and files.
file: state=link src="{{app_shared_dir}}{{item.src}}" path="{{app_current_release_dir}}{{item.path}}"
with_items:
- { src: "/var", path: "/var" } # location of shared log directory
- { src: "/.env", path: "/.env" } # contains sensitive app credentials
become: yes
become_user: deployer
- name: Install composer.
get_url: url=https://getcomposer.org/composer.phar dest={{app_current_release_dir}}/composer.phar mode=0755 validate_certs=no
become: yes
become_user: deployer
- name: Run composer install.
shell: cd {{app_current_release_dir}}; php composer.phar install --no-dev --optimize-autoloader --no-interaction
become: yes
become_user: deployer
- name: Run migrations.
shell: cd {{app_current_release_dir}}; php {{app_console}} migrations:migrate -n
become: yes
become_user: deployer
- name: Create symlink for release.
file: state=link src="{{app_current_release_dir}}" path="{{app_project_root}}/current"
become: yes
become_user: deployer
- name: Cleanup releases.
shell: "cd {{app_project_root}}/releases && ls -t1 | tail -n +$((4)) | xargs -n1 rm -rf" # only keeps latest 3
notify:
- restart fpm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment