Code Monkey home page Code Monkey logo

sshdeploy's Introduction

This project has been archived

dotnet-sshdeploy

NuGet Analytics Build Status Build status NuGet version

Please star this project if you find it useful!

A dotnet CLI command that enables quick deployments over SSH. This program was specifically designed to streamline .NET application development for the Raspberry Pi running Raspbian.

If you came here looking for our old version of SSHDeploy please click here, otherwise you are in the right place

The following commands are currently available:

  • dotnet-sshdeploy monitor - Watches changes on a single file, if this event is raised then it proceeds to send the specified source path files over SSH
  • dotnet-sshdeploy push - Single-use command that transfers files over SSH

Installation

We are using the brand new implementation of the global tool in .NET Core Apps 2.1+. Now you can easily download the package by running the next command

dotnet tool install -g dotnet-sshdeploy

Custom installation

If you download the project and want to test installing your own version of the project you need to pack and then install the nuget

// In the root of your project run
dotnet pack

// Run the following command where you nupkg was created
dotnet tool install -g dotnet-sshdeploy --add-source ./

Update

To update ssh-deploy to the latest version, use the dotnet tool update command

dotnet tool update -g dotnet-sshdeploy

Usage

There are two ways of passing arguments: the old school way using the cli and our approach using the csproj file.

Using the csproj file

Push

  1. Edit your csproj file and add:
<PropertyGroup>
    <SshDeployHost>192.168.2.194</SshDeployHost>
    <SshDeployClean />
    <SshDeployTargetPath>/home/pi/libfprint-cs</SshDeployTargetPath>
    <SshDeployUsername>pi</SshDeployUsername>
    <SshDeployPassword>raspberry</SshDeployPassword>
    <RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
</PropertyGroup>
  1. We need a post build event as well:
<Target Condition="$(BuildingInsideSshDeploy) ==''" Name="PostBuild" AfterTargets="PostBuildEvent">
   <Exec Command="cd $(ProjectDir)" />
   <Exec Command="dotnet-sshdeploy push" />
</Target>

Voilà! sshdeploy finds the necessary arguments provided using proper xml tags and deploys after a successful build

  • Be sure you are using ' / ' with RemoteTargetPath otherwise it will not work.
  • You MUST use the property BuildingInsideSshDeploy to make sure this event will not be executed within sshdeploy's build method to avoid an infinite loop
  • If no RuntimeIdentifier is provided a Framework-dependent deployment will be created otherwise a Self-contained deployment will
  • The command needs to be excuted in the same folder as the csproj

If your project happens to target multiple runtimes, i.e. win-x64 and linux-arm, then sshdeploy does not necessarily know which binaries to deploy. Also, you might want to control that i.e. only the linux-arm build should be automatically deployed. In this case, you can change the post build event and add an additional condition to the target (only run on builds for linux), and also pass the desired runtime identifier to the actual deployment call as follows:

<Target Condition="$(BuildingInsideSshDeploy) == '' and $(RuntimeIdentifier) == 'linux-arm'" Name="PostBuild" AfterTargets="PostBuildEvent">
   <Exec Command="cd $(ProjectDir)" />
   <Exec Command="dotnet-sshdeploy push -r $(RuntimeIdentifier)" />
</Target>

Monitor

  1. Go to your Visual Studio Solution (the one you intend to continuously deploy to the Raspberry Pi).
  2. Right-click on the project and click on the menu item "Properties"
  3. 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 the sshdeploy.ready file. Whenever this file CHANGES, the deployment tool will perform a deployment.
  1. Edit your csproj file and add:
    <RemoteHost>192.168.2.194</RemoteHost>
    <SourcePath>C:\projects\Unosquare.Labs.RasPiConsole\Unosquare.Labs.RasPiConsole\bin\Debug</SourcePath>
    <RemoteTargetPath>/home/pi/libfprint-cs</RemoteTargetPath>
    <RemoteUsername>pi</RemoteUsername>
    <RemotePassword>raspberry</RemotePassword>
  1. Execute
dotnet-sshdeploy monitor

FYI: Arguments passed using the csproj file will not override the ones provided using the cli

XML Tags

Heres a complete list of arguments with their corresponding XML tag.

Args XML Tag
-m,--monitor <SshDeployMonitorFile>
-f,--framework <TargetFramework>
-r,--runtime <RuntimeIdentifier>
-s, --source <SshDeploySourcePath>
-t,--target <SshDeployTargetPath>
--pre <SshDeployPreCommand>
--post <SshDeployPostCommand>
--clean <SshDeployClean/>
--exclude <SshDeployExclude>
-v,--verbose <SshDeployVerbose/>
-h,--host <SshDeployHost>
-p,--port <SshDeployPort>
-u,--username <SshDeployUsername>
-w,--password <SshDeployPassword>
-l,--legacy <SshDeployLegacy/>
-x, --execute <SshDeployExecutePermission>

Old school way

Push

  1. Navigate to your project folder where the csproj file resides. Example:
cd C:\projects\Unosquare.Labs.RasPiConsole\Unosquare.Labs.RasPiConsole\
  1. Execute this command with some arguments. Here's a simple example:
dotnet-sshdeploy push -f netcoreapp2.0 -t "/home/pi/libfprint-cs" -h 192.168.2.194
  • In the command shown above :
    • -f refers to the source framework
    • -t refers to the target path
    • -h refers to the host (IP address of the Raspberry Pi)
  • For a detailed list of all the arguments available please see below or execute dotnet-sshdeploy push

Monitor

The following steps outline a continuous deployment of a Visual Studio solution to a Raspberry Pi running the default Raspbian SSH daemon.

  1. Go to your Visual Studio Solution (the one you intend to continously deploy to the Raspberry Pi).
  2. Right-click on the project and click on the menu item "Properties"
  3. 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 the sshdeploy.ready file. Whenever this file CHANGES, the deployment tool will perform a deployment.
  1. Open a Command Prompt (Start, Run, cmd, [Enter Key])
  2. Navigate to your project folder where the csproj file resides
  • Example: cd "C:\projects\Unosquare.Labs.RasPiConsole\Unosquare.Labs.RasPiConsole\"
  1. Run this tool with some arguments. Here is an example so you can get started quickly.
    dotnet-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,
    • -s refers to the source path of the files to transfer.
    • t refers to the full path of the target directory.
    • -h refers to the host (IP address of the Raspberry Pi).
    • -u refers to the login.
    • -w refers to the password.
  • Note that there are many more arguments you can use. Simply issue
dotnet-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 0.3.1.0]
(c)2015 - 2017 Unosquare SA de CV. All Rights Reserved.
For additional help, please visit https://github.com/unosquare/sshdeploy

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 SSH.
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!
  1. Now go back to your Visual Studio Solution, right click on the project, a select "Rebuild". You should see the 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 that 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: dotnet-sshdeploy 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

References

Monitor Mode

Short Argument Long Argument Description Default Required
-m --monitor The path to the file used as a signal that the files are ready to be deployed. Once the deploymetn is completed,the file is deleted. sshdeploy.ready ✔️
-s --source The source path for the files to transfer. ✔️
-t --target 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 Deletes all files and folders on the target before pushing the new files True
--exclude a pipe (|) separated list of file suffixes to ignore while deploying. .ready|.vshost.exe|.vshost.exe.config
-v --verbose Add this option to print messages to standard error and standard output streams. True
-h --host Hostname or IP Address of the target. -- Must be running an SSH server. ✔️
-p --port Port on which SSH is running. 22
-u --username The username under which the connection will be established. pi
-w --password The password for the given username. raspberry
-l --legacy Monitor files using legacy method False

Push Mode

Short Argument Long Argument Description Default Required
-c --configuration Target configuration. Debug
-f --framework The source framework. ✔️
--pre Command to execute prior file transfer to target.
--post Command to execute after file transfer to target.
--clean Deletes all files and folders on the target before pushing the new files. True
--exclude a pipe (|) separated list of file suffixes to ignore while deploying. .ready|.vshost.exe|.vshost.exe.config
-v --verbose Add this option to print messages to standard error and standard output streams. True
-h --host Hostname or IP Address of the target. -- Must be running an SSH server. ✔️
-p --port Port on which SSH is running. 22
-u --username The username under which the connection will be established. pi
-w --password The password for the given username. raspberry
-x --execute Adds user execute permissions to the deployed files. False

Special Thanks

This code uses the very cool Renci's SSH.NET library and our awesome SWAN library.

sshdeploy's People

Contributors

bdfin avatar dependabot-preview[bot] avatar geoperez avatar gingters avatar israelramosm avatar jpalcala avatar k3z0 avatar mariodivece avatar rflechner avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sshdeploy's Issues

Support for VbProj

Is your feature request related to a problem? Please describe.
I wanted to use the Proj file Solution to push the binaries. Sadly it is not recognizing a VbProj file.
The error I'm getting is "No csproj file was found"
Describe the solution you'd like
It should be searching for CsProj and VbProj files.

Feature request: automatically chmod executable for deployments

When I deploy a .net core self-contained project onto my Raspberry Pi,
I always have to chmod +x myProject && ./myProject on the Pi, as the executable is not marked as an executable file after the ssh copy of the project.

This is, however, only a minor inconvenience. That said, if it would be possible to add a chmod call to mark the executable as such without a lot of effort (i.e. the executable could be easily found from msbuild properties and the call could easily be added), that would be a nice improvement.

Deploys the wrong files when project supports multiple runtimes

I have a project that cannot be deployed to the pi, when multiple target runtimes are available.

When I have only <RuntimeIdentifier>linux-arm</RuntimeIdentifier> set, and I do a dotnet publish command, it works.

However, when I have set <RuntimeIdentifiers>win-x64;linux-arm</RuntimeIdentifiers> and I do a dotnet publish -r linux-arm, ssh-deploy deploys the wrong files (the framework-dependent project .exe) and not the self-contained Linux version.

I also did not find a way to pass the directory to deploy (in my case D:\Dev\sg\bsc-ampel\bin\Debug\netcoreapp3.0\linux-arm\publish) to the tool. It always wants to deploy the wrong build.

I have to go back to only support one runtime, which makes local debugging extremely tedious.

Add support for .NET Core worker SDK

Describe the bug
I'm using the worker template from the dotnet cli (dotnet new worker) and I wanted to use sshdeploy with this project but the template has a SDK that is not supported (Microsoft.NET.Sdk.Worker). Would it be possible to add this SDK to the supported ones?

To Reproduce
Steps to reproduce the behavior:

  1. Create a new worker project with the dotnet cli
  2. Add sshdeploy
  3. Push
  4. See error

Expected behavior
The application is pushed.

Actual behavior

Unhandled exception. System.ArgumentException: Project file is not of the new .csproj type.
     at Unosquare.Labs.SshDeploy.Utils.CsProjFile`1..ctor(Stream stream, Boolean leaveOpen) in C:\Unosquare\sshdeploy\Unosquare.Labs.SshDeploy\Utils\CsProjFile.cs:line 54
     at Unosquare.Labs.SshDeploy.Utils.CsProjFile`1..ctor(String filename) in C:\Unosquare\sshdeploy\Unosquare.Labs.SshDeploy\Utils\CsProjFile.cs:line 32
     at Unosquare.Labs.SshDeploy.Program.Main(String[] args) in C:\Unosquare\sshdeploy\Unosquare.Labs.SshDeploy\Program.cs:line 46

Tool hangs after deploy, must Ctrl+C to stop

Using Version 0.4.0.0.

When I run dotnet-sshdeploy push, the files are copied to my Pi device and it tells me that it finished the deployment (it did copy the files) but the tool is still running. It seems indefinitely stuck waiting for either some event to occur or the user to terminate the app with Ctrl+C, which is the only way I can seem to stop it. I'm assuming this is not expected behavior since I'm not running monitor. Ideas on potential cause and fix?

Project file has this:

  <PropertyGroup>
    <RuntimeIdentifiers>linux-arm</RuntimeIdentifiers>
    <SshDeployHost>192.168.4.87</SshDeployHost>
    <SshDeployTargetPath>/home/pi/myapp</SshDeployTargetPath>
    <SshDeployUsername>pi</SshDeployUsername>
  </PropertyGroup>

I'm running the tool with dotnet-sshdeploy push -w $PI_PWD -v. I've also tried it with the password directly in the project file, and with and without runtime identifiers.

Fails if project depends on a .NET standard 2.1 assembly

Describe the bug
Projects that have .NET Standard 2.1 dependencies fail to deploy

To Reproduce
Steps to reproduce the behavior:

  1. Create solution with a .NET 5.0 console application that has a project reference to a .NET Standard 2.1 class library
  2. From the project directory of the console application, execute "dotnet-sshdeploy push -f net50"
  3. Deployment fails with error:
    C:\Program Files\dotnet\sdk\5.0.102\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(241,5): error NETSDK1005: Assets file '<.NET Standard 2.1 project directory>\obj\project.assets.json' doesn't have a target for 'netstandard2.1'. Ensure that restore has run and that you have included 'netstandard2.1' in the TargetFrameworks for your project.
    [<.NET Standard 2.1 project .csproj file>]
    Invoking MSBuild target failed

Expected behavior
The application should successfully deploy.

Desktop (please complete the following information):

  • OS: Windows 10

SshDeploySourcePath does not work

I try running
dotnet sshdeploy push
with a source path on
..\bin\Debug\net46
but the push command always creates the publish folder and sets the source path to ..\bin\Debug\net46\publish

Make sshdeploy also available as a dotnet CLI tool extension

This is just a suggestion.
Since the dotnet CLI can be extended, you could make it available on nuget to extend the dotnet CLI.
A possible usage would be:
dotnet sshdeploy ...

Going further, the sshdeploy could also trigger the SCD publishing (Self Contained Deployment) when you don't want to install the runtime or the sdk on the target linux machine.

Use rsync where available

Invoking the rsync command when available (on both source and destination), would make transfers 100x faster. Rsync copies only the portions of files that have changed and can be directed to delete all files not wanted on the destination.

Unhandled exception when csproj file is invalid

Unhandled Exception: System.ArgumentException: Project file is not of the new .csproj type.
   at Unosquare.Swan.Components.CsProjFile1..ctor(Stream stream, Boolean leaveOpen)
   at Unosquare.Labs.SshDeploy.Program.Main(String[] args)

Not support in .NET 5

Did you have a planning to make this library usable in .NET 5? Because i like this raspberryIO but that library seems dependable with ssh deploy library

image

Publish breaks application

Describe the bug
When I publish after a succesfull build my dotnet application does not execute anymore.

The following exception is thrown:

pi@pibot01:~/publish $ ./PiCore
PiCore: /root/coresetup/src/corehost/cli/fxr/fx_muxer.cpp:416: static pal::strin g_t fx_muxer_t::resolve_fx_dir(host_mode_t, const pal::string_t &, const runtime _config_t &, const pal::string_t &, const int &): Assertion `mode != host_mode_t ::standalone' failed.
Aborted

To Reproduce
My initial deploy was with Putty pscp.exe.
Later I implemented dotnet-sshdeploy which published the changes.

Expected behavior
I expect an update of my application.

async main is not available

Describe the bug
When you try to publish an app that uses async main, ssh deploy generates the next error:

error CS8107: Feature 'async main' is not available in C# 7.0.

Note: It seems like if you don't include the LangVersion tag then ssh deploy uses C# 7.0 by default for publishing the app.

imagen

Feature Request: Passwordless authentication

Is your feature request related to a problem? Please describe.
The current tool requires specifying a password to allow authentication.

Describe the solution you'd like
I would like to to have support for password-less authentication by using ssh private key and ssh-agent

Describe alternatives you've considered
Either try to get a public key for authenticating by default or if property was specified

Reference to type SingletonBase<> Error in Asp.Net Core 2.0 Projekt

I had the following error
CS7069 Reference to type 'SingletonBase<>' claims it is defined in 'Unosquare.Swan', but it could not be found

A Default ASP.NET Core 2.0 Projekt with following additional class

using System.Text;
using Unosquare.RaspberryIO;
using Unosquare.RaspberryIO.Gpio;

namespace WebApplication2.Controllers
{
    public class Class
    {
        public string Test()
        {
            StringBuilder str = new StringBuilder();

            GpioController gpio = Pi.Gpio;
            foreach (var pin in gpio)
            {
                str.AppendLine($"Pin: {pin.PinNumber} and BCM number: {pin.BcmPinNumber} has value: {pin.Read()}");
            }

            return str.ToString();
        }
    }
}

My csproj file after installing the Nuget looks like:

<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework>netcoreapp2.0</TargetFramework>
  </PropertyGroup>
 
  <ItemGroup>
    <PackageReference Include="dotnet-sshdeploy" Version="0.2.1" />
    <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.6" />
    <PackageReference Include="Unosquare.Raspberry.IO" Version="0.13.0" />
  </ItemGroup>
  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.3" />
  </ItemGroup>
</Project>

Optimize file pushing for only files that changed

A default MVC app will push almost 400 files in "self-contained" mode. THis happens on every build and takes a minute every time. It would be great if there could be some file compare or datetime stamp logic to skip the 390 files that did not change.

Directory Not Found Exception

Describe the bug
When the flag AppendTargetFrameworkToOutputPath is set to false in the csproj of the project the dotnet-sshdeploy throws a DirectoryNotFoundException

To Reproduce
Steps to reproduce the behavior:

  1. In the csproj add <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
  2. Rebuild the solution
  3. Execute dotnet-sshdeploy push
  4. See error DirectoryNotFoundException

Expected behavior
It should push the files into the target

Additional context
Working with netcoreapp 2.1 versions and linux-arm runtime identifier

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.