GruntFile automated deployment using ssh (Windows) - javascript

I am trying to set up a GruntFile.js file to automate the process of logging on to my personal website's server via ssh and pulling the latest version of the git repo. The relevant part of my grunt file looks like this:
sshconfig: {
portfolioServer: {
host: 'mySite.com',
username: 'root',
agent: process.env.SSH_AUTH_SOCK,
}
},
sshexec:{
deploy:{
command: [
'cd portfolio',
'git pull'
].join(' && ')
},
options:{
config: 'portfolioServer'
}
},
However, when I run the associated task (I named it "grunt deploy"). I get the following error.
Running "sshexec:deploy" (sshexec) task
Warning: Connection :: error :: Error: Authentication failure. Available authentication methods: publickey,password Use --force to continue.
Aborted due to warnings.
My understanding is that this error means that I have not set up the public/private ssh keys correctly. However, I have already gone through the process of setting up public/private keys.I am already able to run the following command through git bash and log in successfully:
ssh root#mySite.com
I have searched online for this problem and it seems like it might have something to do with process.env.SSH_AUTH_SOCK not behaving in git bash on windows in the same way that it might be expected to be have in a native linux distribution.
What further steps in my setup do I have to take in order to make this deployment configuration work?

Related

typescript, javascript, angular, nginx, alpine, docker communications in the network via nginx i think i missed something. looking for a review

once i migrated to docker to have a virtual network to simulate an atual network (bridge type with dns which works . the fqdn is resolved correctly to referrring ip) the following errors appeared in the console.log AND no data is displayed on the frontend website.
ERROR Error: NG0901
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://backend:4000/crafts. (Reason: CORS request did not succeed). Status code: (null).
ERROR
Object { headers: {…}, status: 0, statusText: "Unknown Error", url: "http://backend:4000/crafts", ok: false, name: "HttpErrorResponse", message: "Http failure response for http://backend:4000/crafts: 0 Unknown Error", error: error }
thats the browser's (firefox) console.log
i think nginx is doing things with the headers and or the body is empty due to serversides configs with nginx
on local host everything worked out fine
so im on the config of gninx but so far without any success.. i read about similar problems but couldnt find a solution myself OR the answers read didnt work with my setup.
i tries to change the ip to 0.0.0.0 to make it accessable in the network
oh AND im using nodejs expressjs
app.listen(port,ip)
I use a Dockerfile and docker-compose.yml to make the images, i use a powershell script to compose the images
what i suspect to cause the problem is:
backend:
index.js is run anbd looks like that
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const express_1 = __importDefault(require("express"));
const Routes_1 = __importDefault(require("./Routes"));
const app = (0, express_1.default)();
app.use(function (req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "*");
res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
next();
});
// middleswares
app.use(express_1.default.json());
app.use(express_1.default.urlencoded({ extended: false })); //changed to see wheater it would effect the package isssue- should allow
app.use(Routes_1.default);
app.listen(4000,'0.0.0.0'); // or fqdn 'frontend'
console.log('server on port', 4000);
this is generated from index.ts and a build command
the referrring dockerfile:
FROM node:alpine as builder
WORKDIR /app/
COPY . /app/
COPY package.json /app/
COPY package-lock.json /app/
RUN cd /app/
RUN npm install -g
RUN npm update express
RUN npm install pg
FROM nginx:alpine
COPY --from=builder ./app/dist ./usr/share/nginx/html/
EXPOSE 3999-6001
CMD ["nginx", "-g", "daemon off;"]
RUN apk add --update nodejs
RUN apk add --update npm
after the image runs i open the terminal and run in the usr/share/gninx/html directory :
npm i express
npm i pg
node index.js
then I install vim
and edit the nginx.config like that
vi /etc/nginx/nginx.conf
i add a server directory, make it listen to the fqdn 'frontend' or its referring IP and the port 4000
listen ip:port kind of syntax
i add error and access logs earlier on and it doesn't return problems besides sometimes it says that IP are not available. im lacking on the understanding on how to interpret that
the PostgreSQL is also running in a docker container by the default port 5432 and the fqdn database which is also properly resolvable
same as the backend's fqdn
there is so much more stuff that links the short pieces of code that i have.. feel free to request more if interested or if u think it'd be required to find out whats going wrong.
I learnt my lesson..
servers listen to their own IPs, or at their localhost.
so i had a misconception there. though thanks to the pple taking a look inside here.
also a nodejs expressjs server doesn't necessarily need nginx to run on.. node is enough.. for the purpose..
fixing these two things led functionality as designed :)
so this can be closed or used as reminder on these two things:
understanding the conceptional idea of how networks work
AND
understanding the tech-stack being used and how it works
else
/closed

Gitlab Runner - listen_address not defined

I am setting up gitlab-runner locally on my mac to be able to run build and test scripts using docker. I have gone through the installation instructions listed on the Gitlab runners page to install the runner locally:
# Download the binary for your system
sudo curl --output /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-darwin-amd64
# Give it permissions to execute
sudo chmod +x /usr/local/bin/gitlab-runner
# The rest of commands execute as the user who will run the Runner
# Register the Runner (steps below), then run
cd ~
gitlab-runner install
gitlab-runner start
From what I can tell it is installed fine. I then registered a runner like so:
sudo gitlab-runner register --url https://gitlab.com/ --registration-token $REGISTRATION_TOKEN
(I obviously replaced $REGISTRATION_TOKEN with my token). When it prompts me for additional details I have entered the following:
Tags: (I left this blank)
Enter an executor: docker
Enter the default docker image: node:14.0.0
I then get the following message:
Runner registered successfully. Feel free to start it, but if it's
running already the config should be automatically reloaded!
When I then navigate to the root of my project I try and run gitlab-runner run but I get the following error:
Starting multi-runner from /Users/ben/.gitlab-runner/config.toml... builds=0
WARNING: Running in user-mode.
WARNING: Use sudo for system-mode:
WARNING: $ sudo gitlab-runner...
Configuration loaded builds=0
listen_address not defined, metrics & debug endpoints disabled builds=0
[session_server].listen_address not defined, session endpoints disabled builds=0
^CWARNING: [runWait] received stop signal builds=0 stop-signal=interrupt
WARNING: Graceful shutdown not finished properly builds=0 error=received stop signal: interrupt
WARNING: Starting forceful shutdown StopSignal=interrupt builds=0
All workers stopped. Can exit now builds=0
When I look at the config.toml if looks like it may be missing some configuration in there as the error above may suggest? Here is a cat of the entire file:
concurrent = 1
check_interval = 0
[session_server]
session_timeout = 1800
I'm not sure why i'm receiving this error message? Does my config look alright? When searching the issue I found another thread that said to just set "Can run untagged jobs" to yes which I have done but it still does not work...
It makes sense that you're having problems with the configuration.
If you read carefully the output, it says that you're running in user-mode, so I suppose you started the runner by using gitlab-runner.
Problem is that you registered your runner using sudo, so you configured the system-mode under /etc/gitlab-runner/. This configuration is loaded when you start gitlab-runner with sudo.
In order to verify that, you will be able to see the registered configuration under /etc/gitlab-runner/, with all the additional sections regarding Docker Runners and so on, instead of the basic configuration that you have under ~/.gitlab-runner/ which I suppose is the one you attached to your question.

Node.js Setup Wizard ended Prematurely on Windows 10 64 bit

I tried to install Node.js Setup for the first time (node-v8.9.1-x64 and node-v9.2.0-x64) on a system running Windows 10 64-bit , but it is giving the dreaded error
Node.js Setup Wizard ended Prematurely
Failed Attempts
Launching .msi from Command Prompt ran as Administrator
Disabling the installation options
Performance Counters
Event Tracing
Online Document Shortcuts
Registry Key Search
No registry keys were found when running the following
reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib\_V2Providers\{793c9b44-3d6b-4f57-b5d7-4ff80adcf9a2}" /s
reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib\_V2Providers\{1e2e15d7-3760-470e-8699-b9db5248edd5}" /s
The installation log shows an error status: 1603. [View Installation Log]
Node is not installed
node -v
Output:
'node' is not recognized as an internal or external command, operable program or batch file.
Attempt 3
Tried the following based on Github issue #4329, but theres no output after running this.
msiexec /i node-v8.9.1-x64.msi /qn+ ADDLOCAL=ALL REMOVE=NodePerfCtrSupport,NodeEtwSupport
Any ideas how to solve this problem?

How to set up SSH Agent Forwarding in node.js (simple-ssh module)?

I am new to this node.js and using module simple-ssh for executing shell commands from my windows to remote server.
Whenever I run my code, the console curses me with [Error: Authentication failure. Available authentication methods: publickey,gssapi-keyex,gssapi-with-mic,password,keyboard-interactive].
I have already put an RSA private-key file, and set the Windows ENV variable SSH_AUTH_SOCK. But still it keeps giving the error.
Below is the code snippet which I wrote for simple-ssh:
var ssh = new SSH({
host: sshHost,
user: 'root',
timeout: 11000000,
key: require('fs').readFileSync("D:/Keys_pair_prvt_pub/rsa_key"),
agent: process.env.SSH_AUTH_SOCK,
agentForward: true
});
When I am trying to SSH the remote from my windows cmd-prompt, it is giving me error:
$> ssh -A <myRemote.host.com>
ssh : The term 'ssh' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
Am I missing anything? If yes, then how do I overcome this ?
Any help will be appreciated :)
Thanks.
Your key needs to be added to ~/.ssh/authorized_keys on the server for your key to work.
mscdex npm package SSH2, which simple-ssh wraps, has this in the docs for using ssh.agent on windows:
`agent - string - Path to ssh-agent's UNIX socket for ssh-agent-based user authentication. Windows users: set to 'pageant' for authenticating with Pageant or (actual) path to a cygwin "UNIX socket."

Grunt-SSH error: Malformed cygwin unix socket file

I am trying to set up a Grunt task to ssh into a remote server and perform some operations using grunt-ssh. I am using git bash on a windows machine. The relevant parts of my Gruntfile.js are the following:
grunt.initConfig({
sshconfig: {
portfolioServer: {
host: 'myWebsite.com',
username: 'root',
agent: process.env.SSH_AUTH_SOCK,
}
},
sshexec:{
deploy:{
command: [
'cd portfolio',
'git pull'
].join(' && ')
},
options:{
config: 'portfolioServer'
}
},
........etc.
grunt.loadNpmTasks('grunt-ssh');
My problem is that when I run my grunt deploy task, i get the following error:
Running "sshexec:deploy" (sshexec) task
Warning: Connection :: error :: Error: Malformed cygwin unix socket file Use --force to continue.
Aborted due to warnings.
If I then run using the --force flag, I get the following output:
Running "sshexec:deploy" (sshexec) task
Warning: Connection :: error :: Error: Malformed cygwin unix socket file Used --force, continuing.
Warning: Connection :: error :: Error: Authentication failure. Available authentication methods: publickey,password Used --force, continuing.
Done, but with warnings.
This seems to suggest I have either set up my SSH authentication incorrectly, or that the commands I have used to get the command line to recognize my keys are poorly formed. This confuses me a little, as I have followed the instructions here to set up SSH keys on the command line, and am able to successfully ssh into my server by typing ssh root#myWebsite.com
What is going wrong?

Categories

Resources