sshdeploy
A command-line tool that enables quick deployments over SSH. This is program was specifically designed to streamline .NET application development for the the Raspberry Pi running Raspbian.
Usage Example
The following steps outline a continuous deployment of a Visual Studio solution to a Raspberry Pi running the default Raspbian SSH daemon.
- Download and compile this tool. You should end up with SshDeploy.exe and a few dll files.
- Open a Command Prompt (Start, Run, cmd, [Enter Key])
-
Navigate to the folder where the SshDeploy.exe file is located (output of step 1).
Example:cd "C:\projects\sshdeploy\trunk\Unosquare.Labs.SshDeploy\bin\Debug" - Now go to your Visual Studio Solution (the one you intend to continously deploy to the Raspberry Pi).
- Right click on the project and click on the menu item "Properties"
- Go to the "Build Events" tab, and under Post-build events, enter the following:
echo %DATE% %TIME% >> "$(TargetDir)sshdeploy.ready"
This simply writes the date and time to thesshdeploy.readyfile. Whenever this file CHANGES, the deployment tool will perform a deployment. -
Go back to the Command Prompt window you opened in a prior step and run this tool with some arguments. Here is an example so you can get started quickly.
sshdeploy monitor -s "C:\projects\Unosquare.Labs.RasPiConsole\Unosquare.Labs.RasPiConsole\bin\Debug" -t "/home/pi/target" -h 192.168.2.194 -u pi -w raspberry
In the above command,-srefers to the full path of the source folder.-trefers to the full path of the target directory.-hrefers to the host (IP address of the Raspberry Pi).-urefers to the login.-wrefers to the password.
sshdeploy monitor
This will get you all the options you can use. - If all goes well you will see output similar to this:
SSH Deployment Tool [Version 1.0.0.0] (c) 2015 Unosquare SA de CV. All Rights Reserved. Monitor mode starting Monitor parameters follow: Monitor File C:\projects\Unosquare.Labs.RasPiConsole\Unosquare.Labs.RasPiConsole\bin\Debug\sshdeploy.ready Source Path C:\projects\Unosquare.Labs.RasPiConsole\Unosquare.Labs.RasPiConsole\bin\Debug Excluded Files .ready|.vshost.exe|.vshost.exe.config Target Address 192.168.2.194:22 Username pi Target Path /home/pi/target Clean Target YES Pre Deployment Post Deployment Connecting to host 192.168.2.194:22 via SFTP. File System Monitor is now running. Writing a new monitor file will trigger a new deployment. Remember: Press Q to quit. Ground Control to Major Tom: Have a nice trip in space! - Now go back to your Visual Studio Solution, right click on the project, a select "Rebuild". You should see output in the command line similar to the following:
Starting deployment ID 1 - Sunday, June 14, 2015 10:16:20 PM Cleaning Target Path '/home/pi/target' Deploying 3 files. Finished deployment in 0.88 seconds. - Every time you rebuild your project, it will be automatically deployed!
In order to make this tool much more useful, we need to take advantage of the pre and post commands. The idea is to find the process and kill it if it is currently running on the pre-command, and run the process once the deployment has been completed using the post-command argument. The hope is thay this will make the deploy, run, and debug cycle, much less tedious for a .NET developer using a Raspberry Pi.
Here's a good example of using pre and post commands to acocmplish the above
monitor -s "C:\projects\libfprint-cs\trunk\Unosquare.Labs.LibFprint.Tests\bin\Debug" -t "/home/pi/libfprint-cs" -h 192.168.2.194 --pre "pgrep -f 'Unosquare.Labs.LibFprint.Tests.exe' | xargs -r kill" --post "mono /home/pi/libfprint-cs/Unosquare.Labs.LibFprint.Tests.exe" --clean False
Monitor Mode Documentation
from command line help output -m, --monitor (Default: sshdeploy.ready) The path to the file used as a
signal that the files are ready to be deployed. Once the
deployemtn is completed, the file is deleted.
-s, --source Required. The source path for the files to transfer
-t, --target Required. The target path of the files to transfer
--pre Command to execute prior file transfer to target
--post Command to execute after file transfer to target
--clean (Default: True) Deletes all files and folders on the target
before pushing the new files
--exclude (Default: .ready|.vshost.exe|.vshost.exe.config) a pipe (|)
separated list of file suffixes to ignore while deploying.
-v, --verbose (Default: True) Add this option to print messages to
standard error and standard output streams.
-h, --host Required. Hostname or IP Address of the target. -- Must be
running an SSH server.
-p, --port (Default: 22) Port on which SSH is running.
-u, --username (Default: pi) The username under which the connection will
be established.
-w, --password (Default: raspberry) The password for the given username.
Special Thanks
This code uses the very cool Renci's SSH.NET library and the awesome Command Line Parser library available here.