Sunday, 20 September 2020

Simple way to deploy docker app on production machine

Small software house house/freelancer life isn't easy. Reading HN post about fancy new tech is amusing but as much as it is nice to read as much it's often not reachable for team counting one person.
So whenever I read something new I ask myself this simple question.

Is that new thingy/tech single dev scalable ?

Let's consider a docker application deployment problem. It's hard to do it both: quick and good enough (production ready).

Later, when the app matures/goes bigger you can create a proper CI but at this very beginning you need something simple. Here is how I do deal with it.

First deploy a local registry server push your app image there, next create ssh tunnel and do remote port forward. Finally fetch image from registry and run the app.

Let's try it out line by line. I do assume you have a docker build image named my-image-app (either created with docker build or docker compose) and want to deploy it to customer's customer-server.address.net on port 8888 over ssh.

First create a new local docker registry server. As docker docs claims it's as simple as:

docker run -d -p 5000:5000 --restart=always --name registry registry:2
Ok your registry server is up and running. Next push your app image to this new registry.
To do that you need to tag my-image-app with a correct name including registry address  ( ie. localhost:5000).

docker tag my-image-app localhost:5000/my-image-app
and then push it to the registry server

docker push localhost:5000/my-image-app
Next connect to remote server via ssh with remote port forwarding

ssh -R 5001:localhost:5000 customer-server.address.net -p 8888
Now you are logged into remote server and your local machine's port 5000 is visible on the remote machine on port 5001.

Finally run your app on the remote machine:

remote-prompt: docker run -d --name my-app localhost:5001/my-image-app

App is running. We are done.

What we can do even better here, is to write you customer server settings into your local .ssh/config file:


host customer-server
 HostName customer-server.address.net
 Port 8888
 User user
 RemoteForward 5001 localhost:5000

Then connecting to remote server is as simple as:

ssh customer-server

You may also consider adding your public key to  .ssh/authorized_keys  on the remote server.

UPDATE: one crucial command connect via ssh was missing when published this first time
UPDATE1: fixed authorized_keys entry

Friday, 6 September 2019

Install Optic Slim 2400+ on Ubuntu or any other linux



Easy to use scan app for linux  simple-scan can be used for scanning on linux

Here is how to make it run with Optic Slim 2400+ scanner

Install sane 

sudo apt-get install sane

Create scanner dir in sane shareed location:

sudo mkdir -p /usr/share/sane/gt68xx

Copy cis3R5B1.fw file to /usr/share/sane/gt68xx/

sudo cp cis3R5B1.fw usr/share/sane/gt68xx

Now open simple scan app - that's it !

Friday, 29 December 2017

Tensorflow with Jupyter Notebook - getting started

I started learning Tensorflow with this awesome course on Udemy.

Even if you don't want to buy the course (although it's worth it's price). You can play with Tensorflow yourself using jupyter notebook. So here are a simple steps to make it possible (note: not all packages mentioned in step 4 are necessary. It's just convenient to have them when doing real projects)


  1. First install Anaconda python distribution with Anacaonda installer docs for your OS
  2. Create new conda environment with:
    conda create -n tensorflow python=3.5
    where tensorflow is your env name
  3. Activate tensorflow env with:
    source activate tensorflow
    (Linux and OSX)
    or
    activate tensorflow
    (Windows)
  4. From terminal install conda packages with:
    conda install jupyter
    conda install numpy
    conda install pandas
    conda install scikit-learn
    conda install matplotlib
    conda install tensorflow
    (or conda install -c conda-forge tensorflow)
  5. Run Jupyter Notebook using:
    jupyter notebook
Finally you can test your environment in Jupyter inserting few commands in a new book.

So after browser shows jupter dir structure press 'new' and select Python 3. In a new document start typing:

import tensorflow as tf

and press shift+enter to run the code.

No error should appear. Then do the same with lines:

hello = tf.constant("Hello World")
sess = tf.Session()
print(sess.run(hello))


If everything went well you should see something like on the screenshot below.


Jupyter Notebook with tensorflow



Thursday, 28 July 2016

Why I like Dart more over Typescript

If you are new to web development you can feel lost. Understanding web development lets say ten years ago was much easier. Developing web app in PHP or ASP was easy to understand. All in all those frameworks were just smart template engines. These days web is more dynamic and much more client side. Progressive Apps and other modern trends make web apps usable even when you are offline

There are plenty of JavaScript and compiled to JavaScript languages. To make it worse there are zillion JS frameworks out there. Selecting good tools for doing modern web apps can be challenging.

I'm doing a lot of so called SPAs (Single Page Applications). Most of them are done in Dart or Javascript with superb IntelliJ. Some time ago I tried to use Typescript with VisualStudioCode in one of smaller projects. After this experiment I still like Dartlang more for web apps and here is why.

Reasons I like Dart more over Typescript

  1. Dart analyzer is usually able to show more common mistakes even if you are not heavy type user. In real life dev you usually do plenty of simple typos. In Dart - thanks to fantastic Analyzer - time to find them is way shorter.
  2. It's easier to start debug in Dart and it's more reliable. This could be IntelliJ itself.
  3. Code in Dart is shorter for small apps since it has build in SDK - there is no need for external libs in simple apps.
  4. It's easier to back to this code after few weeks (shorter less dependencies) and easier to maintain it. Also time needed to start from scratch is shorter.
  5. Pub is modern lib/package mechanism (versioning, automatic fetching) and is way superior to what is there in Typescript world. There is single library index site: pub.dartlang.org
  6. Dart has one mechanism for library importing (which doesn't confuse me!)
  7. I'm not afraid if library x conflicts with library y
  8. await async works on non ES6 browsers - no wired settings in main config file!

There are still things I like more in Typescript


There is one thing better in TS which I like very much - how interfaces can be applied to Maps allowing using json as typed object.

Monday, 14 July 2014

Set of informative links regarding Linux/Unix

Redit Linux http://www.reddit.com/r/linux/
Name says it all http://www.unixmen.com/
Not exactly Linux but often geeky https://news.ycombinator.com/
Ubuntu and desktop oriented - still valuable http://www.omgubuntu.co.uk/
Based on: http://www.reddit.com/r/linux/comments/2alzzf/informative_linux_websites/

Wednesday, 18 September 2013

Yet another linux CLI tips & tricks list (updated)

Yet another linux CLI tips & tricks list

(update: 2017-12-15 added few magic mc commands at bottom)

When I started my jurney with *nix like systems, the environment was hostile to me. But after a few years it become obvious that the CLI is a superior way of dealing with Linux OS. You can see a lot of similiar articles in the web like here or here but this list is stripped to what I find useful on the one hand, eliminating obvious on the other (eg. I'm assuming that you know you can browse hostory with arrow key or use tab for apt-get install completion).
So here is my list.
Reverse search is one of the most important key shortcuts when using CLI, because usually you don't remember what exact arguments were used in in your beloved tricky_and_very_long_command you've commited in the past. You will find out that in the real life there is a limited number of commands (with minor modifications) your are using frequently.

ctrl+d leave or exit from console/ssh session etc

current line navigation commands

  • ctrl+e go to end of line
  • ctrl+a go to begining of line
  • ctrl+u delete till begining of line
  • ctrl+k delete till end of line
  • ctrl+w delete word before cursor
NOTE you can change default bash editor to vi like editor with: set -o vi command

tmux

Allows executing commands on a detached console (useful when doing something via ssh and can't/won't have open session) - this should be a separate blog post but here is my cheat sheet
  • tmux start a new tmux session
  • tmux a or tmux attach attach to an existing tmux session
while in tmux session
  • ctrl+b+d leave (d for detach) tmux session not killing it
  • ctrl+b+c create a new pane
  • ctrl+b+n next pane
  • ctrl+b+p previous pane
  • ctrl+b+" split pane horizontally
  • ctrl+b+% split pane vertically
  • ctrl+b+arrow go to: up right down left panel
  • ctrl+b holding ctrl key and pressing one of arrow keys - allow change panel size!
NOTE: nice thing about tmux is...you can use tmux in tmux by doing double ctrl+b

mc - Midnight Commander

If you are old enough (like I am) you do remember famous Norton Commander or Total Commander. Midnight Commander is a similar tool - superior when it comes to copy files over ssh or ftp.
NOTE: if an escape key esc is not present int your keyboard - like in many bluetooth keyboards - you can use ctrl+[ instead.
  • ctrl+\ - open favorite location list (then add current, edit, delete)
  • esc+9 - open right pane menu
  • esc+0 - exit
  • esc+h - in any entry field (like 'open ftp/ssh' dialog window) wherever ^ character is present - opens current entry field history dialog
  • alt + o - display dir under cursor on other pane
  • alt + i - display current dir on other pane
  • alt + . - display/hide hidden files
  • alt + h - display history
  • alt + y/u -  change dir to previous/next dir

Simple way to deploy docker app on production machine

Small software house house/freelancer life isn't easy. Reading HN post about fancy new tech is amusing but as much as it is nice to read...