Part 3: What about alternative deployment options?
This is the third of six articles about how an IoT project with certain constraints and prerequisites was implemented. In recent article I described why it was not possible to create the docker container for OSISoft AKSDK lib. This article is about possible options to deploy old-school .net framework libs in different ways.
- Part 1: Analysis & Design
- Part 2: Let’s go with containers
- Part 3: (this one) What about alternative deployment options?
- Part 4: Going on with alternative deployment options
- Part 5: Final architecture & learnings
Containers do not work. How to move code to different Cloud Services?
Here we go. I already spent too much time on the docker alternative. Let’s talk what it means to the actual code when moving from one option to another.
Moving to different deployment options has strong impacts on code. Does it?
Let’s have a look onto the source structure and how the implement took place.
First the root folder. I guess there is nothing too specific here. There are some common rules how code is going to be structured. I stick to it, having a “src” folder in root for all the code, a “build” folder for all build specific configuration files and a 3rdparty folder. Let’s go into the details. I tend to use lowercase folder names wherever sensible and possible. Windows implementations make this sometimes a rule that is hard to follow.
This here shows the structure of src. There is a Common as well as an Infrastructure folder. I guess it is imaginable what is the content of these. Nuget will always have the “packages” folder in there. Below that there is one folder per component: Reader, Scheduler, Writer. So far so good. Let’s have a look onto the Reader’s folder.
You can imagine, I had more than one try. I’ll come to the why and how later in this article. Believe me, that wasn’t my plan in the first run. Every additional environment had been tested due to different unknown obstacles that came up when doing.
- Reader: The first docker implementation
- Reader.Classic/ Cloud: Classic means the old portal implementations. This is Azure Classic Cloud Services, a service that is probably not often used anymore.
- Reader.ServiceFabric: Azure Service Fabric approach
- Reader.WindowsService: I’ll come later to that one.
Back to the original question:
How costly is it to move code between different cloud services?
I wrote some articles about code structuring, dependency injection and onion architecture. The code is implemented with wrappers for framework specific logic. This enables the code to be moved between different cloud services without having it to change too much. What are the wrappers?
- Configuration files: Configuration files in Azure Functions, Azure Classic Cloud Services, Azure Service Fabric, .net Framework or .net core are different. To follow single responsibility and make my live easier, there are kind of adapters chosen that makes it easy to provide configuration information to code from the cloud services without changing the code at all.
- Logging: For logging it is pretty much the same. I could have chosen the integrated logging mechanism of Azure Functions or Azure Service Fabric or one of the others, but I would like to have one approach that is used throughout the whole system. It should not be dependent on the cloud services. Actually I spent some time onto this due to sometimes it is harder than expected. There is going to be another blog article about that specific one.
- Bootstrap: When having an executable in a docker container, bootstrap looks pretty different from letting it run within Azure Classic Cloud Services or Azure Service Fabric. When you are familiar with Autofac Modules or Windows Castle Installers you’ll get the idea. It is pretty simple to move the bootstrap when it is anyway prepared for being flexible.
Starting with (Classic) Cloud Services
I used Azure Classic Cloud Services a lot back 5 year before. When there was no serverless approach as Azure Functions and Azure Service Fabric hasn’t been released, it was the only real option. Azure Classic Cloud Services works pretty different than Azure Functions or docker containers. Actually, deployment one instance means deployment of a dedicated VM. Having multiple instances mean multiple VMs. So from cost perspective pretty hard to justify, but anyway. It has the functionality to install a setup on startup. This can be done via batch files.
As this is windows, I used a .cmd and a Powershell command. This pretty much looks like this:
[pastacode lang=”bash” manual=”ECHO%20install%20afclient%20%3E%3E%20%22%25TEMP%25%5CStartupLog.txt%22%202%3E%261%0Apowershell%20-ExecutionPolicy%20Unrestricted%20.%5Cstartup.ps1%20″ message=”” highlight=”” provider=”manual”/]
This file obviously is the starting point. It just calls the powershell script with elevated permissions.
[pastacode lang=”bash” manual=”%20try%20%7B%0A%20%20Write-Host%20%22Expanding%20archive%22%0A%20%20Expand-Archive%20-Force%20.%5CAFClient.zip%20.%5CAFClient%0A%20%20Write-Host%20%22cd%20afclient%22%0A%20%20cd%20.%5CAFClient%0A%20%20Write-Host%20%22call%20setup.exe%22%0A%20%20Start-Process%20%22setup.exe%22%20%22-f%20silent.ini%22%20-PassThru%20%7C%20Wait-Process%20%0A%7D%0A%0Acatch%20%7B%0A%20%20%20Write-Host%20%22An%20error%20occurred%3A%22%0A%20%20%20Write-Host%20%24_%0A%7D%20%0A” message=”” highlight=”” provider=”manual”/]
Then doing the hard work. Unzipping the file which has 280MB. Then doing the weird stuff that actually is necessary for running the setup silently. It took some time to get it running but then it did it!
Installation works. What about automation?
Okay, I made it running manually. That’s not the full story. Certainly I expect my code to be pushed automatically after finishing a pull request. It’s Azure DevOps that is in use for all the pipelining stuff. Creating the pipeline was not a problem. Actually I first tried the Azure Cloud Service Deployment Task, which is a yaml snippet. I couldn’t it to work with various error messages. This was quite odd, so I tried the visual one. Here it got more obvious:
When trying to access classic cloud services, this includes also classic storage accounts, the named service connection doesn’t work. I used my Google Fu, but unsuccessful. So I opened a Microsoft Support case. This is the answer:
[pastacode lang=”bash” manual=”Service%20Principal%20cannot%20be%20used%20for%20authenticating%20against%20cloud%20service%20classic%20based%20Service%20Management%20API.%0AHowever%2C%20the%20authorization_code_grant_type%20can%20be%20used%20to%20obtain%20user%20token%20for%20ARM-based%20service%20Management%20API.%0A%0AThis%20isn’t%20possible%20due%20to%20the%20Application%20Permissions%3A%200%20setting%20for%20the%20Service%20Management%20API.%0AThe%20client_credentials%20grant%20type%20uses%20credentials%20from%20the%20application%20(client_id%20and%20client_secret)%2C%20and%20since%20the%20application%20does%20not%20have%20permissions%20for%20this%20API%20the%20call%20fails.%0ASince%20the%20Service%20Management%20API%20will%20not%20allow%20application%20permissions%20of%20any%20kind%0ASee%20https%3A%2F%2Fstackoverflow.com%2Fquestions%2F26003820%2Fazure-service-management-api-authentication-using-azure-active-directory-oauth” message=”” highlight=”” provider=”manual”/]
I won’t go into the details here, there is a solution available. Unluckily it couldn’t be adopted due to internal restrictions and permissions. With Docker I couldn’t create a sensible image due to the setup, with Classic Cloud Services I could execute the setup, but I cannot automate pushing my code via Azure DevOps. Frustration level rises.