Moving your .NET app to linux and docker

A few months back, I decided to convert an existing .NET core application to run on Linux. As part of this work, I decided to run it inside a Docker container, which meant I could have my application running on Linux without worrying about setting up all of the dependencies on the server like .NET runtime, Apache, etc.

Now I fully realise that Windows containers exist and that I could have tried to get them to work. But the aim for me wasn’t to run on Docker, it was to run on Linux. Docker just came in handy because it meant I didn’t need to install all dependencies onto my Linux server – I could just fire up Docker.

Now, much like communism, Docker is pretty great--in theory. Once the process begins, however, you quickly realise just how many worms are inside the can you’ve just opened.

But unlike communism, in the end, this worked! Here’s the output from my web application showing some server details. Notice any differences?

moving .NET application to linux 0

So with that in mind, here's a list of issues that you should probabl...
Read More ->

Azure devops yaml template bugs

Over the past couple of days I have been investigating using Templates for Azure Pipelines. So far, I am not impressed. After some googling, it seems like there's not that many helpful blogs on the topic, so I'm writing this one to let you know you are not alone!

UI bugs

  • If the template is invalid, the pipeline will fail to run, which is great, however the "Run" button is then disabled - even after you fix the template. This is really confusing. But all you need to do is refresh the page and the button is enabled again. (Handy UI hint - if you're going to disable a button, you need to re-enable it again at some stage)
  • The syntax highlighting for the "resources: repositories" says my syntax is wrong when referencing a template. Even though it works perfectly fine.
  • The Azure Devops UI changes the capitalisation of my step names. Even though I explicity set them in my yaml with "display name". (Handy UI hint - if I have the option to set it, don't override it for me)
  • If I edit the template from within the Azure Devops UI, and click the commit button, the comment message is not highlightable. It seems like it's automatically popul...
    Read More ->

Building a quiz application with youtube's player API

A few months back, I decided to convert an existing Dotnet core application to run on Linux as a proof of concept. As part of this work, I decided to run it inside a Docker container, which meant I could have my application running on Linux without worrying about setting up all of the dependencies on the server like Dotnet runtime, Apache, etc.

Now I fully realise that Windows containers exist and that I could have tried to get them to work. But the aim for me wasn’t to run on Docker, it was to run on Linux. Docker just came in handy because it meant I didn’t need to install all dependencies onto my Linux server – I could just fire up Docker.

Now, much like communism, Docker is pretty great--in theory. Once the process begins, however, you quickly realise just how many worms are inside the can you’ve just opened.

But unlike communism, in the end, this worked! Here’s the output from my web application showing some server details. Notice any differences?

moving dotnet application to linux 0

So with that in mind, here's a list of issues that you should probably know about.

Table Of Contents

  • Building the docker image
    • Image Layers and caching
  • Getting the app to start up

Optimise your app with Visual Studio's Profiler

Do you want to optimise your app so it run faster? Just read this.

But hang on... there's so much information! You could spend weeks optimising your app for nothing!

Stop The Guesswork!

Most people guess at what's slow, based on their previous experience. The problem is it's so easy to be wrong, and you can waste a huge amount of time fixing the wrong stuff. So how do you take the guesswork out and start making an actual, measurable difference?

Let's take this c# code sample:

...
Read More ->

Fixing my Dad's archtop

This is a photo of my Dad's 1981 Noyce archtop guitar:

As you can see, it's a beautiful thing. Sounds amazing and super easy to play. It's all fantastic, until you go to plug the guitar in, and you see this:

What the heck??

When the guitar was originally made, an active EMG pickup was installed. Apparently at the time EMG were a pretty new company! I asked on reddit and apparently I needed to look underneath the pickup to see what it was. So after a bit of screwing this is what I found:

I couldn't find anything about this pickup online, but I think "A" stands for Alnico.

Now because the pickup needed two 9v batteries, instead of adding a large cavity to the body of the guitar and risking reduced resonance, way back in 1981 a crafty solution was comprised.

Instead of the usual setup for an active pickup with one volume knob, which should look like this:

They decided to get rid of the ba...
Read More ->

Using Seq and Asp Dot Net Core

I am unabashed in how awesome I think Seq is. For troubleshooting stuff in production, this thing is a goldmine. Let's say I have some code:


public int Divide(int x, int y)
{
    int z = x / y;
    return z;
}

int result = Divide(10, 5);

With Seq it's extremely easy to add some logging that gives you all the information you need to troubleshoot this function when it's running in production:

I won't go into any more detail about Seq, you can read about it yourself, so here's how I set it up.

Setting up Serilog and Seq for Logging

We are going to use ASP.NET Core's standard logging, Serilog as the implementation, and Seq as a serilog sink. This gives us the most...
Read More ->

Throttling your API in ASP.NET

Can someone DOS attack your API and bring down your webservice? Could I hit your API at 100 requests a second and bring down your server? Or can you throttle your users like this?

Homer throttling Bart

Sorry, I couldn't resist. How about like this?

throttling animated gif

If the answer is no, the good news is that it's quite easy to do in ASP.NET. You can use the fully featured WebApiThrottle, or if you don't need something fancy you can build it yourself.

...
Read More ->

Deployments with Zero Downtime in ASP.NET

Did you know that you can have zero downtime deployments with your ASP.NET application?

You don't even need to be using AWS or Azure, or have a fancy load balancer or anything else clever and expensive! So how does this thing work?




The basic idea is that you have two instances of your app running in production. At any point in time your users are using only one of these instances, and when you do a deploy you update the instance that isn't being used. Then you switch the users over to the new instance. See that blue line? That's a reverse proxy.

Martin Fowler (genius) calls this Blue-green deployments.

So how do I do this?

Well, before we can proceed, perhaps there should be a few pre-requisites listed:

...
Read More ->

Setting up CI to setup your success

Build servers

Does your build save you time and effort? Or does everyone emit a collective groan whenever you hear the dreaded "Someone broke the build" ? A great build setup you will love, a bad setup you will hate. How do you get started and where do you want to end up?

Fundamentals

Which one?

Well, a lot of it depends on your circumstances. If you're a Microsoft shop, you might already have TFS. If you're using Github you've got access to Travis. If you want to set up your own, Jenkins is free and fully featured. If you have a budget you can buy Team City. Or you could check out BuildBot. My recommendation is not to agonise over the decision, just pick one and get stuck in. If you don't have a server and you're not using a hosted source control solution, you could always install Jenkins on your local box in a VM. Remember, you don't need permission to be awesome.

So, what are the basics that your build server should do and in what order should you set them up?

Check ou...
Read More ->

Electron App vs native Winforms App

Like many other software developers I have a bunch of CI jobs that I need to monitor. If any of these jobs are failing I don't want to update my code and break everything. Recently I've been using an app named Catlight. It works great, it's simple, it looks nice:

But the CPU and memory usage?? For just a simple app (all it does is poll a JSON service every minute and displays some basic stats) check out the memory usage:

Yes, that's THREE processes running, and it's using, in total, 94 meg of memory!

Is this a problem? Perhaps not to you. Is it an affront to everything we believe in as software developers? Yes.

It's also worth noting that I'm running a Dell Latitude E6540, which is a great laptop, but it has a notorious fan problem. If you tax the CPU a little bit for longer than a few seconds, the incredibly annoying fan kicks in, whirrs for a second and then stops. Then repeats. It drives you mental.

As a little exercise I wanted to see what would happen if I wrote the equivalent program in a boring Winforms c# app. I came ...
Read More ->

Next Page...