How to manage a project folder via ssh? - ssh

Developing full-stack web apps, I would like to have all my code and build logic on a linux machine (i.e. git, docker containers and other terminal commands), but all my development workflow on my windows machine (so my IDE, web browser and REST client) accessing it via SSH.
I've managed to do all of that except for the IDE, I could only edit individual files via SSH instead of managing a folder as a project. So right now I use VSCode on the linux machine (Ubuntu), and it's the last thing preventing me for dropping the graphical interface and install Ubuntu Server on it.
And no, I don't want to use Vim or Emacs. I want to use VSCode, or another modern IDE, but preferably VSCode.

Try using the Remote VSCode plugin as explained here: Using Remote VSCode
This discussion is exactly about your problem: VSCode 13643 issue Github
EDIT: I have recently found a new VSCode plugin on Github: vs-deploy. It was designed to deploy files and folders remotely very quickly. It seems to be working and I haven't found any bugs so far. It works with FTP, SFTP (SSH) and many other protocols.

The SSH.NET nuget Package can be used quite nicly to copy files and folders.
Here is an example:
var host = "YourServerIpAddress";
var port = 22;
var user = "root"; // TODO: fix
var yourPathToAPrivateKeyFile = #"C:\Users\Bob\mykey"; // Use certificate for login
var authMethod = new PrivateKeyAuthenticationMethod(user, new PrivateKeyFile(yourPathToAPrivateKeyFile));
var connectionInfo = new ConnectionInfo(host, port, user, authMethod);
using (var client = new SftpClient(connectionInfo))
{
client.Connect();
if (client.IsConnected)
{
//TODO: Copy folders recursivly etc.
DirectoryInfo source = new DirectoryInfo(#"C:\your\probject\publish\path");
foreach (var file in source.GetFiles())
{
client.UploadFile(File.OpenRead(file.FullName), $"/home/yourUploadPath/{file.Name}", true);
}
}
}
When you create a upload console application using the code above your should be able to automatically trigger an upload by using postbuild events by adding a section to your Project.
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="path to execute your script or application" />
</Target>
If you prefer to do the same but more manual you can perform a
dotnet build --configuration Release
followed by a
dotnet publish ~/projects/app1/app1.csproj
and then use the code above to perform an upload.

Search for the extension SSHExtension developed by Vitaly Kondratiev
Install the extension.
And edit the serverlist json with the server details.
ex:
"sshextension.serverList": [
{
"name": "Kuberntes 212",
"host": "10.64.234.54",
"port": 22,
"username": "root",
"password": "byebye"
}
]
save the file
Then log in using ctrl+shift+p and choose sshextension open ssh extension category. It shall create a session for you.
More Easily if u need the entire directory structure into ur local workspace.
Use extension ftp-simple in vscode. It works as a wonder, trust me.
Install ftp-simple in vscode
ctrl+shift+p
select ftp-simple:config.
Configure your settings
[
{
"name": "Kubernetes 212",
"host": "10.75.64.2",
"port": 22,
"type": "sftp",
"username": "root",
"password": "byebye",
"path": "/home/vinod/",
"autosave": true,
"confirm": true
}]
save the file.
Now ctrl+shift+p
and select ftp-simple:remote directory to workspace.
Viola Your work is done, Life is simple

Related

How to deploy molecular project without docker in production?

How should I deploy a molecular microservice project on the server without using docker and Kubernetes?
I pull my updated code into a server and run the npm run dev command project run as per aspected.
But now I want to set up pm2 for this project so, what do I need to do?
I try to run npm run start command on a server but I am getting below output and the project is not running.
Please help.
Your problem is that you didn't configure the services to start. For Docker and Kubernetes environment, we use SERVICES env variable to configure what services should be loaded on a Moleculer node.
So you can also use this way, or modify the start script in package.json and set the services what you want to load. E.g.
moleculer-runner -e services/**/*.service.js
I got the solution.
If we not use the Docker and Kubernetes for moleclar project and directly clone our code on server same as like normal NodeJS(Express) project.
Then we need to create index.js file and need to put below lines.
const { ServiceBroker } = require('moleculer');
const config = require('./moleculer.config');
config.hotReload = true;
const broker = new ServiceBroker(config);
broker.loadServices('services', '**/*.service.js');
broker.start();
So, using above command Molecular started all the service of our project
After, index file we can able to start our project using pm2 service.
I created a start script (api-init.json) as below:
[
{
"script": "./node_modules/moleculer/bin/moleculer-runner.js",
"args": "services",
"instances": "max",
"watch": false,
"name": "API"
}
]
Then use pm2 to start:
pm2 start api-init.json

How to connect bitcore-lib to a running full node-bitcoin

I want to run full node on my box, and write a program using bitcore-lib using which I can get balance from a given address and also transfer money, using the running full node on my box. I would really appreciate any pointers to achieve it.
How to connect bitcore-lib to a running full node-bitcoin
Use npm to install bitcore-lib. It should also come with it's own version of bitcoind (unsure if they've switched over to bcoin). If not/you're unsure, you can download and set up your own bitcoind node by cloning the bitcoin repository and follow the docs on setting it up on your machine (OSX, Linux, Windows, etc)
Then, to configure bitcore-lib to connect to your node, you can configure your bitcore-node.json file to look something like this.
{
"network": "livenet",
"port": 3001,
"services": [
"bitcoind",
"insight-api",
"insight-ui",
"web"
],
"servicesConfig": {
"bitcoind": {
"connect": [
{
"rpcuser": "bitcoin",
"rpcpassword": "local321",
"zmqpubrawtx": "tcp://127.0.0.1:28332"
}
]
}
}
}
I want to run full node on my box, and write a program using bitcore-lib using which I can get balance from a given address and also transfer money, using the running full node on my box.
If you're interesting in building applications on top of bitcoin, and you're fine using javascript you should take a look at bcoin(bcoin.io). It's a full node implementation written in node.js and has great tutorials on how to use it's fleshed out api. If you have issues, they also have an open slack team where you can ask the developers for help. bitcore-lib, while a front runner in the past is not as well supported and suffers from a host of issues.

Need to use a password in package.json

When working locally I start my application with an npm command in my package.json. The problem is that I need this command to include a password for a remote database:
"scripts": {
"start":
"MONGO_URL='mongodb://USERNAME:PASSWORD#URL:PORT/DB-NAME' meteor --settings settings.json"
},
This is working but I dont want to save my password to my source control. How can I run the same command without committing my password?
You can set the environement variable programmaticaly at startup and store the secret in the settings.json file (which is appropriate to store secrets and shouldn't be in version control - see here)
in the startup/server/index.js file:
let mongoPassword = Meteor.settings.private.mongoPassword;
process.env.MONGO_URL = "mongodb://USERNAME:" + mongoPassword + "#URL:PORT/DB-NAME";
You can also choose to start your app using the meteor command and store the MONGO_URL environment variable in your local development environment
In production, you shouldn't use the meteor command but build with meteor build and then run the bundled app with node main.js

Running custom script extension on deployed scale set instances

currently I'm using custom script extension to run scripts on demand on my azure vm server as part of our software solution, our other dev team is moving an application to a scale set and i am no longer capable of deploying custom script extension on demand to the scale set instances. the only solution i have found for running custom script extension on scale set instances is to reconfigure the deployment template with it, this method is not good for me as the scripts should be run on demand and are changed frequently and updating the template every time is bad practice.
Is there anyway to configure custom script extension on scale set instances on demand like on regular virtual machines?
powershell example for regular on demand script deployment on vm:
Set-AzureRmVMCustomScriptExtension -ResourceGroupName myResourceGroup `
-VMName myVM `
-Location myLocation `
-FileUri myURL `
-Run 'myScript.ps1' `
-Name DemoScriptExtension
I found a workaround for this using PowerShell and ARM JSON templates (I'm using Powershell version 5.1). In commandToExecute under virtualMachineProfile in your json template, specify a value that almost always changes and it will force the command to re-execute to run every time your template is deployed. You will see in my template that I added: ' -Date ', deployment().name to the commandToExecute. The value for deployment().name is specified in my New-AzureRmResourceGroupDeployment command as:
-Name $($(Get-Date -format "MM_dd_yyyy_HH_mm"))
The deployment name is based on the date and time, which will be different per minute.
PowerShell Command:
New-AzureRmResourceGroupDeployment -ResourceGroupName $ResourceGroupName -TemplateFile $PathToJsonTemplate -TemplateParameterFile $PathToParametersFile -Debug -Name $($(Get-Date -format "MM_dd_yyyy_HH_mm")) -force
The custom script extension section under virtualMachineProfile in my script appears as such (pay attention to the commandToExecute):
"virtualMachineProfile": {
"extensionProfile": {
"extensions": [
{
"type": "Microsoft.Compute/virtualMachines/extensions",
"name": "MyExtensionName",
"location": "[parameters('location')]",
"properties": {
"publisher": "Microsoft.Compute",
"type": "CustomScriptExtension",
"typeHandlerVersion": "1.8",
"autoUpgradeMinorVersion": true,
"settings": {
"fileUris": [
"[concat(parameters('customScriptExtensionSettings').storageAccountUri, '/scripts/MyScript.ps1')]"
],
"commandToExecute": "[concat('powershell -ExecutionPolicy Unrestricted -File MyScript.ps1', ' -Date ', deployment().name)]"
},
"protectedSettings": {
"storageAccountName": "[parameters('customScriptExtensionSettings').storageAccountName]",
"storageAccountKey": "[listKeys(variables('accountid'),'2015-05-01-preview').key1]"
}
}
},
This will allow you to update a Custom Script Extension on a Virtual Machine Scale Set that has already been deployed. I hope this helps!
Is there anyway to configure custom script extension on scale set
instances on demand like on regular virtual machines?
For now, Azure does not support this.
We only can use VMSS custom script to install software at the time the scale set is provisioned.
More information about VMSS extension, please refer to this link.

How to connect a database in Atom Editor?

I want to connect my database in atom and execute directly from the editor. How can I do that?
Install a package "data-atom" Reference. You can do it in two ways :
1.Through command line (windows) :
apm install data-atom
make sure you have ssl false, if not then type
apm config set strict-ssl false
before "apm install"
2.Open atom and go to settings and click on "+Install" and look for "data-atom" package.
Once you downloaded, restart atom and do "alt+shift+r" to open database window. Fill in the configuration and you are good to go.
Hope this helps
Install data-atom as recommended already by Sdembla. But beware, the recommended commands in the documentation for these packages do not work, until you first use "Edit connections", to create a connections file for it to work with.
Interestingly this also applied to the "data-ace" Atom package.
The exact steps (assuming you've installed the data-atom package, and restarted Atom) are...
click Packages > Data Atom > Edit connections
replace the generic file contents ("[ ]") with a connection config, like that shown in guzman's question here:
[
{
name: "WindowsAuthentication"
protocol: "sqlserver"
user: "username"
password: "password"
server: "apphost/Username"
database: "master"
options: ""
}
{
name: "SQLServerAuthentication"
protocol: "sqlserver"
user: "userlogin"
password: "password"
server: "apphost/sqlexpress"
database: "master"
options: ""
}
]
the other commands (eg ctrl-shift-R) should now work 😎
it's important you Save this connections file, otherwise the commands will stop working again.