Posts

Docker save and load images offline

 In some rare occasions, it was beneficial for me to save (export) the docker as a local file and load (import) the local file as docker image. Hence, I am posting the commands to save, load and tag the images to enable offline working with docker. In order to save the image, first we need to pull the image from a docker registry (default docker hub or any other registry). Pull docker image: docker pull postgres:10.6 Save (export) docker image: docker save -o /tmp/postgres-10.6.tar postgres:10.6 Load (import) docker image: docker load -i /tmp/postgres-10.6.tar See the loaded image: docker images postgres:10.6 Create a new tag from the loaded image: docker tag postgres:10.6 org.example/postgres:10.6

minikube as drop in replacement for Docker Desktop (Mac and Windows)

For a very long time, development time dependencies like postgres (database), kafka (message broker) was run using docker desktop (Docker for Mac / Docker for Windows). However due to recent changes to licensing, docker desktop is not free for all organisations. As a developer, if you are in an organisation who can't provide Docker Desktop, then minikube can be used as a drop in replacement for Docker Engine, so that your dependency scripts using docker cli can continue to work. The following contents explains the bare minimal commands needed to run minikube which will work if you are running dependencies using docker cli via: Shell scripts Maven docker plugin Gradle docker plugin TestContainers IDE (Intellij / Eclipse / VS Code) Plugin Install minikube: https://minikube.sigs.k8s.io/docs/start/ Start minikube: minikube start Stop minikube: minikube stop Delete minikube cluster: minikube delete Delete all minikube clusters: minikube delete --all See minikube dashboard: minikube dash...

Google Auto Value with Jackson Json

 I got a chance to work on a code base which used Google's Auto Value library and Jackson library for serialising and deserialising Json request and response payload. I tried to get the sweet spot with minimal need of annotations from Auto Value and Jackson. The following example shows the bare minimal change need to generate Json payload. It has the flexibility to construct the value object using builder pattern and ability to handle optional fields, collections and change the field name if required. package com.harishkannarao.example; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; import com.google.auto.value.AutoValue; import java.time.OffsetDateTime; import java.util.List; import java.util.Optional; import java.util.UUID; @AutoValue @JsonDeserialize(builder = AutoValue_ExampleModel.Builder.class) public abstract class ExampleModel { ...

ReactJs + NodeJs for Java Developers

  Background I am a Java Developer who enjoyed developing both server side web (frontend) and server side (backend) Http API. In recent years, Java or other JVM languages are predominantly used for server side API and NodeJs stack is the defacto standard for Frontend. This page explores the frontend (UI) development using ReactJs + NodeJs stack using Java lens by comparing tools and framework in Java stack. Source code available at:  https://github.com/harishkannarao/react-nextjs-rest-api In this repository, I explored the ReactJs ecosystem to build, test (unit and integration) and deploy a pure client side rendering (CSR) web application. Development Stack ReactJs is the basic building block to build the UI components and NextJs is built on top of ReactJs to create pages with routing and deployment tools for application built with ReactJs. Axios is a very popular Http Client library to fetch data from server side Http APIs NodeJs Java ReactJs  ...

nodeenv: Isolated node runtimes on MacOS

nodeenv allows to create isolated node runtimes per project which resembles to virtual environments in python world. In enterprise projects, where multiple projects are built against different versions of node runtime and dependencies, it is advantageous to have nodeenv to install multiple versions of node runtimes at project level. Install nodeenv brew install nodeenv or pip install nodeenv List available node runtime versions nodeenv --list Create latest node version as virtual environment nodeenv .nodeenv Create a specific node version as virtual environment nodeenv --node=14.15.0 .nodeenv Activate a virtual environment source .nodeenv/bin/activate Verify node and npm version node --version npm --version Install a package scoped to the virutal environment npm install -g cypress Deactivate or exit from virtual environment deactivate_node Delete the virtual environment rm -rf .nodeenv

GitOps - Viewing and Creating git tags

In a team following continuous delivery based on git tags or otherwise popularly known as GitOps, there will be a frequent need to list the existing tags in a repository in chronological order so that a new tag can be created based on recent commit (HEAD) from master / main branch. The following chained command will list all the remote tags in chronological order along with latest commit, so that new release tags can be quickly created through command line. List all annotated tags name with the commit SHA in chronological order along with recent commit id git fetch origin && git checkout master && git pull && git ls-remote --tags --sort=creatordate origin && git log -n 1 Create a new tag based on master / main branch or specific commit SHA and push the tag to remote server tag_name="production-v1.0" && git tag -a $tag_name master -m "Production version 1.0" && git push origin $tag_name

Creating python virtual environments on Mac OS with pyenv

Using pyenv Install pyenv through homebrew: brew install pyenv List installed versions of python: pyenv versions List available versions of python that can be installed: pyenv install --list Virtual environment for python 3: Install a specific version of python: pyenv install 3.9.0 NOTE for Big Sur (MacOS 11) users: If the install command fails, then try the command as SYSTEM_VERSION_COMPAT=1 pyenv install 3.9.0 Uninstall a version of python: pyenv uninstall 3.9.0 Switch to specific version of python in local terminal window: pyenv local 3.9.0 Switch to specific version of python globally: pyenv global 3.9.0 Switch to specific version of python using environment variable: export PYENV_VERSION=3.9.0 Get pyenv root directory: pyenv root Access the python installation: pyenv exec python --version Create a virtual environment from specific python version: pyenv exec python -m venv .venv Source the virtual environment source .venv/bin/activate Virtual environment for python 2: Install ...