Ansible project-deploy (NomadPHP lightning talk)
-
Upload
ramon-de-la-fuente -
Category
Internet
-
view
160 -
download
2
description
Transcript of Ansible project-deploy (NomadPHP lightning talk)
![Page 1: Ansible project-deploy (NomadPHP lightning talk)](https://reader033.fdocuments.us/reader033/viewer/2022052505/554f705db4c905c8088b5528/html5/thumbnails/1.jpg)
ANSIBLE-PROJECT-DEPLOYa re-usable Ansible role to deploy projects
![Page 2: Ansible project-deploy (NomadPHP lightning talk)](https://reader033.fdocuments.us/reader033/viewer/2022052505/554f705db4c905c8088b5528/html5/thumbnails/2.jpg)
ABOUT US
2
Ramon de la Fuente @f_u_e_n_t_e
Jasper N. Brouwer @jaspernbrouwer
Future500 B.V.
![Page 3: Ansible project-deploy (NomadPHP lightning talk)](https://reader033.fdocuments.us/reader033/viewer/2022052505/554f705db4c905c8088b5528/html5/thumbnails/3.jpg)
THE PROBLEM
3
![Page 4: Ansible project-deploy (NomadPHP lightning talk)](https://reader033.fdocuments.us/reader033/viewer/2022052505/554f705db4c905c8088b5528/html5/thumbnails/4.jpg)
THE PROBLEM• Continuous deployment
• Easy maintenance of the deploy procedure.
• Small learning curve.
• Reuse between projects with little effort.
4
![Page 5: Ansible project-deploy (NomadPHP lightning talk)](https://reader033.fdocuments.us/reader033/viewer/2022052505/554f705db4c905c8088b5528/html5/thumbnails/5.jpg)
WHAT IS A DEPLOY?
5
![Page 6: Ansible project-deploy (NomadPHP lightning talk)](https://reader033.fdocuments.us/reader033/viewer/2022052505/554f705db4c905c8088b5528/html5/thumbnails/6.jpg)
WHAT IS A DEPLOY?Directory structure:
.
!"" releases | !"" 20140415234508 | #"" 20140415235146 !"" shared | !"" sessions | !"" source | #"" uploads #"" current -> releases/20140415235146
6
![Page 7: Ansible project-deploy (NomadPHP lightning talk)](https://reader033.fdocuments.us/reader033/viewer/2022052505/554f705db4c905c8088b5528/html5/thumbnails/7.jpg)
WHAT IS A DEPLOY?Directory structure:
.
!"" releases | !"" 20140415234508 | #"" 20140415235146 !"" shared | !"" sessions | !"" source | #"" uploads #"" current -> releases/20140415235146
7
![Page 8: Ansible project-deploy (NomadPHP lightning talk)](https://reader033.fdocuments.us/reader033/viewer/2022052505/554f705db4c905c8088b5528/html5/thumbnails/8.jpg)
WHAT IS A DEPLOY?1. Update the codebase + configuration
8
![Page 9: Ansible project-deploy (NomadPHP lightning talk)](https://reader033.fdocuments.us/reader033/viewer/2022052505/554f705db4c905c8088b5528/html5/thumbnails/9.jpg)
WHAT IS A DEPLOY?1. Update the codebase + configuration
2. Install dependencies
9
![Page 10: Ansible project-deploy (NomadPHP lightning talk)](https://reader033.fdocuments.us/reader033/viewer/2022052505/554f705db4c905c8088b5528/html5/thumbnails/10.jpg)
WHAT IS A DEPLOY?1. Update the codebase + configuration
2. Install dependencies
3. Preserve shared resources
10
![Page 11: Ansible project-deploy (NomadPHP lightning talk)](https://reader033.fdocuments.us/reader033/viewer/2022052505/554f705db4c905c8088b5528/html5/thumbnails/11.jpg)
WHAT IS A DEPLOY?1. Update the codebase + configuration
2. Install dependencies
3. Preserve shared resources
4. Build tasks
11
![Page 12: Ansible project-deploy (NomadPHP lightning talk)](https://reader033.fdocuments.us/reader033/viewer/2022052505/554f705db4c905c8088b5528/html5/thumbnails/12.jpg)
WHAT IS A DEPLOY?1. Update the codebase + configuration
2. Install dependencies
3. Preserve shared resources
4. Build tasks
5. Finalize
12
![Page 13: Ansible project-deploy (NomadPHP lightning talk)](https://reader033.fdocuments.us/reader033/viewer/2022052505/554f705db4c905c8088b5528/html5/thumbnails/13.jpg)
THE ROLE
13
https://galaxy.ansible.com/list#/roles/732project_deploy
![Page 14: Ansible project-deploy (NomadPHP lightning talk)](https://reader033.fdocuments.us/reader033/viewer/2022052505/554f705db4c905c8088b5528/html5/thumbnails/14.jpg)
ROLE WALKTHROUGH
14
![Page 15: Ansible project-deploy (NomadPHP lightning talk)](https://reader033.fdocuments.us/reader033/viewer/2022052505/554f705db4c905c8088b5528/html5/thumbnails/15.jpg)
ROLE WALKTHROUGH! Deploy module variables: ! deploy: project_path current_path releases_path shared_path last_release last_release_path new_release new_release_path unfinished_filename !!
15
![Page 16: Ansible project-deploy (NomadPHP lightning talk)](https://reader033.fdocuments.us/reader033/viewer/2022052505/554f705db4c905c8088b5528/html5/thumbnails/16.jpg)
ROLE WALKTHROUGH! Deploy module variables: ! deploy: project_path: /path/to/project/ current_path: /path/to/project/current releases_path: /path/to/project/releases shared_path: /path/to/project/shared last_release: 20140415234508 last_release_path: /path/to/project/releases/20140415234508 new_release: 20140415235146 new_release_path: /path/to/project/releases/20140415235146 unfinished_filename: DEPLOY_UNFINISHED Used as: {{ deploy.new_release }}
16
![Page 17: Ansible project-deploy (NomadPHP lightning talk)](https://reader033.fdocuments.us/reader033/viewer/2022052505/554f705db4c905c8088b5528/html5/thumbnails/17.jpg)
1. UPDATE THE CODEBASE!- name: Clone project files git: repo={{ project_git_repo }} dest={{ project_source_path }} version={{ project_version }} when: project_deploy_strategy == 'git' !- name: Rsync project files synchronize: src={{ project_local_path }} dest={{ project_source_path }} rsync_timeout={{ project_deploy_synchronize_timeout }} recursive=yes when: project_deploy_strategy == 'synchronize' !
17
![Page 18: Ansible project-deploy (NomadPHP lightning talk)](https://reader033.fdocuments.us/reader033/viewer/2022052505/554f705db4c905c8088b5528/html5/thumbnails/18.jpg)
1. UPDATE THE CODEBASE!- name: Clone project files git: repo={{ project_git_repo }} dest={{ project_source_path }} version={{ project_version }} when: project_deploy_strategy == 'git' !- name: Rsync project files synchronize: src={{ project_local_path }} dest={{ project_source_path }} rsync_timeout={{ project_deploy_synchronize_timeout }} recursive=yes when: project_deploy_strategy == 'synchronize' !
18
![Page 19: Ansible project-deploy (NomadPHP lightning talk)](https://reader033.fdocuments.us/reader033/viewer/2022052505/554f705db4c905c8088b5528/html5/thumbnails/19.jpg)
1. UPDATE THE CODEBASE!- name: Clone project files git: repo={{ project_git_repo }} dest={{ project_source_path }} version={{ project_version }} when: project_deploy_strategy == 'git' !- name: Rsync project files synchronize: src={{ project_local_path }} dest={{ project_source_path }} rsync_timeout={{ project_deploy_synchronize_timeout }} recursive=yes when: project_deploy_strategy == 'synchronize' !
19
![Page 20: Ansible project-deploy (NomadPHP lightning talk)](https://reader033.fdocuments.us/reader033/viewer/2022052505/554f705db4c905c8088b5528/html5/thumbnails/20.jpg)
1. UPDATE THE CODEBASE!- name: Write unfinished file file: path={{ project_source_path }}/{{ deploy.unfinished_filename }} state=touch !- name: Copy files to new build dir command: "cp -pr {{ project_source_path }} {{ deploy.new_release_path }}" !- name: Remove unwanted files/folders from new release file: path={{ deploy.new_release_path }}/{{ item }} state=absent with_items: project_unwanted_items
20
![Page 21: Ansible project-deploy (NomadPHP lightning talk)](https://reader033.fdocuments.us/reader033/viewer/2022052505/554f705db4c905c8088b5528/html5/thumbnails/21.jpg)
1. UPDATE THE CONFIG FILES!- name: Copy project files copy: src={{ item.src }} dest={{ deploy.new_release_path }}/{{ item.dest }} mode={{ item.mode|default('0644') }} with_items: project_files !- name: Copy project templates template: src={{ item.src }} dest={{ deploy.new_release_path }}/{{ item.dest }} mode={{ item.mode|default('0644') }} with_items: project_templates
21
![Page 22: Ansible project-deploy (NomadPHP lightning talk)](https://reader033.fdocuments.us/reader033/viewer/2022052505/554f705db4c905c8088b5528/html5/thumbnails/22.jpg)
2. INSTALL DEPENDENCIES!- name: Do composer install command: "{{ project_command_for_composer_install }} chdir=…" environment: project_environment when: project_has_composer !- name: Do npm install command: "{{ project_command_for_npm_install }} chdir=…" environment: project_environment when: project_has_npm !- name: Do bower install command: "{{ project_command_for_bower_install }} chdir=…" environment: project_environment when: project_has_bower
22
![Page 23: Ansible project-deploy (NomadPHP lightning talk)](https://reader033.fdocuments.us/reader033/viewer/2022052505/554f705db4c905c8088b5528/html5/thumbnails/23.jpg)
2. INSTALL DEPENDENCIES!- name: Do composer install command: "{{ project_command_for_composer_install }} chdir=…" environment: project_environment when: project_has_composer !- name: Do npm install command: "{{ project_command_for_npm_install }} chdir=…" environment: project_environment when: project_has_npm !- name: Do bower install command: "{{ project_command_for_bower_install }} chdir=…" environment: project_environment when: project_has_bower
23
![Page 24: Ansible project-deploy (NomadPHP lightning talk)](https://reader033.fdocuments.us/reader033/viewer/2022052505/554f705db4c905c8088b5528/html5/thumbnails/24.jpg)
3. SHARED RESOURCES!- name: Ensure shared sources are present file: "path='{{ deploy.shared_path }}/{{ item.src }}' state={{ item.type }}“ with_items: project_shared_children !- name: Ensure shared paths are absent file: "path='{{ deploy.new_release_path }}/{{ item.path }}' state=absent" with_items: project_shared_children !- name: Create shared symlinks file: path='{{ deploy.new_release_path }}/{{ item.path }}' src='{{ deploy.shared_path }}/{{ item.src }}' state=link" with_items: project_shared_children
24
![Page 25: Ansible project-deploy (NomadPHP lightning talk)](https://reader033.fdocuments.us/reader033/viewer/2022052505/554f705db4c905c8088b5528/html5/thumbnails/25.jpg)
4. BUILD STEPS!- name: Run post_build_commands in the new_release_path command: "{{ item }} chdir={{ deploy.new_release_path }}" with_items: project_post_build_commands environment: project_environment
25
![Page 26: Ansible project-deploy (NomadPHP lightning talk)](https://reader033.fdocuments.us/reader033/viewer/2022052505/554f705db4c905c8088b5528/html5/thumbnails/26.jpg)
4. BUILD STEPS!- name: Run post_build_commands in the new_release_path command: "{{ item }} chdir={{ deploy.new_release_path }}" with_items: project_post_build_commands environment: project_environment
26
! project_post_build_commands: - "app/console cache:clear" - "app/console assets:install" - "app/console assetic:dump"
![Page 27: Ansible project-deploy (NomadPHP lightning talk)](https://reader033.fdocuments.us/reader033/viewer/2022052505/554f705db4c905c8088b5528/html5/thumbnails/27.jpg)
5. FINALIZE!- name: Remove unfinished file file: path={{ deploy.new_release_path }}/{{ deploy.unfinished_filename }} state=absent when: project_finalize !- name: Finalize the deploy file: src={{ deploy.new_release_path }} dest={{ deploy.current_path }} state=link when: project_finalize
27
![Page 28: Ansible project-deploy (NomadPHP lightning talk)](https://reader033.fdocuments.us/reader033/viewer/2022052505/554f705db4c905c8088b5528/html5/thumbnails/28.jpg)
28
![Page 29: Ansible project-deploy (NomadPHP lightning talk)](https://reader033.fdocuments.us/reader033/viewer/2022052505/554f705db4c905c8088b5528/html5/thumbnails/29.jpg)
IT’S NOT COMPLICATED!• Only 75 lines
• Number of tasks: 18
• Variables to configure: 24
29
![Page 30: Ansible project-deploy (NomadPHP lightning talk)](https://reader033.fdocuments.us/reader033/viewer/2022052505/554f705db4c905c8088b5528/html5/thumbnails/30.jpg)
EXAMPLE PLAYBOOK
30
![Page 31: Ansible project-deploy (NomadPHP lightning talk)](https://reader033.fdocuments.us/reader033/viewer/2022052505/554f705db4c905c8088b5528/html5/thumbnails/31.jpg)
EXAMPLE PLAYBOOK!- name: Deploy the application hosts: production remote_user: "{{ production_deploy_user }}" sudo: no ! vars: project_root: "{{ sweetlakephp_root }}" project_git_repo: "{{ sweetlakephp_github_repo }}" project_deploy_strategy: git
31
![Page 32: Ansible project-deploy (NomadPHP lightning talk)](https://reader033.fdocuments.us/reader033/viewer/2022052505/554f705db4c905c8088b5528/html5/thumbnails/32.jpg)
EXAMPLE PLAYBOOK!- name: Deploy the application hosts: production remote_user: "{{ production_deploy_user }}" sudo: no ! vars: project_root: "{{ sweetlakephp_root }}" project_git_repo: "{{ sweetlakephp_github_repo }}" project_deploy_strategy: git ! project_environment: SYMFONY_ENV: "prod"
32
![Page 33: Ansible project-deploy (NomadPHP lightning talk)](https://reader033.fdocuments.us/reader033/viewer/2022052505/554f705db4c905c8088b5528/html5/thumbnails/33.jpg)
EXAMPLE PLAYBOOK! project_environment: SYMFONY_ENV: "prod" ! project_shared_children: - path: "/app/sessions" src: "sessions" - path: "/web/uploads" src: "uploads" ! project_templates: - name: parameters.yml src: "templates/parameters_prod.yml.j2" dest: "/app/config/parameters_prod.yml" !
33
![Page 34: Ansible project-deploy (NomadPHP lightning talk)](https://reader033.fdocuments.us/reader033/viewer/2022052505/554f705db4c905c8088b5528/html5/thumbnails/34.jpg)
EXAMPLE PLAYBOOK! project_environment: SYMFONY_ENV: "prod" ! project_shared_children: - path: "/app/sessions" src: "sessions" - path: "/web/uploads" src: "uploads" ! project_templates: - name: parameters.yml src: "templates/parameters_prod.yml.j2" dest: "/app/config/parameters_prod.yml" !
34
![Page 35: Ansible project-deploy (NomadPHP lightning talk)](https://reader033.fdocuments.us/reader033/viewer/2022052505/554f705db4c905c8088b5528/html5/thumbnails/35.jpg)
EXAMPLE PLAYBOOK! project_has_composer: yes ! project_post_build_commands: - "php vendor/sensio/…/DistributionBundle/…/bin/build_bootstrap.php” - "app/console cache:clear" - "app/console doctrine:migrations:migrate --no-interaction" - "app/console assets:install" - "app/console assetic:dump" ! roles: - f500.project_deploy ! post_tasks: - name: Remove old releases deploy: "path={{ project_root }} state=clean"
35
![Page 36: Ansible project-deploy (NomadPHP lightning talk)](https://reader033.fdocuments.us/reader033/viewer/2022052505/554f705db4c905c8088b5528/html5/thumbnails/36.jpg)
EXAMPLE PLAYBOOK! project_has_composer: yes ! project_post_build_commands: - "php vendor/sensio/…/DistributionBundle/…/bin/build_bootstrap.php” - "app/console cache:clear" - "app/console doctrine:migrations:migrate --no-interaction" - "app/console assets:install" - "app/console assetic:dump" ! roles: - f500.project_deploy ! post_tasks: - name: Remove old releases deploy: "path={{ project_root }} state=clean"
36
![Page 37: Ansible project-deploy (NomadPHP lightning talk)](https://reader033.fdocuments.us/reader033/viewer/2022052505/554f705db4c905c8088b5528/html5/thumbnails/37.jpg)
THANK YOU!
37
Feedback: https://joind.in/11570
https://github.com/f500/ansible-project_deploy