Commit 24883e2a authored by Visay Keo's avatar Visay Keo

[TASK] Initial import

parents
# Introduction
This is a helper tool for fetch content from TYPO3 Flow / Neos installation on a remote server to your local computer running with docker.
# Dependency
This is requires that your TYPO3 Flow / Neos installation is configured to run with `dockerflow` package. See https://github.com/Sebobo/Shel.DockerFlow
# Installation
Add the `syncontent` package into your `composer.json` file and update `composer.lock`. It is recommended to add in the `require-dev` section of your composer.
```
"visay/syncontent": "dev-master"
```
# Usage
In the root directory of your project, execute:
```bash
bin/syncontent latest-014-073
```
- Replace the user `latest-014-073` with the one you want to get content from.
- You need to make sure that you have auto login with public key to `latest-014-073@10.10.10.27`
- Only `latest` or `demo` is supported at the moment. We don't recommend you to have autologin access to the live site
- You can only run the command from the root directory of your project
## Customization
If you are lazy typing the user again and again, you can define it by creating a file at `Configuration/.syncontent` with the user as the only content inside
```Configuration/.syncontent
latest-014-073
```
With this file, you can now execute the content sync with just:
```bash
bin/syncontent
```
# Author
Visay Keo <visay@web-essentials.asia>
If you have any feedback, comments and/or questions, feel free to contact with email address above. And of course, a merge request is always welcome.
\ No newline at end of file
localhost ansible_connection=local
[joel]
latest ansible_ssh_host=10.10.10.27 ansible_ssh_private_key_file=~/.ssh/id_rsa
demo ansible_ssh_host=10.10.10.27 ansible_ssh_private_key_file=~/.ssh/id_rsa
\ No newline at end of file
---
- hosts: "{{ stage }}"
remote_user: "{{ ssh_user }}"
roles:
- role: rsync
- role: database
\ No newline at end of file
Database
========
Dump database from remote machine to local.
License
-------
MIT
Author Information
------------------
Visay Keo <visay@web-essentials.asia>
---
# defaults file for database
---
# handlers file for database
---
galaxy_info:
author: Visay Keo
description: Dump database from remote machine to local
company: Web Essentials
license: MIT
min_ansible_version: 1.6
platforms:
- name: Ubuntu
versions:
- trusty
dependencies: []
---
# tasks file for database
- name: Read remote database information (FLOW_CONTEXT=Production)
shell: FLOW_CONTEXT=Production ./flow configuration:show --type Settings --path TYPO3.Flow.persistence.backendOptions chdir="{{ remote_path }}"
register: db_info
- name: Get remote database host
shell: echo "{{ db_info.stdout }}" | grep "host:" | cut -d ' ' -f2
register: db_host
- name: Get remote database name
shell: echo "{{ db_info.stdout }}" | grep "dbname:" | cut -d ' ' -f2
register: db_name
- name: Get remote database user
shell: echo "{{ db_info.stdout }}" | grep "user:" | cut -d ' ' -f2
register: db_user
- name: Get remote database password
shell: echo "{{ db_info.stdout }}" | grep "password:" | cut -d ' ' -f2
register: db_pass
- name: Dump remote database
mysql_db: login_host="{{ db_host.stdout }}"
login_user="{{ db_user.stdout }}"
login_password="{{ db_pass.stdout }}"
name="{{ db_name.stdout }}"
state=dump
target=/tmp/{{ db_name.stdout }}.sql
encoding=utf8
collation=utf8_unicode_ci
- name: Sync remote database dump to local temp
synchronize: mode=pull src="/tmp/{{ db_name.stdout }}.sql" dest="/tmp/{{ db_name.stdout }}.sql"
- name: Check local database name
local_action: shell bin/dockerflow run -T app /var/www/flow configuration:show --type Settings --path TYPO3.Flow.persistence.backendOptions | grep 'dbname' | cut -d ' ' -f2
chdir="{{ local_path }}"
register: local_db_name
- name: Drop local database (TODO)
local_action: shell bin/dockerflow run db mysqladmin -h db -u root drop {{ local_db_name.stdout }} -f
chdir="{{ local_path }}"
- name: Re-create local database (TODO)
local_action: shell bin/dockerflow run db mysqladmin -h db -u root create {{ local_db_name.stdout }} --default-character-set=utf8
chdir="{{ local_path }}"
- name: Restore local database from remote dump
local_action: shell bin/dockerflow run db mysql -h db -u root {{ local_db_name.stdout }} < /tmp/{{ db_name.stdout }}.sql
chdir="{{ local_path }}"
- name: Execute ./flow flow:cache:flush --force
local_action: shell bin/dockerflow run app /var/www/flow flow:cache:flush --force
chdir="{{ local_path }}"
- name: Execute ./flow cache:warmup
local_action: shell bin/dockerflow run app /var/www/flow cache:warmup
chdir="{{ local_path }}"
---
# vars file for database
Rsync
=====
Sync resources from remote machine to local.
License
-------
MIT
Author Information
------------------
Visay Keo <visay@web-essentials.asia>
---
# defaults file for rsync
---
# handlers file for rsync
---
galaxy_info:
author: Visay Keo
description: Sync resources from remote machine to local
company: Web Essentials
license: MIT
min_ansible_version: 1.6
platforms:
- name: Ubuntu
versions:
- trusty
dependencies: []
---
# tasks file for rsync
- name: Sync persistent data from remote server to local
synchronize: mode=pull src="{{ remote_path }}/Data/Persistent/" dest="{{ local_path }}/Data/Persistent/"
\ No newline at end of file
---
# vars file for rsync
#!/bin/bash
ARG=$1
ROOT_DIR=`pwd`
PACKAGE_DIR="${ROOT_DIR}/Packages/Libraries/visay/syncontent"
if [ -z "${ARG}" ]; then
MASTER=`cat ${ROOT_DIR}/Configuration/.syncontent | tr -d ' ' | tr -d '\n' | tr -d '\r' | tr -d '\t'`
else
MASTER="${ARG}"
fi
if [ -z "${MASTER}" ]; then
echo "Please specify the server to sync from:"
echo "Example: bin/syncontent latest-014-073"
echo "Example: bin/syncontent demo-014-073"
echo "Or specify it in Configuration/.syncontent"
exit 0
fi
STAGE=`echo ${MASTER} | cut -d '-' -f1`
if [ "${STAGE}" != "latest" ] && [ "${STAGE}" != "demo" ]; then
echo "Only latest or demo is supported at the moment:"
echo "Example: bin/syncontent latest-014-073"
echo "Example: bin/syncontent demo-014-073"
exit 0
fi
SSH_USER="${MASTER}"
SSH_HOST="10.10.10.27"
PING=`ssh -q -o "BatchMode=yes" ${SSH_USER}@${SSH_HOST} echo "OK"`
if [ "${PING}" != "OK" ]; then
echo "Public key authentication failed!"
echo "Make sure you have auto login when running: ssh ${SSH_USER}@${SSH_HOST}"
exit 0
fi
echo "Start content sync from ${SSH_USER} to local"
ansible-playbook -i ${PACKAGE_DIR}/ansible/hosts.ini ${PACKAGE_DIR}/ansible/playbook.yml \
--extra-vars "stage=${STAGE}
ssh_user=${SSH_USER}
local_path=${ROOT_DIR}
remote_path=/home/${SSH_USER}/public_html"
echo "Sync content from ${STAGE} completed!"
{
"name": "visay/syncontent",
"description": "Fetch site content from remote server to local.",
"license": "MIT",
"authors": [
{
"name": "Visay Keo",
"email": "visay@web-essentials.asia",
"homepage": "http://www.web-essentials.asia",
"role": "Developer"
}
],
"require": {
"shel/dockerflow": "*"
},
"bin": [
"bin/syncontent"
]
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment