Commit e5608dba authored by Visay Keo's avatar Visay Keo

[FEATURE] Introduce --from-cache switch

parent cd9fb23c
CHANGELOG
=========
3.0.6
-----
- [FEATURE] Introduce --from-cache switch
3.0.5
-----
......
......@@ -9,7 +9,7 @@ This is requires that your Flow Framework / Neos CMS installation is configured
(see https://github.com/Sebobo/Shel.DockerFlow) or your TYPO3 installation is configured to run with `dockertypo3`
package (see https://github.com/visay/DockerTYPO3) and all containers are started before executing the sync.
Ansible is needed on your local installation machine.
Ansible is needed on your local machine.
## Installation
......@@ -56,6 +56,7 @@ bin-dir/syncontent -u=demo-014-007 -h=10.10.10.37 -p=/home/user/neosbox
- `-t` | `--ansible-tags`: Set the specific task you want run. See available sync tasks section for details
- `--remote-php` : Set the path to php on the remote server
- `--remote-dump` : Set the sql dump location on the remote server. It must contain the absolute path and filename
- `--from-cache` : Use local caches of files and database dump from previous run instead of getting fresh from remote
- `-v` : Set the verbosity of ansible output. You can also set more verbose by adding more `v` like `-vvvvv`
- `--dry-run` : Force to display the command to execute but won't run them. Useful for debugging when you want
to see the full ansible command and maybe execute them directly for better error hints
......@@ -172,7 +173,7 @@ They run in the following order for Flow Framework:
- resource:publish
- cache:warmup
Add for TYPO3 CMS (`helhum/typo3-console` package is required for this part to run):
And for TYPO3 CMS (`helhum/typo3-console` package is required for this part to run):
- cache:flush
- database:updateschema --schema-update-types=field.add
......
---
# tasks file for flow database
- name: Read remote database info (FLOW_CONTEXT=Production)
shell: FLOW_CONTEXT=Production {{ remote_php | default('') }} ./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={{ remote_dump }}/{{ db_name.stdout }}.sql
encoding=utf8
collation=utf8_unicode_ci
- name: Sync remote database dump to local temp
synchronize: mode=pull src="/{{ remote_dump }}/{{ db_name.stdout }}.sql" dest="/tmp/{{ db_name.stdout }}.sql"
- include: flow_db_dump.yml
when: not from_cache|bool
- name: Check local database name
local_action: shell FLOW_CONTEXT={{ local_context }} {{ bin_path }}/dockerflow run -T app ./flow configuration:show --type Settings --path TYPO3.Flow.persistence.backendOptions | grep 'dbname' | cut -d ' ' -f2
......@@ -48,5 +18,5 @@
chdir="{{ local_path }}"
- name: Restore local database from remote dump
local_action: shell {{ bin_path }}/dockerflow run db mysql -h db -u root -proot {{ local_db_name.stdout }} < /tmp/{{ db_name.stdout }}.sql
local_action: shell {{ bin_path }}/dockerflow run db mysql -h db -u root -proot {{ local_db_name.stdout }} < /tmp/{{ ssh_user }}/db_dump.sql
chdir="{{ local_path }}"
---
# tasks file for flow database
- name: Read remote database info (FLOW_CONTEXT=Production)
shell: FLOW_CONTEXT=Production {{ remote_php | default('') }} ./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={{ remote_dump }}/{{ db_name.stdout }}.sql
encoding=utf8
collation=utf8_unicode_ci
- name: Sync remote database dump to local temp
synchronize: mode=pull src="/{{ remote_dump }}/{{ db_name.stdout }}.sql" dest="/tmp/{{ ssh_user }}/db_dump.sql"
---
# tasks file for database
- include: flow.yml
- include: flow.yml
when: framework == "flow"
- include: typo3.yml
- include: typo3.yml
when: framework == "typo3"
......@@ -2,7 +2,8 @@
# tasks file for typo3 database
- name: Sync remote database dump to local temp
synchronize: mode=pull src="{{ remote_dump }}" dest="/tmp/{{ ssh_user }}.sql"
synchronize: mode=pull src="{{ remote_dump }}" dest="/tmp/{{ ssh_user }}/db_dump.sql"
when: not from_cache|bool
- name: Drop local database
local_action: shell {{ bin_path }}/dockertypo3 run db mysqladmin -h db -u root -proot drop dockertypo3 -f
......@@ -13,5 +14,5 @@
chdir="{{ local_path }}"
- name: Restore local database from remote dump
local_action: shell {{ bin_path }}/dockertypo3 run db mysql -h db -u root -proot dockertypo3 < /tmp/{{ ssh_user }}.sql
local_action: shell {{ bin_path }}/dockertypo3 run db mysql -h db -u root -proot dockertypo3 < /tmp/{{ ssh_user }}/db_dump.sql
chdir="{{ local_path }}"
---
# tasks file for rsync
- name: Make sure local temp directory exists
local_action: file path="/tmp/{{ ssh_user }}/{{ item }}" state=directory
with_items:
- Data/Persistent/
- name: Sync flow persistent data from remote server to local temp
synchronize: mode=pull
src="{{ remote_path }}/{{ item }}"
dest="/tmp/{{ ssh_user }}/{{ item }}"
delete=yes
with_items:
- Data/Persistent/
when: not from_cache|bool
- name: Sync flow persistent data from local temp to working directory
local_action: synchronize src="/tmp/{{ ssh_user }}/{{ item }}"
dest="{{ local_path }}/{{ item }}"
delete=yes
with_items:
- Data/Persistent/
---
# tasks file for rsync
- name: Sync flow persistent data from remote server to local
synchronize: mode=pull
src="{{ remote_path }}/{{ item }}"
dest="{{ local_path }}/{{ item }}"
delete=yes
with_items:
- Data/Persistent/
- include: flow.yml
when: framework == "flow"
- name: Sync typo3 data from remote server to local
synchronize: mode=pull
src="{{ remote_path }}/{{ item }}"
dest="{{ local_path }}/{{ item }}"
delete=yes
rsync_opts="--exclude=.gitkeep --exclude=_temp_ --exclude=_processed_"
with_items:
- web/fileadmin/
- web/typo3conf/l10n/
- web/uploads/
- include: typo3.yml
when: framework == "typo3"
---
# tasks file for rsync
- name: Make sure local temp directory exists
local_action: file path="/tmp/{{ ssh_user }}/{{ item }}" state=directory
with_items:
- web/fileadmin/
- web/typo3conf/l10n/
- web/uploads/
- name: Sync typo3 data from remote server to local temp
synchronize: mode=pull
src="{{ remote_path }}/{{ item }}"
dest="/tmp/{{ ssh_user }}/{{ item }}"
delete=yes
rsync_opts="--exclude=.gitkeep --exclude=_temp_ --exclude=_processed_"
with_items:
- web/fileadmin/
- web/typo3conf/l10n/
- web/uploads/
when: not from_cache|bool
- name: Sync typo3 data from local temp to working directory
local_action: synchronize src="/tmp/{{ ssh_user }}/{{ item }}"
dest="{{ local_path }}/{{ item }}"
delete=yes
rsync_opts="--exclude=.gitkeep --exclude=_temp_ --exclude=_processed_"
with_items:
- web/fileadmin/
- web/typo3conf/l10n/
- web/uploads/
......@@ -77,6 +77,10 @@ do
REMOTE_DUMP="${ARGS#*=}"
shift
;;
--from-cache)
FROM_CACHE="${ARGS}"
shift
;;
-v*)
VERBOSE_LEVEL="${ARGS}"
shift
......@@ -244,14 +248,23 @@ ANSIBLE_EXTRA_VARS="stage=remote ssh_user=${REMOTE_USER} local_path=${ROOT_DIR}
if [ -n "${REMOTE_PHP}" ]; then
ANSIBLE_EXTRA_VARS="${ANSIBLE_EXTRA_VARS} remote_php=${REMOTE_PHP}"
fi
if [[ -n "${FROM_CACHE}" ]]; then
ANSIBLE_EXTRA_VARS="${ANSIBLE_EXTRA_VARS} from_cache=yes"
else
ANSIBLE_EXTRA_VARS="${ANSIBLE_EXTRA_VARS} from_cache=no"
fi
echo -e ${GREEN}"ENVIRONMENT SUMMARY:"${NC}
echo "======================="
echo -e "FRAMEWORK: ${GREEN}${FRAMEWORK}${NC}"
echo "-----------------------"
echo -e "FROM: ${GREEN}${REMOTE_USER}${NC}"
echo -e "ON: ${GREEN}${REMOTE_HOST}${NC}"
echo -e "CONTEXT: ${GREEN}Production${NC}"
if [[ -n "${FROM_CACHE}" ]]; then
echo -e "FROM: ${GREEN}Local Caches${NC}"
else
echo -e "FROM: ${GREEN}${REMOTE_USER}${NC}"
echo -e "ON: ${GREEN}${REMOTE_HOST}${NC}"
echo -e "CONTEXT: ${GREEN}Production${NC}"
fi
echo "-----------------------"
echo -e "TO: ${GREEN}Local Docker${NC}"
echo -e "CONTEXT: ${GREEN}${FRAMEWORK_CONTEXT}${NC}"
......
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