Saturday, July 14, 2018

Playing with Docker

It's been stressful at work, home, and everything else but I have had some time to learn new technologies (or learn more about them). I just published my first node-red node called node-red-contrib-mytimeout. It started out as a clone of Pete Scargill's node-red-contrib-timeout. I just wanted to learn how to create a node and publish it. It quickly morphed into a node of it's own. I found I didn't really understand Pete's code so I poked at it until it did what I wanted. But the code ended up having so many corner cases and patches to get it to work that it became unmaintainable. So I rewrote it starting with a simple state machine. Then I started to run into the corner cases (mostly the different types of input) that the node needed to handle. So I rewrote it again and again and again. I think it's much better now. :-) I'm not saying it's the best way to do things or that I'm a great programmer just that it's better than it was ... a lot cleaner. One thing I picked up was putting node-red into it's own docker container. That helped with testing the new code. Which is all manual at the moment. It seems that I need to learn to make better use of git branches to deal with master, hotfix and features. I did try to make use of node-red-node-test-helper but I don't quite understand it yet and I haven't been able to get the examples to work. I'll spend a bit more time with docker and node-red and understanding node-red-node-test-helper. I did manage to find the solution to being able to do a docker exec and getting an error

$ docker exec -it mynodered /bin/bash
unable to find user node-red: no matching entries in passwd file
$ docker exec -it -u 1001 mynodered /bin/bash
node-red@49cd98fddf2e:~$

I figured out 1001 for user node-red by looking at the /etc/passwd file that I copied out of the container. I could have also logged in as root with 0 and poked around but being root should be limited to only when you need it.

Once I figure out node-red and some kind of reasonable testing strategy I'll have my first Continous Integration (CI) project completed. I do see the full value of this as a way not to repeat the mistakes of the past.

PS: I made one change to my package to run mocha instead of node and the basic test suite ran fine (yeah!). I've since added a bit more basic functionality (unit?) testing and it too runs and passes. Not on to the more complex features. The test quite itself will be as complex as the code it's testing. So do I need a test suite for my test suite? ;-)

0 Comments:

Post a Comment

<< Home