Package: cploy
CPLOYThe ad hoc continuous deployment solution for developersI sometimes have to code stuff that needs to be deployed and run on
remote hosts. Since I don’t have all my prefs/settings/dotfiles/etc on
the remote, I usually code on local and have a small one-liner lying
around that allows me to quickly deploy the code (withscpor
similar) and run some command on the other side (withsshfor
example). This is not optimal and that’s the reason I createdcploy.Cployallows to mirror changes performed on a local directory to a
remote host through SSH. A specific command (bash one-liner for example)
can be run after any change, for example to trigger a build or execute a
script.Features:handle multiple syncs in parallelsecure sync through SSHrun in the backgroundexecute command on each local changeability to exclude some files from syncsave and resume tasksload tasks from fileQuick start:# install cploysudopip3installcploy# start the daemoncploystart# add a directory to synccploysync/tmp/localsomeuser@somehost/tmp/remoteseeusagefor more infoTable of ContentsInstallationUsageAdding a taskTalking with the daemonFile exclusionSync eventsRun a command on changeSave and resume tasksContributionInstallationTo install run:$sudopip3installcploy$cploy--helpOr from github directly$cd/tmp;gitclonehttps://github.com/deadc0de6/cploycploy-git&&cdcploy-git$sudopython3setup.pyinstall$cploy--helpTo work withcploywithout installing it, you can do the following$cd/tmp;gitclonehttps://github.com/deadc0de6/cploycploy-git&&cdcploy-git$sudopip3install-rrequirements.txt$python3-mcploy.cploy--helpor install it in a virtualenv$cd/tmp;gitclonehttps://github.com/deadc0de6/cploycploy-git&&cdcploy-git$virtualenv-ppython3env$sourceenv/bin/activate$pythonsetup.pyinstall$cploy--helpUsageThe usual way of usingcployis by starting the daemon. A task will
continuously synchronize any change made to a specific local directory
on a remote path. All synchronizations are done through SSH.Start the daemon$cploystart--debugThe daemon’s logs are in/tmp/cploy/cploy.log. Debug logs and errors
are written to/tmp/cploy/cploy.err.And add a task to it:# sync local dir /tmp/local
# on host "somehost" under /tmp/remote$cploysync/tmp/local/somehost/tmp/remoteThat’s it. Now every changes made in the/tmp/localdirectory will
be applied in/tmp/remoteonsomehost.Adding a taskTasks can be added by using thesynccommand.After adding a task, make sure to check the daemon to see if the task
has been added successfully withcploy info. In case it wasn’t,
checking the logs in/tmp/cploy/cploy.{log,err}usually allows to
identify the issue.Connections to a remote hosts is done using SFTP (SSH). Multiple
connection options can be applied: connection with password, with SSH
keys, using the SSH agent, different port, different username, etc.Besides using the above switches, The ** argument can also be provided
using a compact format similar to what the SSH client provides:<username>@<hostname>:<port>The<remote_path>is normalized based on the default user’s
directory on the remote (usually$HOME). For example../../tmp/testwould result in/tmp/testif the remote user’s
default directory is/home/user. Note that shell expansions are not
performed on remote paths (like~for example) neither are
environment variables (like$HOME).Once a new task is added,cploywill start by copying any local
existing files to the remote directory to initiate the remote directory.
Then, any change to the local directory is automatically applied on the
remote.Connection Requirements:SSH access is working (obviously)remote host key is trustedlocal directory exists (<local_path>)remote directory does not exist (<remote_path>) unless--forceis usedTalking with the daemonA few commands are available to talk to the daemon:start: start the daemonstop: stop the daemonrestart: stop and then start the daemoninfo: get a list of current tasksping: ping the daemondebug: toggle debug flagunsync: stop syncing a specific taskresync: force a full sync of the local directory to the remote
oneresume: resume sync from a fileIf you prefer not to use the daemon,cploycan also be entirely run in
the foreground by using the--frontswitch. However only a single
task can be added to it then.Getting information from the daemon allows to see the different task
running and their id:$cployinfoFile exclusionFiles can be excluded from the sync in the monitored directory by using
the--excludeswitch. Matching is done usingfnmatch.Example: exclude any hidden files--exclude '*/.*'Example: exclude any files containingtest--exclude '*/test*'Exclusions pattern can be loaded from a file using the--expathswitch. The file should contain one pattern per line.For example:*/.*
*/test*Sync eventsHere is a list of changes that are synchronized on the remote:File creationFile deletionFile attribute changeFile content modificationFile moveRun a command on changeA command can be added to a task using the--commandswitch. The
provided command will be run on the remote anytime a change is applied
on the local monitored directory.Cployuses paramiko channel’sexec_commandto execute the command which will be run from the default directory of
the remote user (usually$HOME).For example if the remote directory is/tmp/remoteand the script to
run remotely is located in/tmp/remote/test.sh, the command argument
will be--command="/tmp/remote/test.sh".Currently the specified command is run on any change with no control
over the granularity.Save and resume tasksEach timecploy’s daemon is stopped, it will append its running tasks
to/tmp/cploy/cploy.save. This file can easily be edited or saved
for backup.Cploycan resume tasks from a saved file by calling theresumedaemon’s command and providing it with a valid saved file.Here’s an example of a saved file’s content describing two tasks:sync /tmp/first host1 /tmp/remote --debug --force
sync /tmp/second host2 /tmp/remote --debug --forceThis also allows to describe tasks in a file directly instead of calling
the command line for each task. Issuing the following command will load
the tasks from/tmp/sometasks$cployresume/tmp/sometasksNote thatsynccommands loaded from file get environment variables
(and relative path) expanded.ContributionIf you are having trouble installing or usingcploy, open an issue.If you want to contribute, feel free to do a PR (please follow PEP8).Have a look at thedesigndirectory.LicenseThis project is licensed under the terms of the GPLv3 license.