Sunday, October 4, 2020
What is Azure Container Instances
Azure Container Instances (ACI) allows us to deploy individual containers in Azure without having to provision Virtual Machines.
It is kind of a serverless computing environment where we can deploy our applications as Docker containers in Azure Container Instances.
Creating an Azure Container Registry (ACR)
We can create an Azure Container Registry (ACR) in different ways, using Azure CLI or Azure Portal or Powershell. In this post, we shall see how to create an Azure Container Registry using Azure CLI.
The first step in creating an Azure Container Registry (ACR) using Azure CLI is to log in to Azure CLI. Open a command prompt and enter the command.What is Azure Container Registry?
Azure Container Registry is like a private DockerHub in Azure. It is a managed private Docker registry service based on the open-source Docker Registry 2.0. Create and maintain Azure container registries to store and manage your private Docker container images and related artifacts.
We can configure to push the docker images into Azure Container Registry. Familiar tools such as Azure DevOps and Jenkins CI/CD pipeline can be configured to use Azure Container Registry as a build endpoint.
Azure CLI
Azure CLI (Command-line Interface) is a command-line tool for Manager azure services. It's like Angular CLI, it provides various commands to manage Azure services in an Account. Before we can start using Azure CLI we need to install it, the latest version of Azure CLI can be installed from the following site.
https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latestOnce Azure CLI is installed run the az --version command to make sure that the installation was done successfully.
Thursday, October 1, 2020
Create Docker Image with .Net Core executable
In the previous post we saw how to create an Executable (.exe file) for a .Net Core console application. In this post we shall see how to package this .exe into a Docker image and deploy it as a Docker Container.
First we will have to create a Dockerfile, we will create this file in the publish folder where the publish results (.exe files) are created.
Creating Executable from .Net Core Application
Monday, September 28, 2020
Updating Dockerfile and rebuilding images using VisualStudio
In the previous post we saw on how to create a .Net Core console App and use Visual Studio to automatically add Dockerfile to the project. In this post, we will see how to change the Dockerfile created by Visual Studio and rebuild the Docker image with the modified file.
Once the Dockerfile is created we
can manually exit the Docker file Add/Modify steps and rebuild the Docker image.
In this sample, we will add proxy settings to enable package restore in a
Corporate firewall environment.
Create Dockerfile and Container using Visual Studio
Visual Studio provides an option to automatically add Docker support. Using Visual Studio we can add the Dockerfile to a project without having to manually create one. Visual Studio will create the Dockerfile with the commands pre-populated based on the type of project, we create.
In this post, we will create a Console application using .Net Core and use Visual Studio to automatically create the Dockerfile for the Project. First, let us create the following Console application.Friday, September 25, 2020
Building an ASP.Net Core Web App Docker image
In this post we shall see how to create a basic Asp.Net core Hello World App and package it into a Docker image. We will deploy the image as a Docker container and execute the Asp.Net Core application from Docker.
First let us start by creating an Asp.Net Core application using Visual Studio 2019Building a Node App Docker image
In the previous post we saw how to build a HelloWorld Docker image, in this post we will create a Docker image for a Node.js application.
First let us create a basic Node server using Express which will respond with a Greeting message in the root path (/).
Building a HelloWorld Docker images
We have seen how to pull a Docker image from DockerHub and run in, now we will see how to create our own Docker image, build and run it.
The first step to create a Docker image is to create a Dockerfile.
Dockerfiles is a text file that contains instructions and steps to create a
new Docker image.
A Dockerfile has no extension. If you are using docker on windows use notepad to create a dockerfile while saving select "All type" and save the file name as "Dockerfile".
Friday, September 18, 2020
Listing and Removing Docker Images
In the previous post we saw on how to pull and run Docker
Images from a remote repository. Once we pull a Docker Image, it gets stored in
the local repository. We can use the image
ls command to view the list of images in the local repository.
Listing and Removing Docker Containers
Docker supports a set of commands to operate on Docker Containers. It supports commands to list Containers, Remove containers etc. Below are some of the commonly used commands for Docker Containers.
Pulling Docker Images
In the previous post we executed the docker run command and noticed that the Docker Engine automatically pulled the hello-world image from DockerHub. We can also use the docker pull command to explicitly pull Docker images from the remote repository (DockerHub) to our local DockerRepository.
To pull images from the remote repository to the local repository we need to use the docker pull command as follows.Running first Docker Container
Once we install Docker and make sure it is up and running we
can start running our first Docker
Container. Let us run the hello-world Docker container, this container is
present in the DockerHub. We will use the docker run command to run the
container as follows.
Monday, September 14, 2020
Docker Desktop
Depending on the version of Windows operating system, we need to either install the Docker Toolkit or Docker Desktop. For Windows version less than 10, we cannot install Docker Desktop for these versions we need to install Docker Toolkit. For Windows 10 we can install Docker Desktop. It is recommended to install Docker Desktop.
Once Docker Desktop is installed, it will start and we can see an icon in the Toolbar.Installing Docker
To get started with using Docker we need to download and install the Docker setup. Docker can be installed in multiple platforms Windows / Mac / Linux. We can get the appropriate version of Docker from the below link and install it to get started.
Friday, September 11, 2020
What is Docker Network?
As the name suggests Docker network allows docker containers to communicate with other containers and with the outside world. Docker supports different types of Network configuration depending on the name of the Application / Docker container setup.
Monday, September 7, 2020
What is Docker Engine?
The Docker Engine is the
heart of the Docker platform, it consists of 2 main parts.
The Client
side (Docker CLI & Rest API) is used to fire commands
The Server side
(Docker Daemon) is used to process the commands and manages Containers.
What is Docker Hub?
Docker Hub is a service provided by Docker for finding and sharing container images. It allows us to push new images and pull existing images from the Hub. DockerHub is like GitHub we can user push/pull commands to manage Docker images. GitHub allows us to store and version controls our source code, while DockerHub allows us to store and version control Docker Images.
DockerHub is the default registry used by the Docker engine. DockerHub hosts public and private repositories, it also provides automated builds, organization accounts, and integration with source control solutions like Github and Bitbucket.
What is Docker Registry?
A Docker Registry is a storage and distribution system for named Docker images. The Docker registry is used to store the static Docker image templates. The same image might have multiple different versions, identified by their tags.
A Docker Registry is organized into Docker repositories, where a repository holds all the versions of a specific image. The registry allows Docker users to pull images locally, as well as push new images to the registry.
DockerHub is the default registry used by the Docker engine, it is the Docker's public registry instance. It is possible to run on-premise the open-source Docker registry/distribution, as well as a commercially supported version called Docker Trusted Registry
Sunday, September 6, 2020
What is Docker Daemon?
The Docker Engine has a client-server setup where can client can fire commands and the Server processes the commands to create and maintain live Docker Containers.
Docker Daemon is the server-side of the Docker Engine, all running Docker Containers are managed by the Docker Daemon. Docker CLI and API are the client-side of the Docker Engine which sends commands to the Docker Daemon. A daemon can also communicate with other daemons to manage Docker services.What is a Docker Image?
A Docker Image is a lightweight, standalone, executable package of software that includes everything needed to run an application: code, runtime, system tools, system libraries, and settings. A Container image is a static template version of a Docker Container, it is stored in the Docker registry.
Container images become containers at runtime and in the case of
Docker containers - images become containers when they run on Docker Engine.
When we execute the $ docker run command the container
image is fetched from the registry and loaded in the Docker Daemon server to
make it a live executing container.
Thursday, September 3, 2020
What is a Docker Container?
Docker Container vs Virtual Machine
A Docker Container can be seen as the next version/improvement to a Virtual Machine. Each Virtual Machine in a server needs a separate Guest operating system to function, but all the Docker Containers in a server use the same underlying Operating System of the server, hence Dockers are lightweight when compared to Virtual Machines. Also, Dockers are faster to spin up and execute when compared to Virtual Machines.
Since each Docker containers don’t need a separate Operating System we can spin up many Docker Containers in a server then the number of Virtual Machines it can handle.
What is Docker?
Wednesday, August 26, 2020
What's new in Angular 10
What's new in Angular 9
ng update @angular/cli @angular/core
What's new in Angular 8
Differential loading
With differential loading, the Angular production build will produce 2 separate bundle files. One ES5 bundle for legacy browsers. Another ES6 bundle for the latest browsers which support ES6 features. This helps in improving the loading speed and performance in modern browsers since this bundle file is smaller in size.
Tuesday, August 25, 2020
Using EventEmitter with @Output
In the example, we have a ParentComponent and a ChildComponent, the child component has a button and a @Output decorator. In the buttons click event, we will trigger the emit event of the EventEmitter associated with the @Output parameter, we will also send a payload along with the emit.
What are EventEmitters?
To pass values from a parent component to a child component we use the @Input property/decorator.
To pass values from a child component to a parent component we need to emit an event using @Output and EventEmitter. Both are parts of the @angular/core.
Sunday, August 23, 2020
Promises vs Observable
Observable is lazy, they don’t trigger until it has a subscriber.
Promises returns only one value
Observable can return multiple values overtime to its subscribers
Promise cannot be canceled, once a promise action is triggered it will execute and return the result
Observable can be canceled, we can call unsubscribe to stop receiving responses from the observable
Promises can be converted to observables, the RxJs library provides a from operator which can convert a promise to an observable. We can use this to deal with some legacy code that is returning promises.
import { from } from 'rxjs';
const myObservable = from(myPromise)
Consuming Observables using async pipe
The view template consumes this Observable and displays the response from the http call in the View template. The async pipe automatically subscribes and unsubscribes to the Observable, whenever a new value is emitted from the Observer the async pipe automatically detects the change and refreshes the component.
Consuming Observable using Subscribe
Creating observable using Inline Arrow functions
In the below example we will create an Observable with an inline function which emits the current time, we use setInterval to emit a new value every 1 second.
Creating Observable
In the below sample we create a function listGenerator, which takes an observer as a parameter and emit list values one at a time using .next().
Friday, August 21, 2020
What is Async Pipe?
For promises, it automatically calls the "then" method.
For observables, it automatically calls subscribe and unsubscribe.
To use the Async Pipe to handle observables in Angular template we use | async followed by the observable, this will automatically subscribe to the observable and refreshes the component whenever a new value is emitted from the observable.
AsyncPipe uses the OnPush change detection out of the box. We need to make sure that all our business logic is immutable and always returns new objects.
Observable in Angular
What is RxJS?
RxJS offers a number of functions that can be used to create new observables. These functions can simplify the process of creating observables from things such as events, timers, promises, and so on.
What is an Observable?
Saturday, August 15, 2020
Angular Dependency Injection
Angular Singleton Services
@Injectable({
providedIn: 'root',
})
Friday, August 14, 2020
Fetch async data using Redux Thunk example
Assuming that we have the required npm packages installed and the redux-thunk middleware configuration is setup as specified in the previous post we will go ahead with the actual implementation of redux-thunk and axios api calls.
We create 2 actions, first to set the locations array in the store and the 2nd to set a success/failure message.
Adding Redux Thunk Middleware to a React-Redux App
To start with we need to install the redux-thunk middleware npm package.
npm install --save redux-thunk
Next we need to add the middleware in the createStore method as follows.
What is Redux Thunk
Adding Redux to a React App
In this sample we will create a simple React application, with a textbox where the user can type his name and a button on click of which a Welcome message is displayed with the name. The onChange event of the textbox and the onClick event of the button will dispatch actions to update the corresponding property in redux store.
mapDispatchToProps in Redux
If mapDispatchToProps is not defined in connect, there is another way to dispatch actions from React components. In this case props.dispatch is passed to the component and using this we can dispatch actions to the store.
mapStateToProps in Redux
mapStateToProps take the state object (the same value returned by a call to store.getState()) as the first argument and return a plain object containing the data that the connected component needs. This function should be passed as the first argument to connect, and will be called every time when the Redux store state changes.
store in Redux
In the previous posts, we saw how to create the store object using createStore and use it to initialize the application. Redux store also allows us to subscribe to events that update the store object. This can be useful to debug changes to the redux store.
In the createStore code of the previous example we will add a subscription to display changes to the state to the console as follows.
combineReducers in Redux
When the application grows it might be difficult to hold the state of all the components in a single file, as it will grow too big making it difficult to maintain, we would like to split the reducer code across different reducer files for maintainability. To achieve this redux provides a utility combineReducers(), this can take multiple reducers and merge them into a single reducer before assigning it to the store.
Let us extend the previous example, add multiple reducers and use combineReducers() to merge them into a single reducer and assign it to the state as follows.
Reducers in Redux
Reducers take the previous state of the app and return a new state based on the action passed to it.
In the previous post, we was a SET_NAME action below is the reducer which handles the SET_NAME action.
Actions in Redux
Below is an example of a simple action object.
What is Redux?
For React applications Redux provides a centralized state container for the whole Application. Redux holds a large JavaScript state object which can be shared across the application.
Thursday, August 13, 2020
React TypeScript stateless Function component example
In this post, we will see how to create a simple Hello World function component in React using TypeScript.
React TypeScript Parent - Child components example
In this post we will alter this component a bit so that the greeting message is passed as a property from the parent component.
React TypeScript component with State and Events
The React component initializes state, notice that we are using the State interface with strongly types properties to define the state object, this is the advantage of TypeScript it allows us to define strongly typed properties which help us capture type errors during development. The state object has 2 properties message and name.
React Component Lifecycle Overview
React ES6 Examples
Angular Provider Scope
To limit the scope of a service to a module we need to specify the module in the providedIn instead of ‘root’. In the below code the HellpService is made available only to the HelloModule, the service is not available to any other Modules in the Application.
Angular Service Scope
Services can be registered with 3 levels of scope
1. Global Scope
2. Module Scope
3. Component Scope
Wednesday, August 12, 2020
What are Angular Services?
1. Global Scope
2. Module Scope
3. Component Scope
Sunday, May 24, 2020
HelloWorld create-react-app Application using TypeScript
In this post we will use the create-react-app package from Facebook to quickly create a React application using TypeScript.
Open a command prompt and run the following command.
HelloWorld example in React with TypeScript
Assuming we have a root folder and the environment setup with required npm packages installed and config files we will go ahead and create the Application files. First let us create the following folder structure for the React components.
Set up React dev Environment using Webpack and TypeScript
When we created React Applications using JavaScript (ES6) we used the Bable loaders to transpile ES6 code into browser compatible JavaScript code, in case of TypeScript we will have to use a TypeScript loader (ts-loader) instead of Bable. In this post we shall see in details on how to setup the environment for creating React applications using TypeScript.
First to start with let us create a new project by running npm init
React Hello World using create-react-app
Let us create a React application hello-world using the following command.
npx create-react-app hello-world
The command will install all the required packages and the basic files for a startup React application. Once the command is completed it creates the following files and folders.
What are React Boilerplates
We need to install react, bable and web-pack packages. Create configuration files for web-pack and bable. Create a root Html page (index.html), create at least one React component and a root class to load the component in the HTML DOM using ReactDOM.render. That’s quite a bit of work to do the simplest Hello World sample.
Friday, May 22, 2020
React Environment Setup and Build Tools Overview
React Environment Setup and Build Tools Overview
|
Source Map
In the previous posts we saw how Bable compiles the ES6 & JSX code and transforms them into JavaScript and how webpack bundles the individual files into a common bundle.js file. As a result of the transpilation, minification and bundling process we are left with a large JavaScript file which is almost impossible to debug, but we cannot avoid these steps since they are required to make the JavaScript application secure and performance efficient in the production environment. If so then how do we debug issues in production environment, the answer to this is Source Map.
Thursday, May 21, 2020
Bable
Webpack cannot compile ES6 JavaScript code, hence it used loaders to transpile ES6 and JSX code. In the React sample we used bable-loader in the webpack configuration to compile ES6 and JSX code into native JavaScript code.
For the React Application we used the following 3 bable packages
npm package-lock.json
In the previous post we saw about the semantic versioning for npm and the various wild cards associated with this versioning. We saw that the package.json by default uses the carot (^) wildcard for package versioning, this allows for auto upgrade of the minor and patch versions.
Let us say we have the following entry in our package.json file for react
"react": "^16.8.3"
Wednesday, May 20, 2020
npm semantic versioning
Minor version – Minor versions will include feature additions without breaking changes
Major version – Major version changes can include breaking changes
NPM
The command npm init is used to create a new project, this command will create a project.json file which will record all the dependent packages required for the project. If also records the commands to be executed when we build/run/test the Project.
The package.json file for our Hello World React application looks as follows.
Webpack
Webpack is configuration driver, remember we created a file in the webpack.config.js previous Hello World post, this is the webpack configuration file. The most minimal webpack configuration includes and entry (input) and an output.
Sunday, May 17, 2020
React Setup and Build Tools
Setting up React dev Environment using Webpack and babel
1. First let us create a folder ReactHelloWorld, we will setup the environment and create the Hello World component in this folder.
2. Next make sure node is installed in the pc, if not installed already install the latest version of Node.js. We can check if Node is installed by running the command node –v, if Node is installed this command will return the version of Node.js Installed in the pc.
ReactHelloWorld>node –v
v8.12.0
Saturday, May 16, 2020
What is Reconciliation?
React reconciliation is based on 2 assumptions
What is React Fiber
To better understand React Fiber we should first understand the concept of Virtual DOM and Reconciliation in React, let us look at these in brief.
Wednesday, May 13, 2020
React.Profiler component example
We will use the useEffect example and add React.Profile to it. The sample consists of a Parent component App, child component UseEffectComponent and the Root ReactDOM to load the App component. We will add Profiler to the App component in the Root and add Profiler component for UseEffectComponent in the parent App component as follows. Remember we are using create-react-app boilerplate to create these examples which will have additional supporting files.
React.Profiler component in React 16.9
React 16.9 introduces the new React.Profiler component which avoids the drawbacks of the earlier DevTools based Profiler. The Profiler API is programmable and we can configure it only for specific applications. Also the Profiler API does not need DevTools support it can capture and write performance logs to the console directly.
Friday, May 8, 2020
useEffect Hook example in React 16.8
In this sample, we will use the useEffect hook to change the title of the document. We will use the value from the state prop title to set the document title as Hello + {title}. Initially the title will be displayed as Hello React, on clicking a button we change the state value of title, which in-turn triggers the useEffect and changes the document title.
useState Hook example in React 16.8
In this post we will create a function component and define a state prop count using the useState hook, we will attach a function setCount which will be used to change the value of the count prop. We will also attach the setCount function to the click event handler of a button, so that each time the button is clicked the setCount function will be called which will increase the value of the count state prop by 1.
Hooks in React 16.8
React 16.8 introduces the following basic hooks
Thursday, May 7, 2020
Lazy loading React components
In React 16.6 lazy loading is enabled by using React.lazy function and the Suspense component. React.lazy is used to lazy load react components from the same or different bundle file and the Suspense component is used to display a fallback UI till the dependent component / bundle is loaded. Lazy loading and code-splitting works together to enable optimization of initial load time for large React Applications.
What is Code-Splitting?
In the React Environment we see how the React components are compiled and bundled before being rendered to the browser. We use Bable to compile the react Application and web-pack to bundle the compiled JavaScript into a bundle.js file.
Wednesday, May 6, 2020
React.lazy with Suspense example
In this post we shall see a simple example which uses React.lazy to lazy load a Child Component and display Loading… text till the child component is loaded. The example has 2 components, the App component is the parent component which laze loads the ChildComponent.
React.memo example
In the below example we will create a React.memo component MyMemoComponent which will take a prop msg from the parent and display it. Remember that the memo component will only re-render when the props passed to it changes.
React.memo & React.lazy in React 16.6
React.memo is similar to PureComponent, it only re-renders if its props are changed. They both offer performance booster to the component by reducing the number of renders. The difference is that PureComponent works with classes and React.memo works with functions.
Tuesday, May 5, 2020
React 16.4 Pointer Events example
In the below example we will capture 2 Pointer events onPointerEnter & onPointerLeave. We will add these events to a DIV, when we move the mouse over the DIV or touch the DIV the onPointerEnter event will trigger in the event handlers we toggle the isHover state property which will in turn change the color of the DIV. By default the DIV gets silver color, when we hover the mouse over the DIV or touch the DIV its color will change to golden color.
What's new in React 16.4
Pointer events are used to handle mouse and touch activity like hover, enter, leave etc. They are similar to jQuery mouse event handlers like mouseenter, mouseleave, mouseover etc. The difference between jQuery mouse events and React pointer events is that the Pointer events support both Mouse events and Touch events.
The following are the pointer events supported in React 16.4