Add DrupalCon slides
BIN
source/deploying-drupal-ansible-ansistrano/demo.mp4
Normal file
After Width: | Height: | Size: 114 KiB |
After Width: | Height: | Size: 108 KiB |
After Width: | Height: | Size: 617 KiB |
After Width: | Height: | Size: 76 KiB |
After Width: | Height: | Size: 48 KiB |
After Width: | Height: | Size: 30 KiB |
After Width: | Height: | Size: 33 KiB |
After Width: | Height: | Size: 7.3 KiB |
BIN
source/deploying-drupal-ansible-ansistrano/images/site.png
Normal file
After Width: | Height: | Size: 626 KiB |
|
@ -1,131 +1,95 @@
|
||||||
theme: poster, 8
|
|
||||||
autoscale: true
|
autoscale: true
|
||||||
build-lists: true
|
build-lists: true
|
||||||
|
code: line-height(1.2)
|
||||||
header-emphasis: #53B0EB
|
header-emphasis: #53B0EB
|
||||||
header: alignment(left)
|
|
||||||
text: alignment(left)
|
text: alignment(left)
|
||||||
text-emphasis: #53B0EB
|
theme: plain jane, 8
|
||||||
code: Monaco, line-height(1.2)
|
|
||||||
|
|
||||||
[.header: alignment(center)]
|
# [fit] **Deploying PHP applications** <br>using Ansible, Ansible Vault <br>and Ansistrano
|
||||||
|
|
||||||
|
^ Ansible crash course
|
||||||
# [fit] Deploying PHP applications
|
Basic deployment
|
||||||
# [fit] _With Ansible, Ansible Vault and Ansistrano_
|
Better deployment
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
[.background-color: #FFFFFF]
|
|
||||||
[.build-lists: false]
|
[.build-lists: false]
|
||||||
[.header: #111111]
|
[.header: #111111]
|
||||||
[.text: #111111, alignment(left)]
|
|
||||||
|
|
||||||
![right 800%](../images/me-phpnw.png)
|
![right 500%](../images/me-phpnw-inviqa.jpg)
|
||||||
|
|
||||||
- Full Stack Web Developer & System Administrator
|
- Full Stack Web Developer & System Administrator
|
||||||
- Senior Developer at Microserve
|
- **Senior Software Engineer** at **Inviqa**
|
||||||
- Part-time freelancer
|
- Acquia certified **Drupal 8 Grand Master**
|
||||||
- Acquia certified Drupal 8 Grand Master
|
- Open sourcer
|
||||||
- Drupal 7 & 8 core contributor
|
- Drupal 7 & 8 **core contributor**
|
||||||
- Symfony, Laravel, Sculpin
|
|
||||||
- @opdavies
|
- @opdavies
|
||||||
- www.oliverdavies.uk
|
- www.oliverdavies.uk
|
||||||
|
|
||||||
^ Work at Microserve.
|
^ Maintain Drupal modules, PHP CLI tools and libraries
|
||||||
Maintain Drupal modules, PHP CLI tools and libraries
|
|
||||||
Blog on my website
|
Blog on my website
|
||||||
|
I work for Inviqa, but this based on my personal and side projects, though I've implemented similar solutions in the past.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
[.background-color: #FFFFFF]
|
![350% inline](images/logo-platformsh.png)
|
||||||
[.build-lists: false]
|
![150% inline](images/logo-acquia.png)
|
||||||
[.text: #111111, alignment(left)]
|
![130% inline](images/logo-pantheon.png)
|
||||||
|
|
||||||
![right 100%](../images/microserve-light.png)
|
^ Large, well-known managed hosting companies
|
||||||
|
Optimised servers for PHP/Drupal applications
|
||||||
- https://microserve.io
|
Include some sort of deployment system
|
||||||
- https://www.drupal.org/microserve
|
|
||||||
- https://github.com/microserve-io
|
|
||||||
- https://twitter.com/microserveltd
|
|
||||||
- https://www.linkedin.com/company/microserve-ltd
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### _Things we'll be_
|
![100%](images/logo-digital-ocean.png)
|
||||||
# Looking at
|
![30%](images/logo-linode.png)
|
||||||
|
![30%](https://www.vultr.com/media/media_card_1200x630.png)
|
||||||
|
|
||||||
|
^ More applicable to virtual or dedicated servers with no existing deployment process
|
||||||
|
Not enough budget for fully-managed, or using internal infrastructure
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
[.background-color: #FFFFFF]
|
## **What we'll be looking at**
|
||||||
|
|
||||||
|
* **Ansible** crash course
|
||||||
![10%](images/ansible.png)
|
* Keeping secrets with **Ansible Vault**
|
||||||
![85%](images/vagrant.png)
|
* Deployments with **Ansistrano**
|
||||||
![325%](images/druplicon.png)
|
|
||||||
![325%](images/composer.png)
|
|
||||||
|
|
||||||
^ Ansible - software provisioning and deployment tool
|
|
||||||
Vagrant - used for managing virtual machines. Used instead of a real server
|
|
||||||
Drupal
|
|
||||||
Composer - required by Drupal 8 to pull in dependencies (e.g. Symfony)
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
1. Ansible crash course
|
# **What is Ansible?**
|
||||||
1. Initial setup and provisioning
|
|
||||||
1. Basic deployment setup
|
|
||||||
1. Using Ansible Vault for variables
|
|
||||||
1. Adding and configuring Ansistrano
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
[.background-color: #FFFFFF]
|
## Ansible is **open source software** that automates **software provisioning**, <br>**configuration management**, <br>and **application deployment**.
|
||||||
[.text: #111111, alignment(left)]
|
|
||||||
|
|
||||||
## When should I use this?
|
|
||||||
|
|
||||||
* Dedicated hosting: probably has this already
|
|
||||||
* Shared hosting: probably not flexible enough
|
|
||||||
* VPS or dedicated server
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### _What is_
|
|
||||||
# Ansible?
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
[.background-color: #FFFFFF]
|
|
||||||
[.text: #111111]
|
|
||||||
[.footer: https://en.wikipedia.org/wiki/Ansible_(software)]
|
|
||||||
|
|
||||||
Ansible is _open source software_<br>that automates _software provisioning_, <br>_configuration management_, <br>and _application deployment_.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
[.background-color: #FFFFFF]
|
|
||||||
[.text: #111111, alignment(left)]
|
|
||||||
|
|
||||||
![10% right](images/ansible.png)
|
![10% right](images/ansible.png)
|
||||||
|
|
||||||
# What is Ansible?
|
---
|
||||||
|
|
||||||
* YAML
|
![10% right](images/ansible.png)
|
||||||
* Batteries included
|
|
||||||
|
### **What is Ansible?**
|
||||||
|
|
||||||
|
* CLI tool
|
||||||
|
* Written in Python
|
||||||
|
* Configured with YAML
|
||||||
* Executes remote commands
|
* Executes remote commands
|
||||||
* Installs software packages
|
* Installs software packages
|
||||||
* Performs deployment steps
|
* Performs deployment steps
|
||||||
|
* Batteries included
|
||||||
|
|
||||||
|
^ Written in Python but you don't need to write or know Python to use it
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
[.background-color: #FFFFFF]
|
|
||||||
[.text: #111111, alignment(left)]
|
|
||||||
|
|
||||||
![10% right](images/ansible.png)
|
![10% right](images/ansible.png)
|
||||||
|
|
||||||
# What is Ansible?
|
### **What is Ansible?**
|
||||||
|
|
||||||
* Hosts
|
* Hosts/Inventories
|
||||||
* Commands
|
* Commands
|
||||||
* Playbooks
|
* Playbooks
|
||||||
* Tasks
|
* Tasks
|
||||||
|
@ -133,13 +97,9 @@ Ansible is _open source software_<br>that automates _software provisioning_, <br
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
||||||
[.background-color: #FFFFFF]
|
|
||||||
[.text: #111111, alignment(left)]
|
|
||||||
|
|
||||||
![10% right](images/ansible.png)
|
![10% right](images/ansible.png)
|
||||||
|
|
||||||
# Why Ansible?
|
### **Why Ansible?**
|
||||||
|
|
||||||
* Familiar syntax
|
* Familiar syntax
|
||||||
* Easily readable
|
* Easily readable
|
||||||
|
@ -147,37 +107,64 @@ Ansible is _open source software_<br>that automates _software provisioning_, <br
|
||||||
* Easy to add to an existing project
|
* Easy to add to an existing project
|
||||||
* Includes relevant modules (e.g. Composer)
|
* Includes relevant modules (e.g. Composer)
|
||||||
|
|
||||||
|
^ Drupal 8, Symfony, Ansible all use YAML
|
||||||
|
Runs on any server with Python
|
||||||
|
Plugins into Drupal via CLI apps like Drush and Drupal Console
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### _Ansible_
|
# **Hosts / Inventories**
|
||||||
# Hosts
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
```ini
|
```ini
|
||||||
# hosts.ini
|
# hosts.ini
|
||||||
|
|
||||||
[dransible]
|
[webservers]
|
||||||
192.168.33.10
|
192.168.33.10
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### _Ansible_
|
```yaml
|
||||||
# Commands
|
# hosts.yml
|
||||||
|
|
||||||
---
|
webservers:
|
||||||
|
hosts:
|
||||||
```
|
192.168.33.10:
|
||||||
ansible all -m ping
|
|
||||||
|
|
||||||
ansible all -m command -a 'git pull --chdir=/var/www/app'
|
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### _Ansible_
|
# **Commands**
|
||||||
# [fit] Tasks and Playbooks
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# `ansible all -m ping`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
```
|
||||||
|
webservers | SUCCESS => {
|
||||||
|
"ansible_facts": {
|
||||||
|
"discovered_interpreter_python": "/usr/bin/python"
|
||||||
|
},
|
||||||
|
"changed": false,
|
||||||
|
"ping": "pong"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# `ansible all `<br>`-m command `<br>`-a 'git pull `<br>`--chdir=/app'`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# `ansible all `<br>`-m git -a 'repo=https://github.com/opdavies/dransible dest=/app`'
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# **Tasks and Playbooks**
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
@ -187,23 +174,25 @@ ansible all -m command -a 'git pull --chdir=/var/www/app'
|
||||||
---
|
---
|
||||||
- hosts: all
|
- hosts: all
|
||||||
|
|
||||||
|
vars:
|
||||||
|
git_repo: https://github.com/opdavies/dransible
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
- name: Update the code
|
- name: Update the code
|
||||||
command: git pull
|
git:
|
||||||
args:
|
repo: '{{ git_repo }}'
|
||||||
chdir: /var/www/app
|
dest: /app
|
||||||
|
version: master
|
||||||
|
update: true
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
```
|
# `ansible-playbook `<br>`ansible/playbook.yml `<br>`-i hosts.yml`
|
||||||
ansible-playbook playbook.yml -i hosts.ini
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### _Ansible_
|
# **Roles**
|
||||||
# Roles
|
|
||||||
|
|
||||||
^ Collections of tasks, variables and handlers
|
^ Collections of tasks, variables and handlers
|
||||||
|
|
||||||
|
@ -220,11 +209,11 @@ ansible-playbook playbook.yml -i hosts.ini
|
||||||
- src: geerlingguy.php-mysql
|
- src: geerlingguy.php-mysql
|
||||||
```
|
```
|
||||||
|
|
||||||
|
^ Provisioning LAMP stack and Composer
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
```
|
# `ansible-galaxy -r`<br>`ansible/requirements.yml install`
|
||||||
ansible-galaxy -r ansible/requirements.yml install
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
@ -246,19 +235,6 @@ ansible-galaxy -r ansible/requirements.yml install
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
[.header: alignment(center)]
|
|
||||||
|
|
||||||
## Let's take a look <br>at the code
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### _Basic deployment_
|
|
||||||
# Ansible
|
|
||||||
|
|
||||||
^ Any questions on Ansible so far?
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
# ansible/provision.yml
|
# ansible/provision.yml
|
||||||
|
|
||||||
|
@ -272,37 +248,38 @@ tasks:
|
||||||
mysql_user:
|
mysql_user:
|
||||||
name: drupal
|
name: drupal
|
||||||
password: secret
|
password: secret
|
||||||
priv: '*.*:ALL'
|
priv: 'mydatabase.*:ALL'
|
||||||
state: present
|
state: present
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
# **Basic deployment**
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
# ansible/deploy.yml
|
# ansible/deploy.yml
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
- name: Creating project directory
|
- name: Creating project directory
|
||||||
file:
|
file:
|
||||||
path: /var/www/app
|
path: /app
|
||||||
state: directory
|
state: directory
|
||||||
|
|
||||||
- name: Uploading application
|
- name: Uploading application
|
||||||
synchronize:
|
synchronize:
|
||||||
src: "{{ playbook_dir }}/../"
|
src: "{{ playbook_dir }}/../"
|
||||||
dest: /var/www/app
|
dest: /app
|
||||||
|
|
||||||
- name: Installing Composer dependencies
|
- name: Installing Composer dependencies
|
||||||
composer:
|
composer:
|
||||||
command: install
|
command: install
|
||||||
working_dir: /var/www/app
|
working_dir: /app
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
[.background-color: #FFFFFF]
|
|
||||||
[.text: #111111, alignment(left)]
|
|
||||||
|
|
||||||
# Disadvantages
|
# Disadvantages
|
||||||
|
|
||||||
* Single point of failure
|
* Single point of failure
|
||||||
|
@ -311,29 +288,11 @@ tasks:
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### _Keeping secrets_
|
# **Keeping secrets: <br>Ansible Vault**
|
||||||
# Ansible Vault
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
```bash
|
# `ansible-vault create` <br>`ansible/vault.yml`
|
||||||
ansible-vault create ansible/vault.yml
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
```
|
|
||||||
$ANSIBLE_VAULT;1.1;AES256
|
|
||||||
36656233323539616336393838396137343939623233393338666530313730373233663263633065
|
|
||||||
3133633335316364306366333539613936376239383133330a356365666232623537333730663638
|
|
||||||
37393264616134613163663762666464373733663737383039316163336263323538393533323266
|
|
||||||
3432346662613438330a386435393432323761386137333736363436386466643031386662353933
|
|
||||||
30393631386463313265653862633866663530626439623063393934653235666530656462643135
|
|
||||||
39366431353762383434663536663761323565616564336131666339653038326333306433326264
|
|
||||||
31623539643166626234663736656337633036323837333137343533386165366531626462643662
|
|
||||||
66626631663930626266653937323634366231326537626131663662396335393361336635373736
|
|
||||||
3435
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
@ -341,22 +300,39 @@ $ANSIBLE_VAULT;1.1;AES256
|
||||||
# ansible/vars/vault.yml
|
# ansible/vars/vault.yml
|
||||||
|
|
||||||
---
|
---
|
||||||
vault_app_db_name: mydatabase
|
vault_database_name: mydatabase
|
||||||
vault_app_db_user: drupal
|
vault_database_user: drupal
|
||||||
vault_app_db_password: secret
|
vault_database_password: secret
|
||||||
```
|
```
|
||||||
|
|
||||||
^ Optional, but easier to see where variables are set
|
^ Optional, but easier to see where variables are set
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
```
|
||||||
|
$ANSIBLE_VAULT;1.1;AES256
|
||||||
|
36656233323539616336393838396137343939623233393338666530313
|
||||||
|
73037323366326363306531336333353163643063663335396139363762
|
||||||
|
39383133330a35636566623262353733373066363837393264616134613
|
||||||
|
16366376266646437373366373738303931616333626332353839353332
|
||||||
|
32663432346662613438330a38643539343232376138613733373636343
|
||||||
|
63864666430313866623539333039363138646331326565386263386666
|
||||||
|
35306264396230633939346532356665306564626431353936643135376
|
||||||
|
23834346635366637613235656165643361316663396530383263333064
|
||||||
|
33326264316235396431666262346637366563376330363238373331373
|
||||||
|
43533386165366531626462643662666266316639306262666539373236
|
||||||
|
343662313265376261316636623963353933613366353737363435
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
# ansible/vars/vars.yml
|
# ansible/vars/vars.yml
|
||||||
|
|
||||||
---
|
---
|
||||||
app_db_name: "{{ vault_app_db_name }}"
|
database_name: "{{ vault_database_name }}"
|
||||||
app_db_user: "{{ vault_app_db_user }}"
|
database_user: "{{ vault_database_user }}"
|
||||||
app_db_password: "{{ vault_app_db_password }}"
|
database_password: "{{ vault_database_password }}"
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
@ -367,20 +343,21 @@ app_db_password: "{{ vault_app_db_password }}"
|
||||||
tasks:
|
tasks:
|
||||||
- name: Create a database
|
- name: Create a database
|
||||||
mysql_db:
|
mysql_db:
|
||||||
name: '{{ app_db_name }}'
|
name: '{{ database_name }}'
|
||||||
state: present
|
state: present
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
```bash
|
# `ansible-vault edit ansible/vault.yml`
|
||||||
ansible-vault edit ansible/vault.yml
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### _Better deployments_
|
# `ansible-playbook` <br>`-i hosts.yml` <br>`ansible/deploy.yml`<br>`--ask-vault-pass`
|
||||||
# Ansistrano
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# **Better deployments**
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
@ -391,16 +368,6 @@ Ansible port of Capistrano
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
[.background-color: #FFFFFF]
|
|
||||||
[.text: #111111, alignment(center)]
|
|
||||||
|
|
||||||
Capistrano is an open-source tool for running scripts on multiple servers; its main use is deploying web applications. <br><br><br>It automates the process of making a new version of an application available on one or more web servers, including supporting tasks such as changing databases.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
[.background-color: #FFFFFF]
|
|
||||||
[.text: #111111, alignment(left)]
|
|
||||||
|
|
||||||
# Features
|
# Features
|
||||||
|
|
||||||
* Multiple release directories
|
* Multiple release directories
|
||||||
|
@ -444,10 +411,40 @@ Capistrano is an open-source tool for running scripts on multiple servers; its m
|
||||||
---
|
---
|
||||||
...
|
...
|
||||||
vars:
|
vars:
|
||||||
ansistrano_deploy_to: /var/www
|
project_deploy_dir: /var/www
|
||||||
|
|
||||||
|
ansistrano_deploy_to: '{{ project_deploy_dir }}'
|
||||||
ansistrano_deploy_via: git
|
ansistrano_deploy_via: git
|
||||||
ansistrano_git_branch: master
|
ansistrano_git_branch: master
|
||||||
ansistrano_git_repo: 'git@github.com:foo/bar.git'
|
ansistrano_git_repo: 'git@github.com:opdavies/dransible'
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# `ansible-playbook` <br>`-i hosts.yml` <br>`ansible/deploy.yml`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
```bash
|
||||||
|
vagrant@dransible:/app$ ls -l
|
||||||
|
total 8
|
||||||
|
|
||||||
|
lrwxrwxrwx 1 26 Jul 19 00:15 current -> ./releases/20190719001241Z
|
||||||
|
drwxr-xr-x 5 4096 Jul 22 20:30 releases
|
||||||
|
drwxr-xr-x 4 4096 Jul 19 00:00 shared
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
```
|
||||||
|
vagrant@dransible:/app/releases$ ls -l
|
||||||
|
total 20
|
||||||
|
|
||||||
|
drwxr-xr-x 5 4096 Jul 22 20:30 .
|
||||||
|
drwxr-xr-x 4 4096 Jul 19 00:15 ..
|
||||||
|
drwxr-xr-x 10 4096 Jul 19 00:02 20190719000013Z
|
||||||
|
drwxr-xr-x 10 4096 Jul 19 00:14 20190719001241Z
|
||||||
|
drwxr-xr-x 9 4096 Jul 22 20:30 20190722203038Z
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
@ -462,19 +459,25 @@ Capistrano is an open-source tool for running scripts on multiple servers; its m
|
||||||
- ansistrano.rollback
|
- ansistrano.rollback
|
||||||
|
|
||||||
vars:
|
vars:
|
||||||
ansistrano_deploy_to: /var/www
|
ansistrano_deploy_to: '{{ project_deploy_dir }}'
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### _Customising Ansistrano_
|
# `ansible-playbook` <br>`-i hosts.yml` <br>`ansible/rollback.yml`
|
||||||
# Build Hooks
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
[.background-color: #FFFFFF]
|
# **Customising Ansistrano: <br>Build Hooks**
|
||||||
|
|
||||||
![inline 125%](images/ansistrano-flow.png)
|
---
|
||||||
|
|
||||||
|
![inline 140%](images/ansistrano-flow.png)
|
||||||
|
|
||||||
|
^ Shared = files directory, logs
|
||||||
|
Before/after symlink shared = run tests
|
||||||
|
Symlink = 'current' symlink, site is live
|
||||||
|
Clean up = remove node_modules, database export, sqlite testing DB
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
@ -525,14 +528,162 @@ vars:
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
[.header: alignment(center)]
|
![80%](images/drupalcon/site.png)
|
||||||
|
|
||||||
# Questions?
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
[.header: alignment(center)]
|
# **Demo**
|
||||||
|
|
||||||
# Thanks
|
---
|
||||||
### _@opdavies_
|
|
||||||
### _oliverdavies.uk_
|
# **Questions?**
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
![](images/drupalcon/contribution.jpg)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
![](images/drupalcon/feedback.jpg)
|
||||||
|
|
||||||
|
^ Please leave feedback via the DrupalCon app, or via Twitter
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# **Managing data <br>across deployments**
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
# ansible/deploy.yml
|
||||||
|
|
||||||
|
vars:
|
||||||
|
# ...
|
||||||
|
ansistrano_shared_paths:
|
||||||
|
- "{{ drupal_root }}/sites/default/files"
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
```
|
||||||
|
vagrant@dransible:/app/shared/web/sites/default/files$ ls -la
|
||||||
|
total 28
|
||||||
|
|
||||||
|
drwxrwxrwx 6 4096 Jul 19 00:18 .
|
||||||
|
drwxr-xr-x 3 4096 Jul 19 00:00 ..
|
||||||
|
drwxrwxr-x 2 4096 Jul 22 21:24 css
|
||||||
|
-rwxrwxrwx 1 487 Jul 19 00:02 .htaccess
|
||||||
|
drwxrwxr-x 2 4096 Jul 19 00:19 js
|
||||||
|
drwxrwxrwx 3 4096 Jul 19 00:18 php
|
||||||
|
drwxrwxrwx 2 4096 Jul 19 00:03 styles
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
```
|
||||||
|
vagrant@dransible:/app/current/web/sites/default$ ls -la
|
||||||
|
total 48
|
||||||
|
dr-xr-xr-x 2 4096 Jul 19 00:14 .
|
||||||
|
drwxr-xr-x 3 4096 Jan 22 17:30 ..
|
||||||
|
-rw-r--r-- 1 6762 Jul 19 00:14 default.services.yml
|
||||||
|
-rw-r--r-- 1 31342 Jul 19 00:14 default.settings.php
|
||||||
|
lrwxrwxrwx 1 45 Jul 19 00:14 files -> ../../../../../shared/web/sites/default/files
|
||||||
|
lrwxrwxrwx 1 35 Jul 19 00:12 settings.php -> /tmp/app/sites/default/settings.php
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# **Generating Drupal settings <br>files per deployment**
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
# ansible/vars/vault.yml
|
||||||
|
|
||||||
|
---
|
||||||
|
vault_database_name: drupal
|
||||||
|
vault_database_user: drupal
|
||||||
|
vault_database_password: drupal
|
||||||
|
vault_hash_salt: dfgiy$fd2!34gsf2*34g74
|
||||||
|
```
|
||||||
|
---
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
# ansible/vars/vars.yml
|
||||||
|
|
||||||
|
---
|
||||||
|
database_name: "{{ vault_database_name }}"
|
||||||
|
database_password: "{{ vault_database_password }}"
|
||||||
|
database_user: "{{ vault_database_user }}"
|
||||||
|
hash_salt: "{{ vault_hash_salt }}"
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
# ansible/vars/vars.yml
|
||||||
|
|
||||||
|
---
|
||||||
|
drupal_settings:
|
||||||
|
- drupal_root: /tmp/app
|
||||||
|
sites:
|
||||||
|
- name: default
|
||||||
|
settings:
|
||||||
|
databases:
|
||||||
|
default:
|
||||||
|
default:
|
||||||
|
driver: mysql
|
||||||
|
host: localhost
|
||||||
|
database: '{{ database_name }}'
|
||||||
|
username: '{{ database_user }}'
|
||||||
|
password: '{{ database_password }}'
|
||||||
|
hash_salt: '{{ hash_salt }}'
|
||||||
|
config_directories:
|
||||||
|
sync: ../config/sync
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
```php
|
||||||
|
// templates/settings.php.j2
|
||||||
|
// {{ ansible_managed }}
|
||||||
|
|
||||||
|
{% for key, values in item.1.settings.databases.items() %}
|
||||||
|
{% for target, values in values.items() %}
|
||||||
|
$databases['{{ key }}']['{{ target }}'] = array(
|
||||||
|
'driver' => '{{ values.driver|default('mysql') }}',
|
||||||
|
'host' => '{{ values.host|default('localhost') }}',
|
||||||
|
'database' => '{{ values.database }}',
|
||||||
|
'username' => '{{ values.username }}',
|
||||||
|
'password' => '{{ values.password }}',
|
||||||
|
);
|
||||||
|
|
||||||
|
{% endfor %}
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
{% if item.1.settings.base_url is defined %}
|
||||||
|
$base_url = '{{ item.1.settings.base_url }}';
|
||||||
|
{% endif %}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- name: Remove settings.php
|
||||||
|
file:
|
||||||
|
path: '{{ ansistrano_release_path.stdout }}/web/sites/{{ item.1.name|default("default")}}/settings.php'
|
||||||
|
state: absent
|
||||||
|
with_subelements:
|
||||||
|
- '{{ drupal_settings }}'
|
||||||
|
- sites
|
||||||
|
|
||||||
|
- name: Link settings.php
|
||||||
|
file:
|
||||||
|
src: '/tmp/app/sites/{{ item.1.name|default("default")}}/settings.php'
|
||||||
|
dest: '{{ ansistrano_release_path.stdout }}/web/sites/{{ item.1.name|default("default")}}/settings.php'
|
||||||
|
state: link
|
||||||
|
with_subelements:
|
||||||
|
- '{{ drupal_settings }}'
|
||||||
|
- sites
|
||||||
|
```
|
||||||
|
|
BIN
source/images/me-phpnw-inviqa.jpg
Normal file
After Width: | Height: | Size: 47 KiB |
BIN
source/images/me-phpnw-inviqa.png
Normal file
After Width: | Height: | Size: 177 KiB |