Web console for docker container - javascript

Situation
There is a data-only-container named: app-data
There is a copier container worker
Initially app/data was created and that's it, it's status is 'stop' / exited.
Then the copier worker copies some files to app/data as its volume, for example an server.py
Okay this was done like this:
docker run --rm --volumes-from app-data /somelocation/server.py ~/www/
the copier takes 2 arguments, the file to copy and where to copy
With that at hand, I can run a image named app/serve to server the file in the volume like so:
docker run --volumes-from app-data -d -P app/serve
the image entry point do this http-server, and workdir is same as the data volume, so it'll run
Hell yeah it works, and the python web app can be accessed in the host with a highport like so: 0.0.0.0:49124 because
the app/serve image expose ports 5000 which is used by the sever.py script
I had the above working, you can focus below.
So the app can run huh? But I want to do more complex things that just running the app (I ran the app using the remote api), what if I want to run the app using a web console connected to a docker container.
My Idea of how would it be possible
use term.js
expose 2 ports e.g. (4000, 5000)
use port 4000, so that when term.js executes in port 4000, it'll generate a highport for the client to use in the web console socket connection
use port 5000 to allow whatever web application ran in port 5000 will be available in a another highport, to be accessed like so 0.0.0.0:49124
This is a prototype implementation of how runnable/dockworker do this, I am still new to nodejs that is why I cannot comprehend how they do it, could there be a less-featured simpler execution of this idea?

Related

Lighsail Bitnami MEAN Stack Application Continuous Running

I have an MEAN application running on server through Amazon Lightsail. I installed my application in the /projects folder and once I ssh onto the server and run node bin/www (where my main startup scripts live) the site runs perfectly. The issue comes once I close the ssh shell the site goes down (node stops running). Does lightsail / AWS provide any utilities to keep up the server or do I need to manually install a service that keeps it up so I can point a domain at the IP and it is consistently running?

Debuging expressjs server alongside electron

I've successfully running expressjs server alongside electron as described on here:
Run Node.js server file automatically after launching Electron App
The problem now, there is no output from command line related to server activity. I simply run
electron .
on project directory, then no other output related to the server.
Is there any way to get that server activity logged onto cli as normally I run with (like just) node server.js ??
Perhaps you can try using the node module concurrently. This will allow you to run two commands at once and is used commonly in development with electron.
Instead of getting the server and electron to run from within the same file, separate it into a server file and an electron file. For example, one of my main development techniques is this:
concurrently "npm run server" "npm run start-app"
Which runs my hot-reload server, that my electron app connects to in development mode.
By using concurrently you can see the output of each process as well.
A good example of this technique in practice is with the electron-react-boilerplate repository. If you're interesting in this style of development I recommend you clone that repository and give npm run dev a try, to see how their development process works (whether you're using React or not).

Run sails.js with least privileges in Production

I'm using Sails.js 0.10.5 on Node 0.10.33 on Ubuntu Trusty. I'd like to execute the node process as a non-root user with the least possible privileges in the production environment. I'm comfortable with the various options for binding to ports below 1024 but I'm more concerned with directory permissions.
Ideally, I'd prefer the node process only have write access to its log files and nothing else. It should only have read access to the directory containing app.js and below.
At the moment I have needed to grant write access to the ./.tmp directory and also to the ./views directory due to the grunt tasks that run at startup. I'd rather perform the grunt tasks at deploy time as a different user instead of at run-time. The sails www command appeared promising but I couldn't get the desired outcome.
Can someone please point me in the right direction for running Sails.js with zero write access to its assets, views, etc?
Use sails www to build static assets
chmod -R 440 all files and directories, so that your user and the webserver (group) can access the files.
Use nginx/apache to host a webserver on port 80/443 and proxy requests to sails (running on its own port or over a unix socket).
Run sails using PM2 to keep it running and have it manage/collect logs.
Sails will lift, but will be unable to write its .tmp directory, which shouldn't even be necessary since all your static files will be routed to the www directory through nginx/apache.
The simplest solution to me seems to be to separate the grunt tasks that need the elevated privileges out into a separate file that you can call with a different user on deploy. Then sails won't need to run anything and can be read only.
EDITED: I use PM2 with apache as proxy ( with mod WS ).
You can use one proxy like apache to route from port 80 to others internal server ports based on host.
With this way you can run multiple apps in same server.
It has a lot of usefull functions like see the logs how varius apps in terminal, restart and log crashed apps, run app as user, app status ... etc .
Pm2 link: https://github.com/Unitech/pm2
PM2 configs: https://github.com/Unitech/PM2/blob/development/ADVANCED_README.md#options

How to use a browser on a remote server for an automated tests

I inherited a project where the person wrote tools to test our site's UI using JQuery and JS.
I don't know too much about it other than it requires a browser to be spawned and I think the tool uses JS to interact with iframes to see if it's the expected values.
My job is to get this tool to run on a remote server and post the results to Jenkins.
The remote test server and staging server is linux. From our staging server, I want to write a script to spawn a browser and run cmds from the tool to test our UI. I ran the following manually:
ssh -X user#remote_test_server /usr/bin/firefox
However, the remote server says:
Error: no display specified
Is there a way to spawn a browser for automated testing from one headless server to another? Thanks in advance for your help.
I faced a similar problem when I tried to automate a GUI installation program. While there are quite some different possibilities to choose from (e.g. Xnest, Xephyr?), I ended up using vncserver, because it's relatively easy to debug the GUI session this way.
You need to create a vncpassword file, I think:
mkdir -p $HOME/.vnc
chmod 0700 $HOME/.vnc
echo MyLittlePassword | vncpasswd -f > $HOME/.vnc/passwd
chmod 0600 $HOME/.vnc/passwd
Starting the server is then quite straightforward
vncserver
export DISPLAY=:1
/usr/bin/firefox&
...
Now it is possible to connect to the VNC server with a VNC viewer of your choice. But beware there may be no window manager, depending on the X startup scripts of your environment.
Shutting the server down
vncserver -kill :1
In the configuration of Jenkins project , specify the
Build Environment
Start Xvfb before the build, and shut it down after.
#

Node.js on Amazon AWS goes down when Putty SSH is disconnected

I just set up my first Amazon AWS server, with a Node.js installation on it. I run my app, at which point Node says that it's listening on port 3000. However, if I close my laptop, Node.js is no longer reachable through my app. How can I make it run even when I'm not logged in to the server through Putty? As a follow-up question, how can I re-open the Node instance (so that I see the any console.log messages from it) when I log back in to my server?
Thank you!
This is part StackOverflow, part Serverfault question I believe. It sounds like the problem is you're running the node server in the foreground of your SSH session, but you'd rather run it like a service (in the background).
When you exec something like that simple node server, you're running it (by default) in your SSH connection, which ends when your connection terminates from sleeping your computer. Some scripts/programs will run by default in the background, but if you're seeing results in STDOUT (printing to the shell) it is running in the foreground.
Highjacking these answers: Node.js as a background service
Two solutions
*nix solution: http://en.wikipedia.org/wiki/Nohup
Node solution: https://github.com/nodejitsu/forever

Categories