Posts

Showing posts from 2018

Manage Kestrel process with systemd

Manage Kestrel process with systemdKestrel is a lightweight standalone process. In order to host it on Linux, the recommended approach is to install it as a service. Systemd is a group of tools providing functionalities to manage processes on Ubuntu.
Today we will see how we can manage an ASP NET Core application together with its Kestrel process using systemd tools. This post will be composed of three parts:IntroductionManaging process with systemctlDebugging using journalctl1. IntroductionASP NET Core application runs on top of Kestrel which is a lightweight standalone webserver.
To be able to start to interact with our Ubuntu server we need to first establish an ssh connection. If you aren’t familiar with ssh, you can refer to my previous blog post where I provide explanations on how to setup ssh.Once we are on the server, we can get our libraries on the server and run:/usr/share/dotnet/dotnet myapp.dll This will run the app from the current session. When we exit the session, the a…

Useful bash and friends commands

Useful bash and friends commandsSince I have installed Ubuntu as a subsystem, I see myself using more and more bash. The reason being that all the VMs I spin up are Ubuntu VMs. My interactions with my servers are very basic but even for those, there are many beautiful commands which ease my interactions. Today I would like to go through the commands and tips which I use on a daily basis:sshscpaliaseslessgrep1. ssh1.1 Remote actionsThe ssh command allows us to remotly access a terminal or to execute commands remotly.For example when we create a new EC2 instance on AWS we can download the private key.
This key can be used to ssh into the vm.ssh -i key.pem user:hostname -i is used to indicate the identity file to use. You might need to change the permissions on the file before it can be used with chmod 700 key.pem.It is also possible, to make life easier, to setup ssh to autodetect the private key file to use based on the host we are trying to access.We can achieve that by placing the ke…

ASP NET Core Client-side libraries management with VS 2017 Library Manager

Image
ASP NET Core Client-side libraries management with VS 2017 Library ManagerFew weeks ago I discussed how we could create a healthchek library which would return json status of our application. Using the json, I wanted to make a quick page to display healthchecks in a nice visual. I wanted to quickly add Bootstrap and momentJS. For frontend libraries, I was used to use Bower as it nicely put every frontend package in /bower_components which can be served as static data. But since Bower was announcing that it was no longer supported and requested to use Yarn or NPM, I started to look around for an easier solution than those as I don’t really care about source code of the frontend libraries, all I want is the latest compiled versions. After few minutes of research, I found out that the team in Microsoft felt the same way as I did and already worked on a tool called Library manager (libman) and is available in VS Preview for the moment. Libman gives the benefit to allow developers to downl…

Async pipe versus Subscribe in Angular

Async pipe versus Subscribe in AngularOver the past year, working in companies using Angular, many times have I been in situations where I was asked to explain the differences between async pipe and .subscribe in Angular.More precisely explain my standpoint which is to always use async pipe when possible and only use .subscribe when side effect is an absolute necessity.The challenge in explaining this comes to how to convince without giving an hour boring lesson of why side effects in logic are hard to maintain and how prematured .subscribe forces developers to make unecessary side effects.So today I would like to talk about that and provide explanations which I hope will help to understand which to use. This post will be composed of three parts:Observable and RxjsSubscribe functionAsync pipeBest practices1. Observable ans RxJSFirst to understand the context, we need to understand what is an observable.1.1 ObservableObservable is an abstraction of asynchronous stream of data.
For exam…

Healthchecks in ASP NET Core

Healthchecks in ASP NET CoreHealthchecks are used to assess the health of an application. There are multiple level of checks which can be implemented, the first level being whether the application is itself running. The second level being whether the application dependencies, services, databases, files, are accessible by the application. Last level being whether the process itself is healthy, consume a reasonable amount of CPU/RAM.
Today we will see how we can implement a simple healthcheck middleware for ASP NET Core in three parts:Define the usageBuild the frameworkSqlite Healthcheck extension1. Define the usageASP NET Core is cooking a healthcheck framework but the nuget package hasn’t been created yet therefore only the codebase is available. The framework in this post is a simpler version inspired by the official healthcheck framework.We will be creating a framework allowing us to register comprehensive healthchecks.public void ConfigureServices(IServiceCollection services) { …

Sementic versioning for dotnet application

Image
Sementic versioning for dotnet applicationVersioning application allows us to know which features are currently available in the environment where we deployed but when our application is composed by multiple webservers, it becomes tedious to maintain the versioning. On top of that with the dotnet core movement, management of versioning has changed. Today I will show a way to automate the versioning using Gitversion and how it can be used for dotnet core and dotnet framework. This post will be composed by 3 parts:Version assembliesSementic versioningGitversion1. Versioning assembliesIn dotnet, assemblies are versioned via the AssemblyInfo.cs file. This file contains the metadata used by the compiler to populate the information about the assembly like the title, the author, the copyrights and the version.
It is handle via attributes. Here is an example of an assembly info file:using System.Reflection; [assembly: AssemblyTitle("HelloWorld")] [assembly: AssemblyProduct("He…

Microsoft Project Orleans ClientBuilder and SiloBuilder

Microsoft Project Orleans ClientBuilder and SiloBuilderPrior 2.0.0 stable, we used to configure client and silo using ClientConfiguration and ClusterConfiguration. I was hard to understand how to configure those as many options were available. Moving forward to 2.0.0 stable, ClientConfiguration and ClusterConfiguration no longer exist! It has now been replaced by a ClientBuilder and a SiloBuilder (notice there is no cluster builder). The shift toward builders makes life easier to us to configure client and silo. Today I want to take the time to explain how the migration between beta 3 and stable can be done in three parts:Configure ClientBuilderConfigure SiloBuilder1. Configure the ClientBuilderA client needs to connect to a cluster. The only configuration needed for the client is therefore:the id of the clusterthe id of the servicewhere to find the clusterDuring beta this used to be configured in ClientConfiguration, it is now done using the ClientBuilder:IClusterClient client = new …

Hashicorp Vault behind IIS

Image
Hashicorp Vault behind IISLast week I talked about Hashicorp Vault and how it could be used to store secrets. Today I will continue on the same line and show how we can host Vault behind IIS and use what we learnt in the previous post to retrieve secrets from ASP.NET Core.Setup VaultRead secrets from Vault from ASP.NET Core1. Setup VaultVault is a webserver which comes with a complete API. In this example, we will show how to setup Vault and proxy calls from IIS to Vault.1.1 Boot VaultTo begin with, we can follow the same steps described in my previous post - Hashicorp Vault and how it could be used to store secrets. As a quick overview, here are the steps to be executed inside Windows Server:download Vaultcreate the config.hcl filerun the command vault.exe server -config=config.hclIn config.hcl, we configured Vault to listen on http://localhost:8200 so the next thing to do is to proxy calls from IIS to Vault process.1.2 Configure IIS to direct calls to Vault processWe assume that we …

Manage secrets with Hashicorp Vault

Manage secrets with Hashicorp VaultDuring development it is common to save local connection string in the code via setting files. But when it comes the time to deploy, hosted environments should not have their secrets persisted as plain text in the code.
Since those can’t be saved in the git repository, they have to be stored in a secure place where they can be managed easily, a vault. Hashicorp Vault is one of this software which allows us to store and retrieve secrets while providing a granular level of control over the secret accesses.
Today we will see the basic configuration of Hashicorp Vault to store and retrieve secrets using the Vault CLI. This post will be composed by four parts:Start VaultSave secretsCreate a role with a policyRetrieve secrets1. Start Vault1.1 Configure VaultHead to https://www.vaultproject.io/downloads.html and download the latest binaries of Vault then place it in a folder and add the folder to PATH.Before starting Vault we need to create a configuration,…

Let’s Encrypt for ASP.NET Core application on IIS

Image
Let’s Encrypt for ASP.NET Core application on IISFew weeks ago we saw how we could generate a SSL cert for free using a browser based ACME implementation. While doing that, we had some manual process for the verification to happen, either by changing the DNS settings or making a key available on an endpoint and at the end we were handling the key to upload it to our server. Today we will see how we can achieve that with an automated verification process and without manual handling of the secrets using IIS and win-acme.Register application on IISSetup SSL with win-acme1. Register application on IISASP.NET Core runs on top of Kestrel. Kestrel was designed to be fast and lightweight therefore does not have all the functionalities that other application servers provide like IIS, Apache or nginx. Therefore for Windows Server, it is recommended to place Kestrel behind IIS.
For example, one of the reason why is that only one application can listen to the HTTP port at a time on a machine. IIS…

Estimating cloud infrastructure cost

Estimating cloud infrastructure costFew weeks ago I was tasked to estimate a cloud architecture with limited requirements.
Today we will see the rules which can be followed in order to come up with a price tag. This post is composed by three parts:Defining the requirementsSolution needsPrice1. Defining RequirementsBefore starting any estimation, it is important to get at least one requirement. In this example we will invent a scenario, really close to what I had irl, whereby we would be setting up a Christmas tree website with the following requirements.The trees are put to sale accross the whole year in advanceWe have about 50k purchases where 80% happens from November to DecemberThe most important aspect to remember is that estimates are estimates. It will never be exact, even if it happens to be exact, we probably got lucky. The goal of the estimates are to evaluate the magnitude of the price of an infrastructure whether the infrastructure would cost $100, $1000, $10K or $1M monthl…