Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
syncontent
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Web Essentials Jira
Web Essentials Jira
Labels
Merge Requests
0
Merge Requests
0
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
Visay Keo
syncontent
Commits
e772d84a
Commit
e772d84a
authored
Sep 03, 2015
by
Visay Keo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[IMP] Add more useful params with nicer message
parent
a83acfa3
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
226 additions
and
43 deletions
+226
-43
CHANGELOG
CHANGELOG
+6
-0
README.md
README.md
+66
-0
ansible/playbook.yml
ansible/playbook.yml
+5
-1
ansible/roles/database/tasks/main.yml
ansible/roles/database/tasks/main.yml
+0
-16
ansible/roles/flow/README.md
ansible/roles/flow/README.md
+14
-0
ansible/roles/flow/defaults/main.yml
ansible/roles/flow/defaults/main.yml
+2
-0
ansible/roles/flow/handlers/main.yml
ansible/roles/flow/handlers/main.yml
+2
-0
ansible/roles/flow/meta/main.yml
ansible/roles/flow/meta/main.yml
+12
-0
ansible/roles/flow/tasks/main.yml
ansible/roles/flow/tasks/main.yml
+17
-0
ansible/roles/flow/vars/main.yml
ansible/roles/flow/vars/main.yml
+2
-0
ansible/roles/rsync/tasks/main.yml
ansible/roles/rsync/tasks/main.yml
+4
-1
bin/syncontent
bin/syncontent
+96
-25
No files found.
CHANGELOG
View file @
e772d84a
...
@@ -4,6 +4,12 @@ CHANGELOG
...
@@ -4,6 +4,12 @@ CHANGELOG
3.0-dev
3.0-dev
---------
---------
-
3.0.0
-----
- [IMP] Add more useful params with nicer message
- [TASK] Update example in README
- [TASK] Update example in README
- [IMP] Add flow command resource:publish
- [IMP] Add flow command resource:publish
...
...
README.md
View file @
e772d84a
...
@@ -51,6 +51,10 @@ bin/syncontent -u=demo-014-007 -h=10.10.10.37 -p=/home/user/neosbox
...
@@ -51,6 +51,10 @@ 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
-
`-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
### Customization
### Customization
...
@@ -94,6 +98,68 @@ directory. In case there are more than one file exists, the script will take fir
...
@@ -94,6 +98,68 @@ directory. In case there are more than one file exists, the script will take fir
-
In most case, the default host and path work fine for internal Web Essentials project development
-
In most case, the default host and path work fine for internal Web Essentials project development
and you just need to define the
`--remote-user`
and you just need to define the
`--remote-user`
### 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
the database from remote and restore on local and last it runs some necessary flow commands for clean up.
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
bin/syncontent
--ansible-tags
=
<TASK-NAME>
```
The available task names are:
-
rsync
-
db
-
flow
### 1. rsync
The first task is to sync directory content in
`Data/Persistent/`
from remote to local. Files that exists only in local
will be removed to make sure everything is exactly the same as on remote.
To execute this task only, run the command:
```
bash
bin/syncontent
--ansible-tags
=
rsync
```
### 2. db
The second task is to reset the local database. It will start by connecting to remote server and get the database connection
information for the Production context of Flow. You cannot change to other context at the moment so if your remote is not
running in Production context, this tool won't work for you but anyway tweaking it to work is 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
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.
To execute this task only, run this command:
```
bash
bin/syncontent
--ansible-tags
=
db
```
### 3. flow
The last step is to run some necessary commands needed in Flow for the application to work. They run in the following order:
-
flow:cache:flush --force
-
database:setcharset
-
doctrine:migrate
-
resource:publish
-
node:repair
-
cache:warmup
To execute this task only, run this command:
```
bash
bin/syncontent
--ansible-tags
=
flow
```
## Author
## Author
Visay Keo
<visay@web-essentials.asia>
Visay Keo
<visay@web-essentials.asia>
...
...
ansible/playbook.yml
View file @
e772d84a
...
@@ -4,4 +4,8 @@
...
@@ -4,4 +4,8 @@
remote_user
:
"
{{
ssh_user
}}"
remote_user
:
"
{{
ssh_user
}}"
roles
:
roles
:
-
role
:
rsync
-
role
:
rsync
-
role
:
database
tags
:
rsync
\ No newline at end of file
-
role
:
database
tags
:
db
-
role
:
flow
tags
:
flow
ansible/roles/database/tasks/main.yml
View file @
e772d84a
...
@@ -50,19 +50,3 @@
...
@@ -50,19 +50,3 @@
-
name
:
Restore local database from remote dump
-
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
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 }}"
chdir="{{ local_path }}"
-
name
:
Execute ./flow database:setcharset
local_action
:
shell FLOW_CONTEXT={{ local_flow_context }} bin/dockerflow run app ./flow database:setcharset
chdir="{{ local_path }}"
-
name
:
Execute ./flow flow:cache:flush --force
local_action
:
shell FLOW_CONTEXT={{ local_flow_context }} bin/dockerflow run app ./flow flow:cache:flush --force
chdir="{{ local_path }}"
-
name
:
Execute ./flow cache:warmup
local_action
:
shell FLOW_CONTEXT={{ local_flow_context }} bin/dockerflow run app ./flow cache:warmup
chdir="{{ local_path }}"
-
name
:
Execute ./flow resource:publish
local_action
:
shell FLOW_CONTEXT={{ local_flow_context }} bin/dockerflow run app ./flow resource:publish
chdir="{{ local_path }}"
ansible/roles/flow/README.md
0 → 100644
View file @
e772d84a
Flow
====
Execute necessary flow commands to setup the system.
License
-------
MIT
Author Information
------------------
Visay Keo
<visay@web-essentials.asia>
ansible/roles/flow/defaults/main.yml
0 → 100644
View file @
e772d84a
---
# defaults file for flow
ansible/roles/flow/handlers/main.yml
0 → 100644
View file @
e772d84a
---
# handlers file for flow
ansible/roles/flow/meta/main.yml
0 → 100644
View file @
e772d84a
---
galaxy_info
:
author
:
Visay Keo
description
:
Execute necessary flow commands to setup the system
company
:
Web Essentials
license
:
MIT
min_ansible_version
:
1.6
platforms
:
-
name
:
Ubuntu
versions
:
-
trusty
dependencies
:
[]
ansible/roles/flow/tasks/main.yml
0 → 100644
View file @
e772d84a
---
# tasks file for flow
-
name
:
Remove PackageStates.php and temp caches directory
local_action
:
shell rm -rf Configuration/PackageStates.php Data/Temporary
chdir="{{ local_path }}"
-
name
:
Execute neccessary flow commands
local_action
:
shell FLOW_CONTEXT={{ local_flow_context }} bin/dockerflow run app ./flow {{ item }}
chdir="{{ local_path }}"
with_items
:
-
flow:cache:flush --force
-
database:setcharset
-
doctrine:migrate
-
resource:publish
-
node:repair
-
cache:warmup
ansible/roles/flow/vars/main.yml
0 → 100644
View file @
e772d84a
---
# vars file for flow
ansible/roles/rsync/tasks/main.yml
View file @
e772d84a
...
@@ -2,4 +2,7 @@
...
@@ -2,4 +2,7 @@
# tasks file for rsync
# tasks file for rsync
-
name
:
Sync persistent data from remote server to local
-
name
:
Sync persistent data from remote server to local
synchronize
:
mode=pull src="{{ remote_path }}/Data/Persistent/" dest="{{ local_path }}/Data/Persistent/"
synchronize
:
mode=pull
\ No newline at end of file
src="{{ remote_path }}/Data/Persistent/"
dest="{{ local_path }}/Data/Persistent/"
delete=yes
bin/syncontent
View file @
e772d84a
...
@@ -4,6 +4,15 @@
...
@@ -4,6 +4,15 @@
ROOT_DIR
=
`
pwd
`
ROOT_DIR
=
`
pwd
`
PACKAGE_DIR
=
"
${
ROOT_DIR
}
/Packages/Libraries/visay/syncontent"
PACKAGE_DIR
=
"
${
ROOT_DIR
}
/Packages/Libraries/visay/syncontent"
# Colors
RED
=
"
\0
33[0;31m"
GREEN
=
"
\0
33[0;32m"
BROWN
=
"
\0
33[0;33m"
WHITE
=
"
\0
33[0;37m"
NC
=
"
\0
33[0m"
echo
# 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
...
@@ -20,6 +29,18 @@ do
...
@@ -20,6 +29,18 @@ do
REMOTE_HOST
=
"
${
ARGS
#*=
}
"
REMOTE_HOST
=
"
${
ARGS
#*=
}
"
shift
shift
;;
;;
-t
=
*
|
--ansible-tags
=
*
)
ANSIBLE_TAGS
=
"--tags=
${
ARGS
#*=
}
"
shift
;;
-v
*
)
VERBOSE_LEVEL
=
"
${
ARGS
}
"
shift
;;
--dry-run
)
DRY_RUN
=
"
${
ARGS
}
"
shift
;;
esac
esac
done
done
...
@@ -30,11 +51,14 @@ fi
...
@@ -30,11 +51,14 @@ fi
# If remote user is not set anywhere, throw error
# If remote user is not set anywhere, throw error
if
[
-z
"
${
REMOTE_USER
}
"
]
;
then
if
[
-z
"
${
REMOTE_USER
}
"
]
;
then
echo
"Please specify the user of the remote server to sync from:"
echo
-e
${
RED
}
"-> Please specify the user of the remote server to sync from:"
${
NC
}
echo
"Example: bin/syncontent --remote-user=latest-014-007"
echo
echo
"Example: bin/syncontent -u=demo-014-007"
echo
-e
${
BROWN
}
"Example: bin/syncontent --remote-user=latest-014-007"
${
NC
}
echo
"Or specify it in config/master directory, read the doc"
echo
-e
${
BROWN
}
"Example: bin/syncontent -u=demo-014-007"
${
NC
}
exit
0
echo
echo
-e
${
BROWN
}
"Or specify it in config/master directory, read the doc"
${
NC
}
echo
exit
1
fi
fi
# Extract from the remote user to get the stage name
# Extract from the remote user to get the stage name
...
@@ -43,10 +67,12 @@ STAGE=`echo ${REMOTE_USER} | cut -d '-' -f1`
...
@@ -43,10 +67,12 @@ STAGE=`echo ${REMOTE_USER} | cut -d '-' -f1`
# Check if stage is not latest or demo, throw error
# Check if stage is not latest or demo, throw error
if
[
"
${
STAGE
}
"
!=
"latest"
]
&&
[
"
${
STAGE
}
"
!=
"demo"
]
;
then
if
[
"
${
STAGE
}
"
!=
"latest"
]
&&
[
"
${
STAGE
}
"
!=
"demo"
]
;
then
echo
"Only latest or demo is supported at the moment:"
echo
-e
${
RED
}
"-> Only latest or demo is supported at the moment:"
${
NC
}
echo
"Example: bin/syncontent -u=latest-014-007"
echo
echo
"Example: bin/syncontent --remote-user=demo-014-007"
echo
-e
${
BROWN
}
"Example: bin/syncontent -u=latest-014-007"
${
NC
}
exit
0
echo
-e
${
BROWN
}
"Example: bin/syncontent --remote-user=demo-014-007"
${
NC
}
echo
exit
1
fi
fi
# If remote host is not set, read it from config file
# If remote host is not set, read it from config file
...
@@ -74,9 +100,11 @@ fi
...
@@ -74,9 +100,11 @@ fi
# Test connection to the server whether auto login is enabled
# Test connection to the server whether auto login is enabled
PING
=
`
ssh
-q
-o
"BatchMode=yes"
${
REMOTE_USER
}
@
${
REMOTE_HOST
}
echo
"OK"
`
PING
=
`
ssh
-q
-o
"BatchMode=yes"
${
REMOTE_USER
}
@
${
REMOTE_HOST
}
echo
"OK"
`
if
[
"
${
PING
}
"
!=
"OK"
]
;
then
if
[
"
${
PING
}
"
!=
"OK"
]
;
then
echo
"Public key authentication failed!"
echo
-e
${
RED
}
"-> Public key authentication failed!"
${
NC
}
echo
"Make sure you have auto login when running: ssh
${
REMOTE_USER
}
@
${
REMOTE_HOST
}
"
echo
exit
0
echo
-e
${
BROWN
}
"Make sure you have auto login when running:
${
WHITE
}
ssh
${
REMOTE_USER
}
@
${
REMOTE_HOST
}
"
${
NC
}
echo
exit
1
fi
fi
# If remote path is not set in argument, check for it in the configuration file
# If remote path is not set in argument, check for it in the configuration file
...
@@ -96,29 +124,72 @@ if [ -z "${REMOTE_PATH}" ]; then
...
@@ -96,29 +124,72 @@ if [ -z "${REMOTE_PATH}" ]; then
fi
fi
fi
fi
# If remote path is defined anywhere, set a standard value
# If remote path is
not
defined anywhere, set a standard value
if
[
-z
"
${
REMOTE_PATH
}
"
]
;
then
if
[
-z
"
${
REMOTE_PATH
}
"
]
;
then
REMOTE_PATH
=
"/home/
${
REMOTE_USER
}
/public_html"
REMOTE_PATH
=
"/home/
${
REMOTE_USER
}
/public_html"
fi
fi
# Check if persistent directory exists at the remote path on the server
# Check if persistent 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/Persistent ]"
)
;
then
echo
"Directory '
${
REMOTE_PATH
}
/Data/Persistent' does not exist on the server"
echo
-e
${
RED
}
"-> Directory '
${
REMOTE_PATH
}
/Data/Persistent' does not exist on the server"
${
NC
}
echo
"Check if your '--remote-path' config is set properly"
echo
exit
0
echo
-e
${
BROWN
}
"Check if your '--remote-path' config is set properly"
${
NC
}
echo
exit
1
fi
fi
# Use Development context if Flow Context is not set
# Use Development context if Flow Context is not set
FLOW_CONTEXT
=
${
FLOW_CONTEXT
:
=Development
}
FLOW_CONTEXT
=
${
FLOW_CONTEXT
:
=Development
}
echo
"Start content sync from
${
REMOTE_USER
}
(Production context)"
echo
-e
${
GREEN
}
"ENVIRONMENT SUMMARY:"
${
NC
}
echo
" to local docker in (
${
FLOW_CONTEXT
}
context)"
echo
"====================="
echo
-e
"FROM:
${
GREEN
}${
REMOTE_USER
}${
NC
}
"
echo
-e
"CONTEXT:
${
GREEN
}
Production
${
NC
}
"
echo
"---------------------"
echo
-e
"TO:
${
GREEN
}
Local Docker
${
NC
}
"
echo
-e
"CONTEXT:
${
GREEN
}${
FLOW_CONTEXT
}${
NC
}
"
echo
"---------------------"
echo
if
[[
-n
"
${
DRY_RUN
}
"
]]
;
then
echo
-e
${
GREEN
}
"DRY RUN MODE:"
${
NC
}
echo
"============"
echo
echo
-e
${
BROWN
}
"The following command should be executed"
${
NC
}
echo
"----------------------------------------"
echo
"ansible-playbook -i
${
PACKAGE_DIR
}
/ansible/hosts.ini
${
PACKAGE_DIR
}
/ansible/playbook.yml
${
VERBOSE_LEVEL
}
${
ANSIBLE_TAGS
}
--extra-vars
\"
stage=
${
STAGE
}
ssh_user=
${
REMOTE_USER
}
local_path=
${
ROOT_DIR
}
remote_path=
${
REMOTE_PATH
}
local_flow_context=
${
FLOW_CONTEXT
}
\"
"
echo
exit
0
fi
ansible-playbook
-i
${
PACKAGE_DIR
}
/ansible/hosts.ini
${
PACKAGE_DIR
}
/ansible/playbook.yml
\
# Ask user to confirm
--extra-vars
"stage=
${
STAGE
}
read
-p
"Are you sure (y/n)? "
-r
ssh_user=
${
REMOTE_USER
}
echo
local_path=
${
ROOT_DIR
}
if
[[
!
${
REPLY
}
=
~ ^[Yy]
$
]]
;
then
remote_path=
${
REMOTE_PATH
}
echo
-e
${
BROWN
}
"#############################"
local_flow_context=
${
FLOW_CONTEXT
}
"
echo
"### CONTENT SYNC SKIPPED ###"
echo
-e
"#############################"
${
NC
}
exit
0
fi
echo
"Sync content from
${
STAGE
}
completed!"
echo
-e
${
GREEN
}
"#############################"
echo
"### STARTING CONTENT SYNC ###"
echo
-e
"#############################"
${
NC
}
ansible-playbook
-i
${
PACKAGE_DIR
}
/ansible/hosts.ini
${
PACKAGE_DIR
}
/ansible/playbook.yml
${
VERBOSE_LEVEL
}
${
ANSIBLE_TAGS
}
\
--extra-vars
"stage=
${
STAGE
}
ssh_user=
${
REMOTE_USER
}
local_path=
${
ROOT_DIR
}
remote_path=
${
REMOTE_PATH
}
local_flow_context=
${
FLOW_CONTEXT
}
"
\
||
ERROR
=
"1"
if
[[
-n
"
${
ERROR
}
"
]]
;
then
echo
echo
-e
${
RED
}
"-> Ansible argument error"
${
NC
}
echo
echo
-e
${
BROWN
}
"Please make sure you pass the correct parameters"
echo
-e
"Read the documentation for detailed usage"
${
NC
}
echo
exit
1
else
echo
-e
${
GREEN
}
"#############################"
echo
"### CONTENT SYNC COMPLETE ###"
echo
-e
"#############################"
${
NC
}
fi
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment