diff --git a/README.md b/README.md index 924ab0c2179d7d54e605f371bbc1c8eed3e37da0..830782358e052ed7da44bb31697b61f55e55868e 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,15 @@ These Playbooks are designed to be used on Debian Stretch virtual servers. +## live2dev + +Ansible playbook to update the [dev site](https://dev.coops.tech/) from the [live site](https://www.coops.tech/). + +```bash +export SERVERNAME="webarch1.co.uk" +ansible-playbook live2dev.yml -i "${SERVERNAME}," -e "hostname=${SERVERNAME}" +``` + ## Discourse Ansible Playbooks to install diff --git a/live2dev.yml b/live2dev.yml new file mode 100644 index 0000000000000000000000000000000000000000..93cd45c68f19faba9807db648d4e281d0673d9ae --- /dev/null +++ b/live2dev.yml @@ -0,0 +1,13 @@ +--- +- name: Populate the dev site with the live data + hosts: "{{ hostname }}" + become: yes + + roles: + - live2dev + + vars: + distro: stretch + users: + - cotech + - cotechdev diff --git a/roles/live2dev/files/htaccess b/roles/live2dev/files/htaccess new file mode 100644 index 0000000000000000000000000000000000000000..02e68466860c0d940f57ab19f6f5d35ce6782c2e --- /dev/null +++ b/roles/live2dev/files/htaccess @@ -0,0 +1,35 @@ +# https://stackoverflow.com/a/10034368 +<FilesMatch "\.(ico|gif|jpg|png)$"> + ExpiresActive On + ExpiresDefault "access plus 11 month" + Header append Cache-Control "public" +</FilesMatch> +<FilesMatch "\.(css|js)$"> + ExpiresActive On + ExpiresDefault "access plus 1 week" + Header append Cache-Control "public" +</FilesMatch> + +# Redirect HTTP to HTTPS +# https://wiki.apache.org/httpd/RewriteHTTPToHTTPS +<IfModule mod_rewrite.c> + RewriteEngine on + RewriteCond %{HTTPS} !=on + RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L] +</IfModule> + +# STS Header +# https://stackoverflow.com/questions/24144552/how-to-set-hsts-header-from-htaccess-only-on-https +Header set Strict-Transport-Security "max-age=31536000" env=HTTPS + +# BEGIN WordPress +<IfModule mod_rewrite.c> +RewriteEngine On +RewriteBase / +RewriteRule ^index\.php$ - [L] +RewriteCond %{REQUEST_FILENAME} !-f +RewriteCond %{REQUEST_FILENAME} !-d +RewriteRule . /index.php [L] +</IfModule> + +# END WordPress diff --git a/roles/live2dev/tasks/main.yml b/roles/live2dev/tasks/main.yml new file mode 100644 index 0000000000000000000000000000000000000000..f3354b45be6e52c09ee3c43f47b782a09081123b --- /dev/null +++ b/roles/live2dev/tasks/main.yml @@ -0,0 +1,44 @@ +--- +- name: Update script in place + template: + src: templates/update.j2 + dest: "/home/{{ item }}/bin/update" + mode: 0755 + owner: "{{ item }}" + group: "{{ item }}" + with_items: "{{ users }}" + +- name: Git config in place + template: + src: templates/gitconfig.j2 + dest: "/home/{{ item }}/.gitconfig" + mode: 0644 + owner: "{{ item }}" + group: "{{ item }}" + with_items: "{{ users }}" + +- name: .htaccess file in place + copy: + src: files/htaccess + dest: "/home/{{ item }}/sites/web/.htaccess" + mode: 0644 + owner: "{{ item }}" + group: "{{ item }}" + with_items: "{{ users }}" + +- name: ~/bin in PATH + lineinfile: + regexp: '^export\ PATH=' + line: 'export PATH="$PATH:$HOME/bin"' + dest: "/home/{{ item }}/.bashrc" + state: present + with_items: "{{ users }}" + +- name: Live database dumped + shell: "mysqldump cotech > /home/cotech/private/cotech.sql" + +- name: Dev database overwritten with live data + shell: "cat /home/cotech/private/cotech.sql | mysql cotechdev" + +- name: Live files rsynced to dev + command: "rsync -aq --chown=cotechdev:cotechdev --chmod=D2775,F0664 /home/cotech/sites/web/app/uploads/ /home/cotechdev/sites/web/app/uploads/" diff --git a/roles/live2dev/templates/gitconfig.j2 b/roles/live2dev/templates/gitconfig.j2 new file mode 100644 index 0000000000000000000000000000000000000000..6a6c8ea6d666764c96c22699f91bcc038d1c2c36 --- /dev/null +++ b/roles/live2dev/templates/gitconfig.j2 @@ -0,0 +1,3 @@ +[user] + name = CoTech + email = {{ item }}@{{ hostname }} diff --git a/roles/live2dev/templates/update.j2 b/roles/live2dev/templates/update.j2 new file mode 100644 index 0000000000000000000000000000000000000000..491ab036a2ae45756466263407fbf3a02be757ac --- /dev/null +++ b/roles/live2dev/templates/update.j2 @@ -0,0 +1,20 @@ +#!/bin/bash + +if [[ "${USER}" != "{{ item }}" ]]; then + echo "This script should be run as {{ item }}, please sudo first" + echo "sudo -u {{ item }} -s /bin/bash" + echo "${0}" + exit +fi + +cd /home/{{ item }}/sites +git stash +git pull +rm -rf web/wp +composer update +cd web/app/themes/coop-tech-oowp-theme +composer update +npm install +nodejs ./node_modules/gulp/bin/gulp.js +cd ../../.. +wp core update-db