Commit 20b57a18 authored by Visay Keo's avatar Visay Keo

[FEATURE] Add support for dockertypo3

parent 82cae226
/config/master/* /config/master/*
\ No newline at end of file /ansible/hosts.ini
CHANGELOG CHANGELOG
========= =========
3.0.2
-----
- [FEATURE] Add support for dockertypo3
3.0.1 3.0.1
----- -----
......
## Introduction ## Introduction
This is a helper tool for fetch content from Flow Framework / Neos CMS installation on a remote server to your local This is a helper tool for fetch content from Flow Framework / Neos CMS / TYPO3 installation on a remote server to your
computer running with docker. local computer running with docker.
## Dependency ## Dependency
This is requires that your Flow Framework / Neos CMS installation is configured to run with `dockerflow` package This is requires that your Flow Framework / Neos CMS installation is configured to run with `dockerflow` package
(see https://github.com/Sebobo/Shel.DockerFlow) and all containers are started before executing the sync. (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.
## Installation ## Installation
...@@ -22,14 +25,13 @@ Add the `syncontent` package into your `composer.json` file and update `composer ...@@ -22,14 +25,13 @@ Add the `syncontent` package into your `composer.json` file and update `composer
In the root directory of your project, execute: In the root directory of your project, execute:
```bash ```bash
bin/syncontent --remote-user=demo-014-007 bin-dir/syncontent --remote-user=demo-014-007
``` ```
- Replace the user `demo-014-007` with the one you want to get content from - Replace the user `demo-014-007` with the server username you want to login and get content from
- You need to make sure that you have auto login with public key to `demo-014-007@YOUR_SERVER_HOSTNAME_OR_IP`. - You need to make sure that you have auto login with public key to `demo-014-007@YOUR_SERVER_HOSTNAME_OR_IP`.
The default host server is `10.10.10.27`, which is the internal web server The default host server is `10.10.10.27`, which is my internal web server
- You can define different server host with `--remote-host=YOUR_SERVER_HOSTNAME_OR_IP` argument - You can define your own server host with `--remote-host=YOUR_SERVER_HOSTNAME_OR_IP` argument
- 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 - You can only run the command from the root directory of your project
- The document root on the server will have to be at `/home/demo-014-007/public_html` - The document root on the server will have to be at `/home/demo-014-007/public_html`
- If you have a different document root path, you can overwrite the default with `--remote-path` argument - If you have a different document root path, you can overwrite the default with `--remote-path` argument
...@@ -37,13 +39,13 @@ The default host server is `10.10.10.27`, which is the internal web server ...@@ -37,13 +39,13 @@ The default host server is `10.10.10.27`, which is the internal web server
So the full overwriting way would be: So the full overwriting way would be:
```bash ```bash
bin/syncontent --remote-user=demo-014-007 --remote-host=10.10.10.37 --remote-path=/home/user/neosbox bin-dir/syncontent --remote-user=demo-014-007 --remote-host=10.10.10.37 --remote-path=/home/user/neosbox
``` ```
Or short form of the arguments: Or short form of the arguments:
```bash ```bash
bin/syncontent -u=demo-014-007 -h=10.10.10.37 -p=/home/user/neosbox bin-dir/syncontent -u=demo-014-007 -h=10.10.10.37 -p=/home/user/neosbox
``` ```
### Available arguments ### Available arguments
...@@ -51,8 +53,9 @@ bin/syncontent -u=demo-014-007 -h=10.10.10.37 -p=/home/user/neosbox ...@@ -51,8 +53,9 @@ bin/syncontent -u=demo-014-007 -h=10.10.10.37 -p=/home/user/neosbox
- `-u` | `--remote-user` : Set the login user to the remote server (__Required__) - `-u` | `--remote-user` : Set the login user to the remote server (__Required__)
- `-h` | `--remote-host` : Set the hostname or IP address of the remote server (__Default__: `10.10.10.27`) - `-h` | `--remote-host` : Set the hostname or IP address of the remote server (__Default__: `10.10.10.27`)
- `-p` | `--remote-path` : Set path to the document root on the remote server (__Default__: `/home/<remote-user>/public_html`) - `-p` | `--remote-path` : Set path to the document root on the remote server (__Default__: `/home/<remote-user>/public_html`)
- `-t` | `--ansible-tags`: Set the specific task you want run. See available sysc tasks section for details - `-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-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
- `-v` : Set the verbosity of ansible output. You can also set more verbose by adding more `v` like `-vvvvv` - `-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 - `--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 to see the full ansible command and maybe execute them directly for better error hints
...@@ -60,25 +63,25 @@ bin/syncontent -u=demo-014-007 -h=10.10.10.37 -p=/home/user/neosbox ...@@ -60,25 +63,25 @@ bin/syncontent -u=demo-014-007 -h=10.10.10.37 -p=/home/user/neosbox
### Customization ### Customization
If you are lazy typing the user again and again, you can define it permanently by creating a file in If you are lazy typing the user again and again, you can define it permanently by creating a file in
`Packages/Libraries/visay/syncontent/config/master` with the same name as the `--remote-user` value. `vendor-dir/visay/syncontent/config/master` with the same name as the `--remote-user` value.
``` ```
Packages vendor-dir
└── Libraries └── visay
└── visay └── syncontent
└── syncontent ├── ansible
├── ansible ├── bin
├── bin ├── config
├── composer.json │ └── master
├── config │ └── demo-014-007
│ └── master ├── CHANGELOG
│ └── demo-014-007 ├── composer.json
└── README.md └── README.md
``` ```
You can also overwrite the default value of `--remote-host`, `--remote-path` and `--remote-php` by setting it in the created master file. You can also overwrite the default value of `--remote-host`, `--remote-path`, `--remote-php`, etc, by setting it in the created master file.
```Packages/Libraries/visay/syncontent/config/master/demo-014-007 ```vendor-dir/visay/syncontent/config/master/demo-014-007
--remote-host=10.10.10.37 --remote-host=10.10.10.37
--remote-path=/home/user/neosbox --remote-path=/home/user/neosbox
--remote-php=/opt/php-versions/php55/bin/php --remote-php=/opt/php-versions/php55/bin/php
...@@ -87,7 +90,7 @@ You can also overwrite the default value of `--remote-host`, `--remote-path` and ...@@ -87,7 +90,7 @@ You can also overwrite the default value of `--remote-host`, `--remote-path` and
With this file and its content, you can now execute the content sync with just: With this file and its content, you can now execute the content sync with just:
```bash ```bash
bin/syncontent bin-dir/syncontent
``` ```
And the script will automatically take `demo-014-007` as the content master, `10.10.10.37` as server host and And the script will automatically take `demo-014-007` as the content master, `10.10.10.37` as server host and
...@@ -102,64 +105,90 @@ and you just need to define the `--remote-user` ...@@ -102,64 +105,90 @@ and you just need to define the `--remote-user`
### Available Sync Tasks ### Available Sync Tasks
Syncontent does its job in 3 different batches. First it sync the user files from remote server to local. Second it dumps syncontent does its job in 3 different batches. First it sync the user files from remote server to local. Second it dumps
the database from remote and restore on local and last it runs some necessary flow commands for clean up. the database from remote and restore on local and last it runs some necessary commands to clean up depends on the framework.
By default, syncontent will run all 3 tasks but you can pass the parameter to call specific task only that you want to run. By default, syncontent will run all 3 tasks but you can pass the parameter to call specific task only that you want to run.
```bash ```bash
bin/syncontent --ansible-tags=<TASK-NAME> bin-dir/syncontent --ansible-tags=<TASK-NAME>
``` ```
The available task names are: The available task names are:
- rsync - rsync
- db - db
- flow - cleanup
### 1. rsync ### 1. rsync
The first task is to sync directory content in `Data/Persistent/` from remote to local. Files that exists only in local The first task is to sync directory content from remote to local. Files that exists only in local will be removed
will be removed to make sure everything is exactly the same as on remote. to make sure everything is exactly the same as on remote.
For Flow, `Data/Persistent/` will be synced while for TYPO3 these directory will be synced:
- web/fileadmin/
- web/typo3conf/l10n/
- web/uploads/
The file/directory with the name `.gitkeep`, `_temp_` and `_processed_` will not be synced.
To execute this task only, run the command: To execute this task only, run the command:
```bash ```bash
bin/syncontent --ansible-tags=rsync bin-dir/syncontent --ansible-tags=rsync
``` ```
### 2. db ### 2. db
The second task is to reset the local database. It will start by connecting to remote server and get the database connection The second task is to reset the local database. For Flow Framework, it will start by connecting to remote server and
information for the Production context of Flow. You cannot change to other context at the moment so if your remote is not get the database connection information for the running context. You cannot change to other context at the moment so
running in Production context, this tool won't work for you but anyway tweaking it to work is not that hard if your remote is not running in Production context, this tool won't work for you but anyway tweaking it to work is
and you can do it in the ansible role. not that hard and you can do it in the ansible role.
Once it gets all the information, it will dump the database, zip it and download to local temp. Before restoring to local Once it gets all the information, it will dump the database, zip it and download to local temp. Before restoring to local
database, it first deletes the local database completely and recreate it again. This way assures that we have exact database, it first deletes the local database completely and recreate it again. This way assures that we have exact
state as on remote and prevent from any issues with the migration status. state as on remote and prevent from any issues with the database content leftover.
For TYPO3, the process is almost the same except that the first step of dumping the database doesn't exist but user
has to defined the location of the dump file on the remote server with the switch `--remote-dump`. That means
the process of creating dump file is manually created. That will change in the future release.
To execute this task only, run this command: To execute this task only, run this command:
```bash ```bash
bin/syncontent --ansible-tags=db bin-dir/syncontent --ansible-tags=db
``` ```
### 3. flow ### 3. cleanup
The last step is to run some necessary commands needed by the framework for the application to work.
The last step is to run some necessary commands needed in Flow for the application to work. They run in the following order: They run in the following order for Flow Framework:
- flow:cache:flush --force - flow:cache:flush --force
- database:setcharset - database:setcharset
- doctrine:migrate - doctrine:migrate
- resource:publish - resource:publish
- node:repair - cache:warmup
Add for TYPO3 CMS (`helhum/typo3-console` package is required for this part to run):
- cache:flush
- database:updateschema --schema-update-types=field.add
- database:updateschema --schema-update-types=field.change
- database:updateschema --schema-update-types=field.drop
- database:updateschema --schema-update-types=table.add
- database:updateschema --schema-update-types=table.change
- database:updateschema --schema-update-types=table.drop
- database:updateschema --schema-update-types=table.clear
- cleanup:updatereferenceindex
- cache:warmup - cache:warmup
To execute this task only, run this command: To execute this task only, run this command:
```bash ```bash
bin/syncontent --ansible-tags=flow bin-dir/syncontent --ansible-tags=cleanup
``` ```
## Author ## Author
......
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
localhost ansible_connection=local
[target]
remote ansible_ssh_host={{ HOST }} ansible_ssh_private_key_file=~/.ssh/id_rsa
--- ---
- hosts: "{{ stage }}" - hosts: "remote"
remote_user: "{{ ssh_user }}" remote_user: "{{ ssh_user }}"
roles: roles:
- role: rsync - role: rsync
tags: rsync tags: rsync
- role: database - role: database
tags: db tags: db
- role: flow - role: cleanup
tags: flow tags: cleanup
Flow Cleanup
==== =======
Execute necessary flow commands to setup the system. Execute necessary cleanup commands to finalize the system setup.
License License
------- -------
......
---
# defaults file for cleanup
---
# handlers file for cleanup
--- ---
galaxy_info: galaxy_info:
author: Visay Keo author: Visay Keo
description: Execute necessary flow commands to setup the system description: Execute necessary cleanup commands to finalize the system setup
company: Web Essentials company: Web Essentials
license: MIT license: MIT
min_ansible_version: 1.6 min_ansible_version: 1.6
......
--- ---
# tasks file for flow # tasks file for flow cleanup
- name: Remove PackageStates.php and temp caches directory - name: Remove PackageStates.php and temp caches directory
local_action: shell rm -rf Configuration/PackageStates.php Data/Temporary local_action: shell rm -rf Configuration/PackageStates.php Data/Temporary
chdir="{{ local_path }}" chdir="{{ local_path }}"
- name: Execute neccessary flow commands - name: Execute neccessary flow commands
local_action: shell FLOW_CONTEXT={{ local_flow_context }} bin/dockerflow run app ./flow {{ item }} local_action: shell FLOW_CONTEXT={{ local_context }} {{ bin_path }}/dockerflow run app ./flow {{ item }}
chdir="{{ local_path }}" chdir="{{ local_path }}"
with_items: with_items:
- flow:cache:flush --force - flow:cache:flush --force
- database:setcharset - database:setcharset
- doctrine:migrate - doctrine:migrate
- resource:publish - resource:publish
- node:repair
- cache:warmup - cache:warmup
---
# tasks file for database
- include: flow.yml
when: framework == "flow"
- include: typo3.yml
when: framework == "typo3"
---
# tasks file for typo3 cleanup
- name: Remove temp caches directory
local_action: shell rm -rf web/typo3temp/Cache
chdir="{{ local_path }}"
- name: Execute neccessary typo3 commands
local_action: shell TYPO3_CONTEXT={{ local_context }} {{ bin_path }}/dockertypo3 run app ./web/typo3cms {{ item }}
chdir="{{ local_path }}"
with_items:
- cache:flush
- database:updateschema --schema-update-types=field.add
- database:updateschema --schema-update-types=field.change
- database:updateschema --schema-update-types=field.drop
- database:updateschema --schema-update-types=table.add
- database:updateschema --schema-update-types=table.change
- database:updateschema --schema-update-types=table.drop
- database:updateschema --schema-update-types=table.clear
- cleanup:updatereferenceindex
- cache:warmup
---
# vars file for cleanup
---
# 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"
- 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
chdir="{{ local_path }}"
register: local_db_name
- name: Drop local database
local_action: shell {{ bin_path }}/dockerflow run db mysqladmin -h db -u root -proot drop {{ local_db_name.stdout }} -f
chdir="{{ local_path }}"
- name: Re-create local database
local_action: shell {{ bin_path }}/dockerflow run db mysqladmin -h db -u root -proot create {{ local_db_name.stdout }} --default-character-set=utf8
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
chdir="{{ local_path }}"
--- ---
# tasks file for database # tasks file for database
- name: Read remote database info (FLOW_CONTEXT=Production) - include: flow.yml
shell: FLOW_CONTEXT=Production {{ remote_php | default('') }} ./flow configuration:show --type Settings --path TYPO3.Flow.persistence.backendOptions chdir="{{ remote_path }}" when: framework == "flow"
register: db_info
- name: Get remote database host - include: typo3.yml
shell: echo "{{ db_info.stdout }}" | grep "host:" | cut -d ' ' -f2 when: framework == "typo3"
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 FLOW_CONTEXT={{ local_flow_context }} bin/dockerflow run -T app ./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
local_action: shell bin/dockerflow run db mysqladmin -h db -u root -proot drop {{ local_db_name.stdout }} -f
chdir="{{ local_path }}"
- name: Re-create local database
local_action: shell bin/dockerflow run db mysqladmin -h db -u root -proot 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 -proot {{ local_db_name.stdout }} < /tmp/{{ db_name.stdout }}.sql
chdir="{{ local_path }}"
---
# tasks file for typo3 database
- name: Sync remote database dump to local temp
synchronize: mode=pull src="{{ remote_dump }}" dest="/tmp/{{ ssh_user }}.sql"
- name: Drop local database
local_action: shell {{ bin_path }}/dockertypo3 run db mysqladmin -h db -u root -proot drop dockertypo3 -f
chdir="{{ local_path }}"
- name: Re-create local database
local_action: shell {{ bin_path }}/dockertypo3 run db mysqladmin -h db -u root -proot create dockertypo3 --default-character-set=utf8
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
chdir="{{ local_path }}"
--- ---
# tasks file for rsync # tasks file for rsync
- name: Sync persistent data from remote server to local - name: Sync flow persistent data from remote server to local
synchronize: mode=pull synchronize: mode=pull
src="{{ remote_path }}/Data/Persistent/" src="{{ remote_path }}/{{ item }}"
dest="{{ local_path }}/Data/Persistent/" dest="{{ local_path }}/{{ item }}"
delete=yes delete=yes
with_items:
- Data/Persistent/
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/
when: framework == "typo3"
...@@ -2,7 +2,11 @@ ...@@ -2,7 +2,11 @@
# Set static variables # Set static variables
ROOT_DIR=`pwd` ROOT_DIR=`pwd`
PACKAGE_DIR="${ROOT_DIR}/Packages/Libraries/visay/syncontent" DIR_NAME=$(dirname "$0")
FILE_NAME=$(basename "$0")
BINARY=`readlink -f ${ROOT_DIR}/${DIR_NAME}/${FILE_NAME}`
BIN_PATH=${BINARY%/*}
PACKAGE_DIR=${BIN_PATH%/*}
# Colors # Colors
RED="\033[0;31m" RED="\033[0;31m"
...@@ -13,6 +17,30 @@ NC="\033[0m" ...@@ -13,6 +17,30 @@ NC="\033[0m"
echo echo
# Detect framework environment
if (cat ${ROOT_DIR}/composer.lock | grep "dockerflow" > /dev/null); then
FRAMEWORK="flow"
DATA_DIR="Data/Persistent"
# Use Development context if Flow Context is not set
FRAMEWORK_CONTEXT=${FLOW_CONTEXT:=Development}
fi
if (cat ${ROOT_DIR}/composer.lock | grep "dockertypo3" > /dev/null); then
FRAMEWORK="typo3"
DATA_DIR="web/uploads"
# Use Development context if TYPO3 Context is not set
FRAMEWORK_CONTEXT=${TYPO3_CONTEXT:=Development}
fi
# If framework is not set anywhere, throw error
if [ -z "${FRAMEWORK}" ]; then
echo -e ${RED}"-> Framework cannot be detected:"${NC}
echo
echo -e ${BROWN}"syncontent requires the system to run with shel/dockerflow or visay/dockertypo3"${NC}
echo
exit 1
fi
# Read all arguments and parse into variable ${REMOTE_USER}, ${REMOTE_PATH} and ${REMOTE_HOST} # Read all arguments and parse into variable ${REMOTE_USER}, ${REMOTE_PATH} and ${REMOTE_HOST}
for ARGS in "$@" for ARGS in "$@"
do do
...@@ -37,6 +65,10 @@ do ...@@ -37,6 +65,10 @@ do
REMOTE_PHP="${ARGS#*=}" REMOTE_PHP="${ARGS#*=}"
shift shift
;; ;;
--remote-dump=*)
REMOTE_DUMP="${ARGS#*=}"
shift
;;
-v*) -v*)
VERBOSE_LEVEL="${ARGS}" VERBOSE_LEVEL="${ARGS}"
shift shift
...@@ -57,8 +89,8 @@ fi ...@@ -57,8 +89,8 @@ fi
if [ -z "${REMOTE_USER}" ]; then if [ -z "${REMOTE_USER}" ]; then
echo -e ${RED}"-> Please specify the user of the remote server to sync from:"${NC} echo -e ${RED}"-> Please specify the user of the remote server to sync from:"${NC}
echo echo
echo -e ${BROWN}"Example: bin/syncontent --remote-user=latest-014-007"${NC} echo -e ${BROWN}"Example: ${DIR_NAME}/${FILE_NAME} --remote-user=latest-014-007"${NC}
echo -e ${BROWN}"Example: bin/syncontent -u=demo-014-007"${NC} echo -e ${BROWN}"Example: ${DIR_NAME}/${FILE_NAME} -u=demo-014-007"${NC}
echo echo
echo -e ${BROWN}"Or specify it in config/master directory, read the doc"${NC} echo -e ${BROWN}"Or specify it in config/master directory, read the doc"${NC}
echo echo
...@@ -67,17 +99,6 @@ fi ...@@ -67,17 +99,6 @@ fi
# Extract from the remote user to get the stage name # Extract from the remote user to get the stage name
MASTER_FILE="${PACKAGE_DIR}/config/master/${REMOTE_USER}" MASTER_FILE="${PACKAGE_DIR}/config/master/${REMOTE_USER}"
STAGE=`echo ${REMOTE_USER} | cut -d '-' -f1`
# Check if stage is not latest or demo, throw error
if [ "${STAGE}" != "latest" ] && [ "${STAGE}" != "demo" ]; then
echo -e ${RED}"-> Only latest or demo is supported at the moment:"${NC}
echo
echo -e ${BROWN}"Example: bin/syncontent -u=latest-014-007"${NC}
echo -e ${BROWN}"Example: bin/syncontent --remote-user=demo-014-007"${NC}
echo
exit 1
fi
# If remote host is not set, read it from config file # If remote host is not set, read it from config file
if [ -z "${REMOTE_HOST}" ]; then if [ -z "${REMOTE_HOST}" ]; then
...@@ -128,6 +149,11 @@ if [ -z "${REMOTE_PATH}" ]; then ...@@ -128,6 +149,11 @@ if [ -z "${REMOTE_PATH}" ]; then
fi fi
fi fi
# If remote path is not defined anywhere, set a standard value
if [ -z "${REMOTE_PATH}" ]; then
REMOTE_PATH="/home/${REMOTE_USER}/public_html"
fi
# If remote php is not set in argument, check for it in the configuration file # If remote php is not set in argument, check for it in the configuration file
if [ -z "${REMOTE_PHP}" ]; then if [ -z "${REMOTE_PHP}" ]; then
if [ -f "${MASTER_FILE}" ]; then if [ -f "${MASTER_FILE}" ]; then
...@@ -145,22 +171,57 @@ if [ -z "${REMOTE_PHP}" ]; then ...@@ -145,22 +171,57 @@ if [ -z "${REMOTE_PHP}" ]; then
fi fi
fi fi
# If remote path is not defined anywhere, set a standard value if [ "${FRAMEWORK}" == "flow" ]; then
if [ -z "${REMOTE_PATH}" ]; then REMOTE_DUMP="/tmp"
REMOTE_PATH="/home/${REMOTE_USER}/public_html" fi
if [ "${FRAMEWORK}" == "typo3" ]; then
if [ -z "${REMOTE_DUMP}" ]; then
if [ -f "${MASTER_FILE}" ]; then
IFS=$'\n'
for LINE in `cat ${MASTER_FILE}`
do
LINE=${LINE//[[:blank:]]/}
case ${LINE} in
--remote-dump=*)
REMOTE_DUMP="${LINE#*=}"
shift
;;
esac
done
fi
fi
if [ -z "${REMOTE_DUMP}" ]; then
echo -e ${RED}"-> Please specify the path to sql dump on remote servers:"${NC}
echo
echo -e ${BROWN}"Example: ${DIR_NAME}/${FILE_NAME} --remote-dump=/tmp/dump/my-db.sql"${NC}
echo
echo -e ${BROWN}"Or specify it in config/master directory, read the doc"${NC}
echo
exit 1
fi
if (ssh ${REMOTE_USER}@${REMOTE_HOST} "[ ! -f ${REMOTE_DUMP} ]"); then
echo -e ${RED}"-> Please make sure the dump file at ${REMOTE_DUMP} exists on remote server"${NC}
echo
exit 1
fi
fi fi
# Check if persistent directory exists at the remote path on the server # Check if data directory exists at the remote path on the server
if (ssh ${REMOTE_USER}@${REMOTE_HOST} "[ ! -d ${REMOTE_PATH}/Data/Persistent ]"); then if (ssh ${REMOTE_USER}@${REMOTE_HOST} "[ ! -d ${REMOTE_PATH}/${DATA_DIR} ]"); then
echo -e ${RED}"-> Directory '${REMOTE_PATH}/Data/Persistent' does not exist on the server"${NC} echo -e ${RED}"-> Directory '${REMOTE_PATH}/${DATA_DIR}' does not exist on the server running ${FRAMEWORK}"${NC}
echo echo
echo -e ${BROWN}"Check if your '--remote-path' config is set properly"${NC} echo -e ${BROWN}"Check if your '--remote-path' config is set properly"${NC}
echo echo
exit 1 exit 1
fi fi
# Use Development context if Flow Context is not set # Create dynamic inventory file
FLOW_CONTEXT=${FLOW_CONTEXT:=Development} rm -f ${PACKAGE_DIR}/ansible/hosts.ini
cp ${PACKAGE_DIR}/ansible/hosts.ini.template ${PACKAGE_DIR}/ansible/hosts.ini
sed -i "s/{{ HOST }}/${REMOTE_HOST}/g" ${PACKAGE_DIR}/ansible/hosts.ini
# Prepare all parameters for ansible # Prepare all parameters for ansible
ANSIBLE_PARAMS="-i ${PACKAGE_DIR}/ansible/hosts.ini ${PACKAGE_DIR}/ansible/playbook.yml" ANSIBLE_PARAMS="-i ${PACKAGE_DIR}/ansible/hosts.ini ${PACKAGE_DIR}/ansible/playbook.yml"
...@@ -172,19 +233,22 @@ if [ -n "${ANSIBLE_TAGS}" ]; then ...@@ -172,19 +233,22 @@ if [ -n "${ANSIBLE_TAGS}" ]; then
fi fi
# Prepare all parameters for ansible extra vars # Prepare all parameters for ansible extra vars
ANSIBLE_EXTRA_VARS="stage=${STAGE} ssh_user=${REMOTE_USER} local_path=${ROOT_DIR} remote_path=${REMOTE_PATH} local_flow_context=${FLOW_CONTEXT}" ANSIBLE_EXTRA_VARS="stage=remote ssh_user=${REMOTE_USER} local_path=${ROOT_DIR} remote_path=${REMOTE_PATH} bin_path=${DIR_NAME} remote_dump=${REMOTE_DUMP} local_context=${FRAMEWORK_CONTEXT} framework=${FRAMEWORK}"
if [ -n "${REMOTE_PHP}" ]; then if [ -n "${REMOTE_PHP}" ]; then
ANSIBLE_EXTRA_VARS="${ANSIBLE_EXTRA_VARS} remote_php=${REMOTE_PHP}" ANSIBLE_EXTRA_VARS="${ANSIBLE_EXTRA_VARS} remote_php=${REMOTE_PHP}"
fi fi
echo -e ${GREEN}"ENVIRONMENT SUMMARY:"${NC} echo -e ${GREEN}"ENVIRONMENT SUMMARY:"${NC}
echo "=====================" echo "======================="
echo -e "FROM: ${GREEN}${REMOTE_USER}${NC}" echo -e "FRAMEWORK: ${GREEN}${FRAMEWORK}${NC}"
echo -e "CONTEXT: ${GREEN}Production${NC}" echo "-----------------------"
echo "---------------------" echo -e "FROM: ${GREEN}${REMOTE_USER}${NC}"
echo -e "TO: ${GREEN}Local Docker${NC}" echo -e "ON: ${GREEN}${REMOTE_HOST}${NC}"
echo -e "CONTEXT: ${GREEN}${FLOW_CONTEXT}${NC}" echo -e "CONTEXT: ${GREEN}Production${NC}"
echo "---------------------" echo "-----------------------"
echo -e "TO: ${GREEN}Local Docker${NC}"
echo -e "CONTEXT: ${GREEN}${FRAMEWORK_CONTEXT}${NC}"
echo "-----------------------"
echo echo
if [[ -n "${DRY_RUN}" ]]; then if [[ -n "${DRY_RUN}" ]]; then
......
...@@ -10,10 +10,11 @@ ...@@ -10,10 +10,11 @@
"role": "Developer" "role": "Developer"
} }
], ],
"require": { "suggest": {
"shel/dockerflow": "*" "shel/dockerflow": "*",
"visay/dockertypo3": "*"
}, },
"bin": [ "bin": [
"bin/syncontent" "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