<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.10.0">Jekyll</generator><link href="https://www.marcmathijssen.nl/feed.xml" rel="self" type="application/atom+xml" /><link href="https://www.marcmathijssen.nl/" rel="alternate" type="text/html" /><updated>2026-10-29T08:19:58+00:00</updated><id>https://www.marcmathijssen.nl/feed.xml</id><title type="html">Marc Mathijssen</title><subtitle>Software Engineering</subtitle><author><name>Marc Mathijssen</name></author><entry><title type="html">Software Engineering met Agentic AI is geweldig… voor seniors</title><link href="https://www.marcmathijssen.nl/2026/10/24/software-engineering-met-agentic-ai-is-geweldig-voor-seniors/" rel="alternate" type="text/html" title="Software Engineering met Agentic AI is geweldig… voor seniors" /><published>2026-10-24T00:00:00+00:00</published><updated>2026-10-24T00:00:00+00:00</updated><id>https://www.marcmathijssen.nl/2026/10/24/software-engineering-met-agentic-ai-is-geweldig-voor-seniors</id><content type="html" xml:base="https://www.marcmathijssen.nl/2026/10/24/software-engineering-met-agentic-ai-is-geweldig-voor-seniors/"><![CDATA[<p>Het voelt een beetje als een ‘guess who’s back’, maar schrijven blijft een manier om denken te structureren en daarom vind ik het ‘ironisch genoeg’ een fijne manier om wat ik geleerd heb de afgelopen dagen over software engineering m.b.v. AI om te zetten in iets wat ik later kan teruglezen.</p>

<p>De voorgaande posts (laatste in 2019, origineel op @Medium) waren ‘technische recepten’ die ik vanwege dezelfde reden schreef. Wel in het Engels, omdat ik toen dacht dat ik een internationaal publiek zou bedienen 😂 .</p>

<p>Inmiddels is er een hoop veranderd. Ik ben docent Software Engineering aan de Avans University of Applied Sciences. Dit in een buitengewoon interessante tijd. Het eerste jaar zag ik studenten nog traditioneel worstelen met code, en daarna veranderde het langzaam in worstelen met code, maar dan dankzij (of ondanks) AI. Het is een beroep dat mij goed ligt. Het contact met de studenten en collega’s i.c.m. een technisch vak gaan goed samen met mijn energie om mensen te willen helpen.</p>

<h2 id="wat-ik-wilde-leren-">Wat ik wilde leren 🧑‍🎓</h2>

<p>De wereld staat niet stil. Afgestudeerde studenten vertelden mij dat ze niet veel meer met de hand schrijven. Hoewel ik dat prima kon accepteren liep ik nog wel rond met een ‘vroeger deden we het zo’-mindset en dat moest veranderen.</p>

<p>Nadat ik een AI-gegenereerde codebase van een student had gereviewed merkte ik dat deze mindset ook vooroordelen met zich meebrengt. Vooroordelen die het belangrijkste doel in het onderwijs: het opleiden tot junior software engineer, in de weg konden staan. Ik moest zelf weer eens mijn handen vies maken. Uiteraard had ik Claude Code al wel eens gebruikt, maar veelal nog op een traditionele wijze: voor het opzoeken van codeconstructies, uitzoeken van problemen en als een soort Google + StackOverflow ineen. De industrie en vele podcasts deden mij echter geloven dat ik daarmee niet alles uit de tooling haalde.</p>

<p>Omdat ik beter leer wanneer ik een echt probleem wil oplossen besloot ik om een oude PHP legacy codebase van het <a href="https://archief.corsozundert.nl">Corso Zundert Archief</a> (sowieso een van mijn favoriete technische speeldomeinen) om te schrijven naar ‘iets moderns’ maar dan ook op een ‘moderne manier’.</p>

<p>De moderne manier werd Claude’s <a href="https://academy.claude.com/courses/ai-native-sdlc-playbook">AI-native SDLC playbook</a></p>

<p>Het doel was niet zozeer het omschrijven van een legacy-applicatie, maar vooral: kan ik deze werkwijze toepassen, vertrouwen hebben in het resultaat en uitleggen hoe het werkt? Hetzelfde als waar mijn studenten mee worstelen.</p>

<h2 id="het-probleem-">Het ‘probleem’ 🤔</h2>

<p>Het <a href="https://archief.corsozundert.nl/">Corso Archief</a> is een relatief eenvoudige applicatie met enkele views waarin informatie &amp; media over alle voorgaande corso’s te vinden is. Het is een schat aan informatie voor de corsoliefhebber en ook erg leuk om in te grasduinen.</p>

<p>Functioneel voldoet het huidige archief prima. De code is legacy PHP en met veel liefde geconstrueerd. De structuur is soms minder optimaal, en dat komt de leesbaarheid en de performance niet altijd ten goede.</p>

<p>Ik was zelf niet belast met al te veel kennis van PHP dus dat vond ik alleen maar een betere reden om deze applicatie aan te pakken.</p>

<h2 id="werkwijze-">Werkwijze 🪏</h2>

<p>Ik maakte een repo, kopieerde de legacy code in een aparte map en vertelde Claude over mijn intenties. Samen kwamen we tot de conclusie dat:</p>

<ul>
  <li>de database &amp; media buiten scope viel 👉 De datastructuur is, ondanks wat kleine imperfecties, niet verkeerd. Als we de huidige database blijven gebruik werd de scope een stuk beperkter en werd het eenvoudiger om de nieuwe versie te testen en te deployen.</li>
  <li>Laravel is het meest geschikte framework voor dit doel was 👉 of zoals ze zelf zeggen “The clean stack for artisans &amp; agents”.</li>
  <li>de originele app blijft als twin ernaast vanuit dezelfde codebase 👉 handig bij dit migratie scenario</li>
  <li>de oplossing volledig containeriseren: lokale MySQL database, legacy app, Laravel app 👉 minder lokale dev dependencies 🥳</li>
</ul>

<p>Met deze opzet (legacy code naast de laravel code) voorzag ik Claude van voldoende context (de code is de beste documentatie right?) en een manier om ‘Parity Tests’ uit te voeren 👉 tonen de nieuwe views hetzelfde als de oude views.</p>

<p>Voor iedere wijziging maakte ik m.b.v. Claude Code op mijn PC:</p>
<ul>
  <li>Een intent (wat is het doel)</li>
  <li>Een spec (wat zijn de specificaties en welke keuzes zitten hierin)</li>
  <li>Een plan (welke stappen gaat Claude uitvoeren)</li>
</ul>

<p>En vervolgens liet ik Claude Code zijn werk doen en het uitprogrammeren.</p>

<h2 id="resultaat-en-agentic-workflow-">Resultaat en agentic workflow 🌺🤖</h2>

<p>Na twee intents en een paar uurtjes was de volledige oplossing herschreven door Claude. Indrukwekkend. Dit had mij minimaal een week gekost.</p>

<p>De output beoordelen bleek lastiger. Ik ben dus geen PHP-expert, en of Laravel op deze wijze juist was ingezet? Ik vermoedde het. Ik zag componenten, services, models. Concepten die mij niet vreemd zijn uit andere frameworks.</p>

<p>Al snel begon ik al allerlei (niet) functionele aspecten te verbeteren met nieuwe intents (laadtijden, media optimalisatie met <code class="language-plaintext highlighter-rouge">WEBP</code> en <code class="language-plaintext highlighter-rouge">srcset</code>, responsive design). De code bekeek ik af en toe, omdat het soms moest van mezelf. Het doorvoeren van verbeteringen is nog steeds even leuk, ook als de code voor je wordt geschreven. De aspecten die ik wilde verbeteren kwamen uit mijn hoofd, maar Claude komt vaak ook met goede suggesties en denkt mee hoe dit te bereiken.</p>

<p><em>Een na- en voor met mijn favoriete corsowagen: <a href="https://archief.corsozundert.nl/wagen.php?id=1798">Feniks, Buurtschapp Tiggelaar, winnaar 2025</a></em></p>
<div class="image-row">
  <figure>
    <img src="/assets/images/software-engineering-met-agentic-ai-is-geweldig-voor-seniors/archief-nieuw.png" alt="De nieuwe versie: de pagina van Feniks (2025) in Laravel en Tailwind CSS" />
    <figcaption>De nieuwe versie (in Laravel en Tailwind CSS)</figcaption>
  </figure>
  <figure>
    <img src="/assets/images/software-engineering-met-agentic-ai-is-geweldig-voor-seniors/archief-oud.webp" alt="De oude versie van dezelfde pagina" />
    <figcaption>De oude versie</figcaption>
  </figure>
</div>

<p>Als laatste stap heb ik de workflow volledig geautomatiseerd in GitHub. Want wat ik op mijn PC in een prompt kan, kan een archief-beheerder (productowner) ook via een GitHub issue, en vaak zelfs beter. Als techneut wil ik wel grip houden op de code, dus implementeerde ik een ‘agentic werkwijze’ die als volgt werkt:</p>

<ul>
  <li>Issue aanmaken. Een productowner of developer maakt een issue aan, in het Nederlands of Engels, en beschrijft wat er moet veranderen en waarom. Zet het label <code class="language-plaintext highlighter-rouge">claude</code> erop.</li>
  <li>Intent beoordelen. Claude schrijft de intent en opent een draft-PR met een Nederlandse samenvatting.</li>
  <li>Spec en output beoordelen. Claude schrijft de spec en het plan, bouwt de wijziging en zet in een reactie op de PR wat er gebouwd is. Met het label <code class="language-plaintext highlighter-rouge">testomgeving</code> wordt deze ook op een aparte testomgeving geplaatst. Deze optie wil ik ook aanbieden voor developers die liever op de lokale PC of met de hand blijven werken, en zo kunnen beide workflows blijven bestaan.</li>
</ul>

<p>Daarnaast heeft Claude guardrails gekregen: welke bestanden mag je wel aanpassen, en welke nooit</p>

<div class="image-row">
  <figure>
    <img src="/assets/images/software-engineering-met-agentic-ai-is-geweldig-voor-seniors/github-issue.png" alt="Een issue met het label claude, opgepakt door Claude op GitHub" />
    <figcaption>Een issue met het label <code>claude</code>, opgepakt door Claude op GitHub</figcaption>
  </figure>
  <figure>
    <img src="/assets/images/software-engineering-met-agentic-ai-is-geweldig-voor-seniors/intents.png" alt="De map .intents in de repository, met een map per wijziging" />
    <figcaption>De map <code>.intents</code> in de repository, met een map per wijziging</figcaption>
  </figure>
</div>

<h2 id="leerpunt-1-reduceren-output-">Leerpunt 1: Reduceren output 🧑‍🌾</h2>

<p>“Programmeren is als tuinieren” hoorde ik ooit in een podcast: op bepaalde plekken mag de code groeien, op bepaalde plekken moet je het een beetje terugsnoeien. Het gaat altijd gepaard met aandacht. Wat ik merk, ook bij studenten, is dat Claude (of Codex for that matter) een handje heeft van overbodig compleet willen zijn en zichzelf te willen beschermen tegen fouten. Dit gaat gepaard met een enorme hoeveel output in de vorm van (test)code, commentaar en documentatie</p>

<p>Hierdoor wordt het lastiger om hoofd- en bijzaak van elkaar te onderscheiden, waardoor code-bases als deze al snel intimiderend groot worden. De complexiteit zit dan niet in de code (het bleef bij enkele views en modellen) maar juist in de hoeveelheid tests &amp; text die ermee gepaard gaan. Heb je echt bij iedere functie 5 regels commentaar nodig met uitleg en verwijzing naar de intent? Is het nodig dat kleine bugfixes in de output blijvend getest worden?</p>

<p>Ik heb er bewust voor gekozen om een aantal tests, overbodige laravel configuratie opties, commentaar en de README drastisch terug te snoeien. Beperk het tot de essentie: wat moet de volgende developer (of jijzelf over een paar jaar) weten voordat deze aan de slag kan met deze codebase en denk goed na over wat er echt niet kapot mag gaan om zo de hoeveel tijd tests beperkt.</p>

<h2 id="leerpunt-2-code-begrijpen-door-enkel-te-lezen-is-niet-leuk-">Leerpunt 2: Code begrijpen door enkel te lezen is niet leuk 🥲</h2>

<p>Ik zag een berg tests, en relatief eenvoudige PHP code. De structuur van Laravel was mij onbekend, dus ja, waar zit dan die verbinding met de database? Een vraag die ik graag stel aan eerstejaarsstudenten. Als je stuurt op de output (een werkende webapplicatie) is het minder ‘leuk’ om naar de code te kijken. Daarom heb ik actief gestuurd op documentatie, zodat ik de oplossing en de werkwijze zelf begrijp.</p>

<h2 id="leerpunt-3-de-ethische-kant-bestaat-echt-">Leerpunt 3: De ethische kant bestaat echt 🤕</h2>

<p>Gaandeweg besefte ik iets anders …</p>

<p>Voor een junior/medior kan het heel leuk en zingevend zijn om een groepje mensen te helpen met code die hun probleem oplost. Dit is ook altijd mijn grote drijfveer geweest. Het ging mij al niet echt om de code, al ben ik later gaan beseffen dat goede code het leven van alle stakeholders fijner maakt. Het oplossen van problemen voor echte mensen leert je veel meer dan alleen coderen.</p>

<p>Met deze “moderne werkwijze” vernietig ik een proces waar een andere junior developer veilig, leerzaam en zingevend werk had kunnen doen in een context waar mensen überhaupt blij zijn dat je een steentje bijdraagt (Corso Zundert draait volledig op vrijwilligers), en ik voelde mij dus ook schuldig over mijn aanpak.</p>

<h2 id="conclusie">Conclusie</h2>

<p>Ik begon met drie vragen: kan ik deze werkwijze toepassen, heb ik vertrouwen in het resultaat, en kan ik uitleggen hoe het werkt?</p>

<p>Toepassen: ja. Dat ging sneller en beter dan ik had verwacht. Na een paar uur stond er een werkende applicatie. Na drie dagen konden beheerders via een GitHub issue zelf wijzigingen laten bouwen.</p>

<p>Vertrouwen: ja, maar niet omdat ik een mentaal model van de applicatie in mijn hoofd had door dat ik de code door- en door kende. 
Vertrouwen omdat ik het proces kon volgen, de tests begreep, de scope veilig had afgebakend (guardrails, parity tests). Dat zijn geen PHP-vaardigheden. Ik vertrouw een applicatie pas als ik hem veilig in productie zou kunnen beheren en dat was hier het</p>

<p>Uitleggen: deels. De werkwijze kan ik uitleggen. Of ik de code kan uitleggen, een stuk minder. Waar die verbinding met de database precies zit, moest ik nog steeds opzoeken.</p>

<p>Het verschil met hoe ik voorheen een applicatie zou realiseren is interessant. “We can know more than we can tell”, Een groot deel van wat een ervaren developer weet, is ‘tacit knowledge’: kennis die je niet kunt opschrijven, alleen kunt opbouwen door het te doen.</p>

<p>In Laravel ben ik een beginner, of zelfs minder dan dat nog, maar in software engineering niet. Claude nam het beginnerswerk over, terwijl ik mijn ervaring en kennis over webdevelopment, cloudhosting op Azure en GitHub workflows inbracht… daarom werkte het voor mij.</p>

<p>Wanneer je die kennis niet hebt, bouw je het pas op in de stadia die AI je nu zo makkelijk laat overslaan: het worstelen, het fout doen, het zelf configureren van de verbinding met de database. Daar zit ook mijn ongemak uit leerpunt 3. Het gaat niet alleen om dit ene project. Het gaat om de plekken waar deze kennis werd opgebouwd, waar werd geworsteld. Een opleiding is slechts één van die plekken, en vaak het startpunt.</p>

<h2 id="verder-lezen-">Verder lezen 📚</h2>

<ul>
  <li>Bosman &amp; Ongena (2026), <a href="https://www.themahogeronderwijs.org/artikel/110-4310_De-paradox-van-het-ICT-onderwijs">De paradox van het ICT-onderwijs</a>. Th&amp;ma, 7 juli 2026.</li>
  <li>Heck (2026), <a href="https://fontysblogt.nl/author/petraheck/">Competences for the AI-Augmented Software Engineer</a>. Fontys blog, 3 juni 2026.</li>
  <li>Hermans (2026), <a href="https://tweakers.net/plan/4864/felienne-hermans-op-de-dev-summit-over-ai-en-code-leer-het-omdat-het-leuk-is.html?referrer=https%3A%2F%2Fwww.felienne.nl%2Fvierkante-ogen%2F">Leer coderen omdat het leuk is!</a>. Tweakers Dev Summit, 21 oktober 2026.</li>
</ul>]]></content><author><name>Marc Mathijssen</name></author><category term="legacy" /><category term="php" /><category term="ai" /><category term="claude" /><category term="modernisering" /><summary type="html"><![CDATA[Wat ik leerde van het moderniseren van het Corso Zundert archief met Claude en het AI-native SDLC playbook.]]></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://www.marcmathijssen.nl/assets/images/software-engineering-met-agentic-ai-is-geweldig-voor-seniors/social-1945-v2.webp" /><media:content medium="image" url="https://www.marcmathijssen.nl/assets/images/software-engineering-met-agentic-ai-is-geweldig-voor-seniors/social-1945-v2.webp" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">Recipe: Angular app on Azure Storage with custom domain and SSL using Azure CDN.</title><link href="https://www.marcmathijssen.nl/2019/11/16/recipe-angular-app-on-azure-storage-with-custom-domain-and-ssl-using-azure-cdn/" rel="alternate" type="text/html" title="Recipe: Angular app on Azure Storage with custom domain and SSL using Azure CDN." /><published>2019-11-16T00:00:00+00:00</published><updated>2019-11-16T00:00:00+00:00</updated><id>https://www.marcmathijssen.nl/2019/11/16/recipe-angular-app-on-azure-storage-with-custom-domain-and-ssl-using-azure-cdn</id><content type="html" xml:base="https://www.marcmathijssen.nl/2019/11/16/recipe-angular-app-on-azure-storage-with-custom-domain-and-ssl-using-azure-cdn/"><![CDATA[<p><img src="/assets/images/recipe-angular-app-on-azure-storage-with-custom-domain-and-ssl-using-azure-cdn/1-6jcsbd8tzz6d3d7pjtllta.png" alt="" /></p>

<p>At <a href="https://unite.nl">Unite.nl</a> we prefer Angular as the frontend stack for the applications we develop and we use Azure as our cloud infrastructure. Over the last few months we’ve learned what it takes to properly host an Angular app in Azure.</p>

<p>In a few steps i’ll explain what we’ve done to run an Angular app on Azure with:<br />
* A custom domain<br />
* Free SSL<br />
* Clean URLs (using Angulars PathLocationStrategy)<br />
* Cache busting<br />
* Compression</p>

<h2 id="1-setup-azurestorage">1. Setup Azure Storage</h2>

<p>The output of your Angular build is a bunch of static HTML / Javascript / CSS files. You can put these on an Azure App Service Web App, but Azure also offers a cheaper and faster option: Azure Storage.</p>

<p>Azure Storage, the developers equivalent of Swish army knife, offers the option to host static websites. Create a storage account and enable static website hosting.</p>

<p><img src="/assets/images/recipe-angular-app-on-azure-storage-with-custom-domain-and-ssl-using-azure-cdn/1-ivzfjdpfnoxh2kllkzyuha.png" alt="" /></p>

<p>Once you’ve uploaded the build output (the files in your dist folder) to the $web container, you can go to the ‘primary endpoint’ in your browser and your website should function properly. By default the LocationStrategy is set to PathLocationStrategy (the clean URLs). These clean urls (e.g. /customers/1234) don’t map to a static file but because we’ve instructed Azure Storage to use index.html as the Error document path, the routes work.</p>

<p>There is a caveat however…</p>

<p>When you check the developer console in your browser, <strong>you’ll see Azure Storage serving 404’s for the clean URLs.</strong> It’s not nice, but it works. In the next steps i’ll show you how to get rid of the 404’s.</p>

<h2 id="2-create-an-azure-cdnendpoint">2. Create an Azure CDN endpoint</h2>

<p>Since Azure Storage does not offer running a static website under a custom domain using SSL, we use Azure CDN to do this for us. Our CDN of choice is Azure CDN Premium Verizon because it’s the only CDN which offers rewriting rules which will help us preventing the 404’s on URLs that are created by Angulars PathLocationStrategy.</p>

<p>The downside of this CDN offer is it has really, really slow purge times. Purging is refreshing your CDN cache. But i’ll show you how to get around this later.</p>

<p><strong>1. Create an Azure CDN Profile with the Premium Verizon offer</strong></p>

<p><strong>2. Setup an endpoint which points to your Azure Storage primary endpoint using the General Web Delivery profile</strong></p>

<p>After creating this you’ll be able to reach your Angular app on the azureedge.net CDN domain that pulls and caches the content from your Azure Storage static website.</p>

<p><strong>3. Add a custom domain by pointing a CNAME record to the azureedge.net domain</strong><br />
⚠ Beware of adding CNAME records to your root domain, you’ll brake your MX records and e-mail will stop working ⚠</p>

<p><strong>4. Enable SSL at your CDN endpoint.</strong></p>

<p>This will take approximately 6 hours to complete. You can choose the ‘CDN Managed’ option and Azure will generate the certificate for you by validating your domain (using e-mail or the CNAME record) or you can import your own keyvault certificate.</p>

<p>We use the ‘CDN Managed’ option since updating your keyvault certificate doesn’t automatically renew the certificate in your CDN. The ‘CDN Managed’ option saves us from this hassle in the future.</p>

<h2 id="3-optimize-azure-cdn-premium-verizon-for-angularapps">3. Optimize Azure CDN Premium Verizon for Angular apps</h2>

<p>Configuring the CDN for Angular apps turned out to be the hard part. Changes in the configuration take over 4 hours to propagate to all edges of the CDN which makes debugging very annoying. Hope to save you some time here 😉</p>

<p>We’ve configured the CDN to:<br />
* Rewrite the clean PathLocationStrategy URLs to Angulars index.html<br />
* Force redirect to HTTPS using a redirect and HSTS headers<br />
* Enable compression on static resources</p>

<p><strong>1.Open the CDN portal</strong><br />
Press the ‘manage’ button in your CDN profile</p>

<p><img src="/assets/images/recipe-angular-app-on-azure-storage-with-custom-domain-and-ssl-using-azure-cdn/1-omfxn1afpp5wqgwzie544w.png" alt="" /></p>

<p><strong>2. Rewrite PathLocationStrategy (clean) URLs to Angulars index.html</strong><br />
Open up the HTTP Large Rules Engine</p>

<p><img src="/assets/images/recipe-angular-app-on-azure-storage-with-custom-domain-and-ssl-using-azure-cdn/1-51ywaegjzo-r5ukf3iogfa.png" alt="" /></p>

<p>Setup a URL rewrite rule (IF Always)</p>

<div class="language-text highlighter-rouge"><div class="highlight"><pre class="highlight"><code>((?:[^\?]*/)?)($|\?.*) =&gt; index.html$2
((?:[^\?]*/)?[^\?/.]+)($|\?.*) =&gt; index.html$2
</code></pre></div></div>

<p>Our rewrite rules look like this:</p>

<p><img src="/assets/images/recipe-angular-app-on-azure-storage-with-custom-domain-and-ssl-using-azure-cdn/1-yfquylt8sm65pjvcbtypva.png" alt="" /></p>

<p>After approximately 4 hours you’ll have clean Angular URLs with a proper Status 200 response.</p>

<p><strong>3. Force HTTPS using redirect and HSTS</strong><br />
 Create a new rule to redirect HTTP traffic to HTTPS. If the redirect scheme is HTTP we redirect to:</p>

<div class="language-text highlighter-rouge"><div class="highlight"><pre class="highlight"><code>https://%{host}/$1
</code></pre></div></div>

<p>Our rule looks like this</p>

<p><img src="/assets/images/recipe-angular-app-on-azure-storage-with-custom-domain-and-ssl-using-azure-cdn/1-fr5n0ay-qj0me1ujuknebg.png" alt="" /></p>

<p>Add a new rule adding a <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Strict-Transport-Security">HSTS header</a> to HTTPS traffic to make sure browsers use HTTPS by default when the user browses to your app.</p>

<p><strong>⚠ Only add HSTS when you’re pretty sure you’ll only be serving over HTTPS in the future ⚠</strong></p>

<p>Setup a rule adding the following header to HTTPS traffic:</p>

<div class="language-text highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Strict-Transport-Security: max-age=31536000
</code></pre></div></div>

<p>Our rule looks like this</p>

<p><img src="/assets/images/recipe-angular-app-on-azure-storage-with-custom-domain-and-ssl-using-azure-cdn/1-hwvoiq9veboa50fq1ghicg.png" alt="" /></p>

<p><strong>4. Enable compression</strong><br />
By default compression (like GZIP) is turned off on the CDN. Since we’re serving mobile friendly Angular apps we like to save our users bandwith by compressing our files before we send them to the browser.</p>

<p>Go to HTTP Large =&gt; Cache Settings =&gt; Compression</p>

<p>and add the following file types</p>

<div class="language-text highlighter-rouge"><div class="highlight"><pre class="highlight"><code>text/plain,text/html,text/css,application/x-javascript,text/javascript,application/javascript,application/json
</code></pre></div></div>

<h2 id="4-cache-busting-thecdn"><strong>4. Cache busting the CDN</strong></h2>

<p>The CDN caches the Azure Storage files and the docs state that by purging the cache you can force the CDN to update the cached files with the new ones from the origin (in this case Azure Storage).</p>

<p>Unfortunately we’ve noticed the ‘purge all’ operation takes a very very long time to actually do this. <strong>In some cases the CDN still served old content hours after purging.</strong></p>

<p>We’ve worked around this by placing our Angular CSS and Javascript resources in a separate folder containing the version number of our client software. After each deployment we only purge the index.html which happens usually instantaneously after purging.</p>

<p><strong>1.Customizing the Angular build</strong></p>

<p>We build with the version (in this example 20191115.3) as deploy-url parameter to tell Angular to load the resources from the versioned folder</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>npm run build <span class="nt">--deploy-url</span><span class="o">=</span><span class="s2">"20191115.3/"</span>
</code></pre></div></div>

<p>Our post-build script moves the CSS / Javascript files to this versioned folder.</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>npm run post-build <span class="s2">"20191115.3"</span>
</code></pre></div></div>

<p>Our NodeJs post-build script looks like this</p>

<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kd">const</span> <span class="nx">path</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="dl">'</span><span class="s1">path</span><span class="dl">'</span><span class="p">);</span>
<span class="kd">const</span> <span class="nx">fs</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="dl">'</span><span class="s1">fs</span><span class="dl">'</span><span class="p">);</span>

<span class="kd">const</span> <span class="nx">APP_VERSION</span> <span class="o">=</span> <span class="nx">process</span><span class="p">.</span><span class="nx">argv</span><span class="p">[</span><span class="mi">2</span><span class="p">];</span>
<span class="kd">const</span> <span class="nx">DIST_PATH</span> <span class="o">=</span> <span class="nx">path</span><span class="p">.</span><span class="nx">join</span><span class="p">(</span><span class="nx">__dirname</span><span class="p">,</span> <span class="dl">'</span><span class="s1">../dist</span><span class="dl">'</span><span class="p">);</span>
<span class="kd">const</span> <span class="nx">VERSIONED_PATH</span> <span class="o">=</span> <span class="nx">path</span><span class="p">.</span><span class="nx">join</span><span class="p">(</span><span class="nx">DIST_PATH</span><span class="p">,</span> <span class="nx">APP_VERSION</span><span class="p">);</span>

<span class="kd">const</span> <span class="nx">distFiles</span> <span class="o">=</span> <span class="nx">fs</span><span class="p">.</span><span class="nx">readdirSync</span><span class="p">(</span><span class="nx">DIST_PATH</span><span class="p">);</span>

<span class="c1">// Create the version folder</span>
<span class="nx">fs</span><span class="p">.</span><span class="nx">mkdirSync</span><span class="p">(</span><span class="nx">VERSIONED_PATH</span><span class="p">);</span>

<span class="c1">// Move all files in the dist folder</span>
<span class="c1">// to the version folder except for index.html</span>

<span class="nx">distFiles</span><span class="p">.</span><span class="nx">forEach</span><span class="p">(</span><span class="nx">file</span> <span class="o">=&gt;</span> <span class="p">{</span>

<span class="kd">const</span> <span class="nx">originalPath</span> <span class="o">=</span> <span class="nx">path</span><span class="p">.</span><span class="nx">join</span><span class="p">(</span><span class="nx">DIST_PATH</span><span class="p">,</span> <span class="nx">file</span><span class="p">);</span>
<span class="kd">const</span> <span class="nx">newAbsolutePath</span> <span class="o">=</span> <span class="nx">path</span><span class="p">.</span><span class="nx">join</span><span class="p">(</span><span class="nx">VERSIONED_PATH</span><span class="p">,</span> <span class="nx">file</span><span class="p">);</span>

<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">file</span><span class="p">.</span><span class="nx">endsWith</span><span class="p">(</span><span class="dl">'</span><span class="s1">.html</span><span class="dl">'</span><span class="p">)</span> <span class="o">&amp;&amp;</span> <span class="nx">fs</span><span class="p">.</span><span class="nx">lstatSync</span><span class="p">(</span><span class="nx">originalPath</span><span class="p">).</span><span class="nx">isFile</span><span class="p">())</span> <span class="p">{</span>

<span class="nx">fs</span><span class="p">.</span><span class="nx">renameSync</span><span class="p">(</span><span class="nx">originalPath</span><span class="p">,</span> <span class="nx">newAbsolutePath</span><span class="p">);</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">`Moved </span><span class="p">${</span><span class="nx">originalPath</span><span class="p">}</span><span class="s2"> to </span><span class="p">${</span><span class="nx">newAbsolutePath</span><span class="p">}</span><span class="s2">`</span><span class="p">);</span>

<span class="p">}</span>
<span class="p">});</span>
</code></pre></div></div>

<p>This is what the output looks like after the build and post-build</p>

<p><img src="/assets/images/recipe-angular-app-on-azure-storage-with-custom-domain-and-ssl-using-azure-cdn/1-9-kqhctu9foj6acrxpl2vq.png" alt="" /></p>

<p>This is what the index.html looks like</p>

<p><img src="/assets/images/recipe-angular-app-on-azure-storage-with-custom-domain-and-ssl-using-azure-cdn/1-3w1rrq6ofeacadgcua9jbw.png" alt="" /></p>

<p><strong>2. Purging the index.html</strong></p>

<p>After you’ve published the output to Azure Storage, you can purge the index.html from the CDN which takes approximately 1 minute. <br />
Here’s how we do it using an Azure CLI task in an Azure Devops Release pipeline:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>az cdn endpoint purge <span class="nt">--resource-group</span> <span class="s2">"***"</span> <span class="nt">-n</span> <span class="s2">"***"</span> <span class="nt">--profile-name</span> <span class="s2">"***"</span>  <span class="nt">--content-paths</span> <span class="s2">"/index.html"</span> <span class="s2">"/*"</span>
</code></pre></div></div>

<p>Note we also append “/*” which is the equivalent of ‘purge all’. We do this for our static assets, for which it is acceptable to have a longer cache duration.</p>

<p>Since the index.html is quickly purged and all Angular resources are loaded from a folder which doesn’t exist on the CDN yet, users will get the latest version of the app.</p>

<p><strong>It took some configuration and trial and error before we finally got it right, but I hope I can save you the trouble by sharing it here 😊</strong></p>]]></content><author><name>Marc Mathijssen</name></author><category term="angular" /><category term="azure" /><category term="cdn" /><summary type="html"><![CDATA[At Unite.nl we prefer Angular as the frontend stack for the applications we develop and we use Azure as our cloud infrastructure. Over the…]]></summary></entry><entry><title type="html">Deploy a .NET Core WebJob within Azure Devops</title><link href="https://www.marcmathijssen.nl/2019/04/10/deploy-a-net-core-webjob-within-azure-devops/" rel="alternate" type="text/html" title="Deploy a .NET Core WebJob within Azure Devops" /><published>2019-04-10T00:00:00+00:00</published><updated>2019-04-10T00:00:00+00:00</updated><id>https://www.marcmathijssen.nl/2019/04/10/deploy-a-net-core-webjob-within-azure-devops</id><content type="html" xml:base="https://www.marcmathijssen.nl/2019/04/10/deploy-a-net-core-webjob-within-azure-devops/"><![CDATA[<p>Recently I created an WebJob to do some background processing for our company’s web app. It took me some time find out how to deploy the WebJob using Azure Devops (most documentation is about full framework WebJobs), so I’d like to share my deployment script with you.</p>

<hr />

<ol>
  <li>Add an Azure Powershell task to your build or release pipeline</li>
</ol>

<p><img src="/assets/images/deploy-a-net-core-webjob-within-azure-devops/1-4rwyo3kpfzoohgjlyzmuxq.png" alt="" /></p>

<p>2. Change the variables in the top of the script below to match your resource group / web app / webjob names.</p>

<div class="language-powershell highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># Deploy a .NET Core WebJob using Azure Powershell within a Azure Devops Pipeline</span><span class="w">

</span><span class="nv">$resourceGroupName</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">""</span><span class="w"> </span><span class="c">#the name of the resource group</span><span class="w">
</span><span class="nv">$webappName</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">""</span><span class="w"> </span><span class="c">#the name of the webapp you would like to deploy to)</span><span class="w">
</span><span class="nv">$webjobName</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">""</span><span class="w"> </span><span class="c">#the name of the webjob</span><span class="w">
</span><span class="nv">$path</span><span class="w"> </span><span class="o">=</span><span class="w">  </span><span class="s2">""</span><span class="w"> </span><span class="c">#path to the .zip containing the webjob</span><span class="w">
</span><span class="nv">$scheduleName</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"continuous"</span><span class="w"> </span><span class="c">#Name of the webjob, either 'continuous' or 'triggered'</span><span class="w">

</span><span class="kr">if</span><span class="w"> </span><span class="p">(</span><span class="o">-not</span><span class="w"> </span><span class="p">(</span><span class="n">Test-Path</span><span class="w"> </span><span class="nv">$path</span><span class="p">))</span><span class="w"> 
</span><span class="p">{</span><span class="w">
    </span><span class="kr">throw</span><span class="w"> </span><span class="p">[</span><span class="n">System.IO.FileNotFoundException</span><span class="p">]</span><span class="w"> </span><span class="s2">"</span><span class="si">$(</span><span class="nv">$path</span><span class="si">)</span><span class="s2"> not found."</span><span class="w">
</span><span class="p">}</span><span class="w">

</span><span class="c"># Retrieve WebDeploy credentials for uploading a file using Kudu</span><span class="w">
</span><span class="nv">$publishingProfilesXml</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">[</span><span class="n">xml</span><span class="p">](</span><span class="n">Get-AzureRmWebAppPublishingProfile</span><span class="w"> </span><span class="nt">-OutputFile</span><span class="w"> </span><span class="nx">test.xml</span><span class="w"> </span><span class="nt">-Format</span><span class="w"> </span><span class="nx">WebDeploy</span><span class="w"> </span><span class="nt">-Name</span><span class="w"> </span><span class="nv">$webappName</span><span class="w"> </span><span class="nt">-ResourceGroupName</span><span class="w"> </span><span class="nv">$resourceGroupName</span><span class="w"> </span><span class="p">)</span><span class="w">
</span><span class="nv">$publishingProfileWebDeploy</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nv">$publishingProfilesXml</span><span class="o">.</span><span class="nf">FirstChild</span><span class="o">.</span><span class="n">ChildNodes</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="w">   
</span><span class="nv">$username</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nv">$publishingProfileWebDeploy</span><span class="o">.</span><span class="nf">userName</span><span class="w">
</span><span class="nv">$password</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nv">$publishingProfileWebDeploy</span><span class="o">.</span><span class="nf">userPWD</span><span class="w">
</span><span class="nv">$base64AuthInfo</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">[</span><span class="n">Convert</span><span class="p">]::</span><span class="n">ToBase64String</span><span class="p">([</span><span class="n">Text.Encoding</span><span class="p">]::</span><span class="n">ASCII.GetBytes</span><span class="p">((</span><span class="s2">"{0}:{1}"</span><span class="w"> </span><span class="nt">-f</span><span class="w"> </span><span class="nv">$username</span><span class="p">,</span><span class="nv">$password</span><span class="p">)))</span><span class="w">
</span><span class="nv">$apiBaseUrl</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"https://</span><span class="si">$(</span><span class="nv">$webappName</span><span class="si">)</span><span class="s2">.scm.azurewebsites.net/api"</span><span class="w">

</span><span class="c"># Upload the deployment zip to Kudu</span><span class="w">
</span><span class="nv">$files</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Get-ChildItem</span><span class="w"> </span><span class="nt">-Path</span><span class="w"> </span><span class="nv">$path</span><span class="w"> </span><span class="nt">-Recurse</span><span class="w">
</span><span class="n">Test-Path</span><span class="w"> </span><span class="nt">-Path</span><span class="w"> </span><span class="nv">$files</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="w">   
</span><span class="nv">$authHeader</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">" Basic "</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="nv">$base64AuthInfo</span><span class="w">
</span><span class="nv">$deployUrl</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"</span><span class="si">$(</span><span class="nv">$apiBaseUrl</span><span class="si">)</span><span class="s2">/</span><span class="si">$(</span><span class="nv">$scheduleName</span><span class="si">)</span><span class="s2">jobs/</span><span class="si">$(</span><span class="nv">$webjobName</span><span class="si">)</span><span class="s2">"</span><span class="w">
  
</span><span class="n">Write-Host</span><span class="w"> </span><span class="s2">"Uploading "</span><span class="w"> </span><span class="nv">$path</span><span class="w">  </span><span class="s2">" to "</span><span class="w"> </span><span class="nv">$deployUrl</span><span class="w">
</span><span class="nv">$ZipHeaders</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">@{</span><span class="w">
</span><span class="nx">Authorization</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nv">$authHeader</span><span class="w">
	</span><span class="s2">"Content-Disposition"</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"attachment; filename=</span><span class="si">$(</span><span class="nv">$files</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="nf">Name</span><span class="si">)</span><span class="s2">"</span><span class="w">
</span><span class="p">}</span><span class="w">

</span><span class="nv">$response</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Invoke-WebRequest</span><span class="w"> </span><span class="nt">-Uri</span><span class="w">  </span><span class="nv">$deployUrl</span><span class="w"> </span><span class="nt">-Headers</span><span class="w"> </span><span class="nv">$ZipHeaders</span><span class="w"> </span><span class="nt">-InFile</span><span class="w"> </span><span class="nv">$files</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="w"> </span><span class="nt">-ContentType</span><span class="w"> </span><span class="s2">"application/zip"</span><span class="w"> </span><span class="nt">-Method</span><span class="w"> </span><span class="nx">Put</span><span class="w">
</span><span class="n">Write-Host</span><span class="w"> </span><span class="nv">$response</span><span class="w">
</span></code></pre></div></div>

<p><a href="https://gist.github.com/dev-marc/2d5504f20001f39d7cc26997a28baa33">View on GitHub Gist</a></p>]]></content><author><name>Marc Mathijssen</name></author><category term="dotnet" /><category term="azure-devops" /><category term="azure" /><summary type="html"><![CDATA[Recently I created an WebJob to do some background processing for our company’s web app. It took me some time find out how to deploy the…]]></summary></entry><entry><title type="html">Using the power of Apache FOP in a .NET world using Azure Functions</title><link href="https://www.marcmathijssen.nl/2019/02/10/using-the-power-of-apache-fop-in-a-net-world-using-azure-functions/" rel="alternate" type="text/html" title="Using the power of Apache FOP in a .NET world using Azure Functions" /><published>2019-02-10T00:00:00+00:00</published><updated>2019-02-10T00:00:00+00:00</updated><id>https://www.marcmathijssen.nl/2019/02/10/using-the-power-of-apache-fop-in-a-net-world-using-azure-functions</id><content type="html" xml:base="https://www.marcmathijssen.nl/2019/02/10/using-the-power-of-apache-fop-in-a-net-world-using-azure-functions/"><![CDATA[<p>Every developer knows the struggle of generating PDF files. Even though in the .NET world there are some pretty good packages to do this, it basically comes down to coding the PDF line by line. Since this is a time consuming and monotonous task, producing a lot of low value code we decided to do this differently</p>

<p>A tool like Altova Stylevision allow you to visually design a document and <a href="https://xmlgraphics.apache.org/fop/">The Apache FOP Project</a> takes the XML containing the data and an XSLT file containing the ‘design’ . That sounds a lot friendlier, but how to integrate this JAVA component into a .NET world? We used Azure Functions.</p>

<p><img src="/assets/images/using-the-power-of-apache-fop-in-a-net-world-using-azure-functions/1-py5ycxuluand2qnycnxdug.png" alt="" /></p>

<h2 id="the-problem">The problem</h2>

<p>Apache FOP is a JAVA component and that doesn’t really play nice with .NET code. There is no nuget package to use Apache FOP inside your .NET solution.</p>

<p>In our first attempt we actually used a VM and ran the Apache FOP executable in isolation with a command like</p>

<div class="language-csharp highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">using</span> <span class="p">(</span><span class="kt">var</span> <span class="n">process</span> <span class="p">=</span> <span class="k">new</span> <span class="nf">Process</span><span class="p">())</span>
<span class="p">{</span>
<span class="c1">// A lot of code to invoke a system process running the .JAR file</span>
<span class="c1">// and read back the generated .PDF file</span>
<span class="p">}</span>
</code></pre></div></div>

<p>It works, but then we actually had to maintain an actual VM (with all the stuff like patching etc.) plus it’s pretty expensive to keep a VM running to only run a ‘small’ JAVA component.</p>

<p><strong>The <em>serverless</em> approach</strong><br />
Since we’re .NET developers we know our way around Azure and we knew Azure Functions had JAVA support in preview. Azure Functions allow you to run some code in the cloud without having to worry about the underlying infrastructure. It’s called <em>serverless</em>, but it’s more like <em>some-random-server.</em> The server gets instantly provisioned by Azure when your function (which is a piece of code) is triggered by an event (a HTTP GET call for instance). Less worrying about infrastructure and focus more on adding value with code!</p>

<p>My most recent JAVA coding experience was over 10 years ago so I wondered if we were able to pull it off in a descent timely matter. I had never used Maven nor had I an IDE for JAVA (we ended up just using Notepad++ ). Luckily I already had some experience with Azure Functions and JAVA looks a lot like C# 😉.</p>

<p><strong>What we installed..</strong></p>

<ol>
  <li>Java SDK</li>
  <li>Maven</li>
  <li>Azure CLI</li>
</ol>

<p><strong>What we did…</strong></p>

<ol>
  <li>Used the excellent tutorial on creating your first <a href="https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-first-java-maven">Azure Function in JAVA</a> using Maven. This Azure Function is triggered by an HTTP call.</li>
  <li>Read the body of the POST request to this function as a POJO (Plain Old JAVA Object) so we end up with a simple REST service taking the XSLT and the XML as JSON properties and giving the raw PDF bytes as a response.</li>
  <li>Since we’re in a JAVA world there is an <a href="https://mvnrepository.com/artifact/org.apache.xmlgraphics/fop">Apache FOP JAVA package available in Maven</a>. We added the Apache FOP package dependency into the <code class="language-plaintext highlighter-rouge">pom.xml</code> that was generated by the Maven Azure Function example.</li>
  <li>Invoke Apache FOP through the package (good code examples can be found <a href="https://xmlgraphics.apache.org/fop/2.1/embedding.html">here</a>) and return the resulting PDF bytes into the response using:</li>
</ol>

<div class="language-text highlighter-rouge"><div class="highlight"><pre class="highlight"><code>java.io.ByteArrayOutputStream
</code></pre></div></div>

<p>After a few hours of trial and error we had our generic Apache FOP REST service! I’m sure there are many optimizations to come but we were already happy with the result!</p>]]></content><author><name>Marc Mathijssen</name></author><category term="dotnet" /><category term="azure-functions" /><category term="java" /><summary type="html"><![CDATA[Every developer knows the struggle of generating PDF files. Even though in the .NET world there are some pretty good packages to do this…]]></summary></entry><entry><title type="html">Setting up an Azure Kubernetes Cluster for a .NET Core MVC app</title><link href="https://www.marcmathijssen.nl/2018/07/04/setting-up-an-azure-kubernetes-cluster-for-a-net-core-mvc-app/" rel="alternate" type="text/html" title="Setting up an Azure Kubernetes Cluster for a .NET Core MVC app" /><published>2018-07-04T00:00:00+00:00</published><updated>2018-07-04T00:00:00+00:00</updated><id>https://www.marcmathijssen.nl/2018/07/04/setting-up-an-azure-kubernetes-cluster-for-a-net-core-mvc-app</id><content type="html" xml:base="https://www.marcmathijssen.nl/2018/07/04/setting-up-an-azure-kubernetes-cluster-for-a-net-core-mvc-app/"><![CDATA[<p>The last couple of weeks I’ve been playing around with Kubernetes (popular abbreviation: k8s). Kubernetes is the #1 container orchestration tool that helps you deploying and scaling containers.</p>

<p>It took me some time figuring out how to get my simple .NET Core MVC app running in Kubernetes on Azure. I started off with some very basic Docker knowledge, and it turned out <a href="https://kubernetes.io/docs/concepts/">Kubernetes throws many more concepts in your face</a> you need to get to know!</p>

<p>I will show you the steps it took to get my .NET Core MVC app running on a managed <a href="https://azure.microsoft.com/en-us/services/kubernetes-service/">Kubernetes cluster in Azure</a>. <strong>I might skip a lot of details here</strong>. If you want to understand some concepts better (like Docker, private container registries, Kubernetes) I suggest you google them during the steps they’re mentioned in.</p>

<p><strong>Prerequisites:</strong></p>

<ul>
  <li>An Azure subscription</li>
  <li>A .NET MVC Core app</li>
  <li>Docker or Docker Toolbox</li>
  <li>A private container registry (for instance <a href="https://azure.microsoft.com/nl-nl/services/container-registry/">Azure Container Registry</a> )</li>
</ul>

<h2 id="step-1-create-a-kubernetes-cluster">Step 1: Create a Kubernetes cluster</h2>

<p>You can create a Kubernetes cluster using the Azure CLI (either in the portal or from your local PowerShell). These steps are also available in the portals GUI, but since you’re going to need the command line pretty often in this tutorial we’ll stick to commands only 🙂</p>

<p>First I created a new resource group</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>az group create <span class="nt">-l</span> westeurope <span class="nt">-n</span> k8s
</code></pre></div></div>

<p>Then I added a Kubernetes cluster with a single node (=VM) of the Standard_A1_v2 size. By default you’ll get 3 nodes with better specs, but I didn’t need that right now.</p>

<p><strong>Please note you can always add increase or decrease the nodes, but you won’t be able to add nodes of different VM specs. So this is pretty important decision you make up front.</strong></p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>az aks create <span class="nt">--resource-group</span> k8s <span class="nt">--name</span> cluster01 <span class="nt">--generate-ssh-keys</span> <span class="nt">--node-vm-size</span> Standard_A1_v2 <span class="nt">--node-count</span> 1 <span class="nt">--enable-addons</span> http_application_routing
</code></pre></div></div>

<p>I also added this thing called <a href="https://docs.microsoft.com/en-us/azure/aks/http-application-routing">http_application_routing</a> that allows me to easily access the application through http on our cluster.</p>

<p>From my experience it will take a minute or 15 before everything is setup and the nodes have been provisioned. In the Azure portal you’ll see a bunch of new resources and a another new resource group (the cluster infrastructure group).</p>

<p><img src="/assets/images/setting-up-an-azure-kubernetes-cluster-for-a-net-core-mvc-app/0-pm4fa-dyznpiikaj.png" alt="" /></p>

<p>When everything is setup you can associate the CLI with the cluster by using the following command</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>az aks get-credentials <span class="nt">--resource-group</span><span class="o">=</span>k8s <span class="nt">--name</span><span class="o">=</span>cluster01
</code></pre></div></div>

<p>This allows you to access the cluster through the <em>kubectl</em> commands (by default installed on the Azure Portal, if you want to use <a href="https://kubernetes.io/docs/tasks/tools/install-kubectl/">kubectl locally check these instructions</a>).</p>

<p>After this step I can control my Kubernetes cluster through the command line. A simple check is to run this command.</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>kubectl get nodes
</code></pre></div></div>

<p>Which showed me:</p>

<div class="language-text highlighter-rouge"><div class="highlight"><pre class="highlight"><code>NAME STATUS ROLES AGE VERSION
aks-nodepool1-12041136-0 Ready agent 10m v1.9.6
</code></pre></div></div>

<p>This is the single node (virtual machine) I provisioned to the cluster. You won’t see a master node. If you see a master node I think you’ve setup an unmanaged kubernetes cluster through Azure Container Service (and used <em>acs</em> in stead of <em>aks</em> in the commands).</p>

<p>With the unmanaged service you are responsible for updating the control plane, and there are more differences I won’t go into right now.</p>

<h2 id="step-2-dockerize-thenet-core-mvcapp">Step 2: Dockerize the .NET Core MVC app</h2>

<p>There are pretty good tutorials out there explaining this. I’ll show you my docker file and the commands I use.</p>

<p>My project is called OMT.Web en this is the Docker file to build it into a container image.</p>

<div class="language-dockerfile highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">FROM</span><span class="w"> </span><span class="s">microsoft/aspnetcore-build:2.0</span><span class="w"> </span><span class="k">AS</span><span class="w"> </span><span class="s">build-env</span>
<span class="k">WORKDIR</span><span class="s"> /app COPY . ./</span>
<span class="k">RUN </span>dotnet publish ./OMT.Web/OMT.Web.csproj <span class="nt">-c</span> Release <span class="nt">-o</span> out

<span class="c"># Build runtime image FROM microsoft/aspnetcore:2.0</span>
<span class="k">WORKDIR</span><span class="s"> /app EXPOSE 80</span>
<span class="k">COPY</span><span class="s"> --from=build-env /app/OMT.Web/out .</span>
<span class="k">ENTRYPOINT</span><span class="s"> ["dotnet", "OMT.Web.dll"]</span>
</code></pre></div></div>

<p>It copies the solution to the build container (microsoft/aspnetcore-build) which publishes the MVC project to the runtime container (microsoft/aspnetcore:2.0). By default port 80 is exposed since it’s handling web requests.</p>

<p>I build this Docker file (that’s called Web) from the root of my solution using the following command:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>docker build <span class="nt">-t</span> omt.web <span class="nb">.</span> <span class="nt">-f</span> Web
</code></pre></div></div>

<p>Before I can push it to the private registry I have to authenticate first using <a href="https://docs.docker.com/engine/reference/commandline/login/">docker login</a>.</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>docker login marcmathijssen.azurecr.io <span class="nt">-u</span> xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx <span class="nt">-p</span> myPassword
</code></pre></div></div>

<p>Now I can tag my local image and push it to the private registry</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>docker tag omt.web:latest marcmathijssen.azurecr.io/omt/web docker push marcmathijssen.azurecr.io/omt/web
</code></pre></div></div>

<p>It will show me something like:</p>

<div class="language-text highlighter-rouge"><div class="highlight"><pre class="highlight"><code>The push refers to a repository [marcmathijssen.azurecr.io/omt/web]
672fff0c4445: Pushing [=====================================&gt; ] 31.99MB/43.13MB
</code></pre></div></div>

<p>The image is in the registry, and the cluster is ready for use. Let’s deploy.</p>

<h2 id="step-3-deploy-the-container-in-kubernetes">Step 3: Deploy the container in Kubernetes</h2>

<p>As I told you in the intro: Kubernetes throws a bunch of concepts at you:</p>

<ul>
  <li>Deployment: Configuring and creating of all of the below</li>
  <li>Pods: One or multiple containers that will be guaranteed to run on the same node (handy if you have multiple containers that depend on each other presence on the same node)</li>
  <li>Services: Allows traffic to your pods</li>
  <li>Ingress: Allows traffic to your services through domain names</li>
</ul>

<p>I created a YAML file (omt.yaml) that sets up a pod, service and ingress through a deployment:</p>

<div class="language-yaml highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="na">apiVersion</span><span class="pi">:</span> <span class="s">extensions/v1beta1</span>
<span class="na">kind</span><span class="pi">:</span> <span class="s">Deployment</span>
<span class="na">metadata</span><span class="pi">:</span>
<span class="na">name</span><span class="pi">:</span> <span class="s">omtweb</span>
<span class="na">spec</span><span class="pi">:</span>
<span class="na">template</span><span class="pi">:</span>
<span class="na">metadata</span><span class="pi">:</span>
<span class="na">labels</span><span class="pi">:</span>
<span class="na">app</span><span class="pi">:</span> <span class="s">omtweb</span>
<span class="na">spec</span><span class="pi">:</span>
<span class="na">containers</span><span class="pi">:</span>
<span class="pi">-</span> <span class="na">image</span><span class="pi">:</span> <span class="s">marcmathijssen.azurecr.io/omt/web</span>
<span class="na">name</span><span class="pi">:</span> <span class="s">omtweb</span>
<span class="na">ports</span><span class="pi">:</span>
<span class="pi">-</span> <span class="na">containerPort</span><span class="pi">:</span> <span class="m">80</span>
<span class="na">imagePullSecrets</span><span class="pi">:</span>
<span class="pi">-</span> <span class="na">name</span><span class="pi">:</span> <span class="s">marcmathijssencr</span>
<span class="nn">---</span>
<span class="na">apiVersion</span><span class="pi">:</span> <span class="s">v1</span>
<span class="na">kind</span><span class="pi">:</span> <span class="s">Service</span>
<span class="na">metadata</span><span class="pi">:</span>
<span class="na">name</span><span class="pi">:</span> <span class="s">omtweb</span>
<span class="na">spec</span><span class="pi">:</span>
<span class="na">ports</span><span class="pi">:</span>
<span class="pi">-</span> <span class="na">port</span><span class="pi">:</span> <span class="m">80</span>
<span class="na">protocol</span><span class="pi">:</span> <span class="s">TCP</span>
<span class="na">targetPort</span><span class="pi">:</span> <span class="m">80</span>
<span class="na">selector</span><span class="pi">:</span>
<span class="na">app</span><span class="pi">:</span> <span class="s">omtweb</span>
<span class="na">type</span><span class="pi">:</span> <span class="s">ClusterIP</span>
<span class="nn">---</span>
<span class="na">apiVersion</span><span class="pi">:</span> <span class="s">extensions/v1beta1</span>
<span class="na">kind</span><span class="pi">:</span> <span class="s">Ingress</span>
<span class="na">metadata</span><span class="pi">:</span>
<span class="na">name</span><span class="pi">:</span> <span class="s">omtweb</span>
<span class="na">annotations</span><span class="pi">:</span>
<span class="na">kubernetes.io/ingress.class</span><span class="pi">:</span> <span class="s">addon-http-application-routing</span>
<span class="na">spec</span><span class="pi">:</span>
<span class="na">rules</span><span class="pi">:</span>
<span class="pi">-</span> <span class="na">host</span><span class="pi">:</span> <span class="s">ourmixtape.net</span>
<span class="na">http</span><span class="pi">:</span>
<span class="na">paths</span><span class="pi">:</span>
<span class="pi">-</span> <span class="na">backend</span><span class="pi">:</span>
<span class="na">serviceName</span><span class="pi">:</span> <span class="s">omtweb</span>
<span class="na">servicePort</span><span class="pi">:</span> <span class="m">80</span>
<span class="na">path</span><span class="pi">:</span> <span class="s">/</span>
<span class="pi">-</span> <span class="na">host</span><span class="pi">:</span> <span class="s">www.ourmixtape.net</span>
<span class="na">http</span><span class="pi">:</span>
<span class="na">paths</span><span class="pi">:</span>
<span class="pi">-</span> <span class="na">backend</span><span class="pi">:</span>
<span class="na">serviceName</span><span class="pi">:</span> <span class="s">omtweb</span>
<span class="na">servicePort</span><span class="pi">:</span> <span class="m">80</span>
<span class="na">path</span><span class="pi">:</span> <span class="s">/</span>
</code></pre></div></div>

<p>As you can see in the file, the image is pulled from my private registry. Kubernetes uses credentials for this. I had to save these credentials in Kubernetes first through the command line.</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>kubectl create secret docker-registry marcmathijssencr <span class="nt">--docker-server</span><span class="o">=</span>marcmathijssen.azurecr.io <span class="nt">--docker-username</span><span class="o">=</span>marcmathijssen <span class="nt">--docker-password</span><span class="o">=</span>&lt;my-key&gt; <span class="nt">--docker-email</span><span class="o">=</span>marcmathijssen@gmail.com
</code></pre></div></div>

<p>I created the deployment of my app with the following command.</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>kubectl create <span class="nt">-f</span> omt.yaml
</code></pre></div></div>

<p>It showed me</p>

<div class="language-text highlighter-rouge"><div class="highlight"><pre class="highlight"><code>deployment "omtweb" created
service "omtweb" created
ingress "omtweb" created
</code></pre></div></div>

<p>So the container is running on the cluster, but how do we access it? The Azure Kubernetes cluster has a public IP assigned to the ingress controller to it. You can find it through querying the ingress.</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>kubectl get ing

NAME HOSTS ADDRESS PORTS AGE
omtweb ourmixtape.net,www.ourmixtape.net 13.80.99.67 80 10m
</code></pre></div></div>

<p>You can also let Azure create a domain name for your resource. Read all about this in the documentation of <a href="https://docs.microsoft.com/en-us/azure/aks/http-application-routing">http application routing</a>. Convenient if you just want to add a CNAME record in yourdomain.com pointing to the cluster.</p>

<p>Once you’ve setup the DNS records your .NET Core MVC application will be served from your Kubernetes cluster in Azure.</p>

<h2 id="tips">Tips</h2>

<ul>
  <li>The tutorials on the <a href="https://kubernetes.io/docs/tutorials/kubernetes-basics/">Kubernetes website</a> are pretty good if you need more knowledge on Kubernetes itself.</li>
  <li>You can view your Azure Kubernetes dashboard by <a href="https://docs.microsoft.com/en-us/azure/aks/kubernetes-dashboard">using the Azure CLI powershell</a></li>
  <li>Test your container on your machine first before you push it to the registry (it’s harder to debug it there :-))</li>
</ul>]]></content><author><name>Marc Mathijssen</name></author><category term="kubernetes" /><category term="azure" /><category term="dotnet" /><summary type="html"><![CDATA[The last couple of weeks I’ve been playing around with Kubernetes (popular abbreviation: k8s). Kubernetes is the #1 container…]]></summary></entry><entry><title type="html">Add SSL to Azure Web App using LetsEncrypt</title><link href="https://www.marcmathijssen.nl/2018/06/30/add-ssl-to-azure-web-app-using-letsencrypt/" rel="alternate" type="text/html" title="Add SSL to Azure Web App using LetsEncrypt" /><published>2018-06-30T00:00:00+00:00</published><updated>2018-06-30T00:00:00+00:00</updated><id>https://www.marcmathijssen.nl/2018/06/30/add-ssl-to-azure-web-app-using-letsencrypt</id><content type="html" xml:base="https://www.marcmathijssen.nl/2018/06/30/add-ssl-to-azure-web-app-using-letsencrypt/"><![CDATA[<p>If you’re interested in adding SSL / HTTPS to your Azure Web App you can buy a certificate within Azure, but if you use <a href="https://letsencrypt.org/">LetsEncrypt</a> you can add SSL for free (downside: renew your certificate every 3 months)</p>

<p>I’ve seen scripts &amp; websites automating these steps. I could not get them to work for this specific scenario (.NET Core MVC Webapplication + Azure Web App) and that’s why I wrote down the steps to get it to work. If you do not have this setup, there might be <a href="https://letsencrypt.org/docs/client-options/">an easier way</a>.</p>

<p><strong>Prerequisites</strong></p>

<ul>
  <li>Ubuntu (I used the <a href="https://www.microsoft.com/en-us/p/ubuntu/9nblggh4msv6">Ubuntu app</a> on my Windows Machine)</li>
  <li>An Azure Web App running on a App Service (platform: Windows, minimal plan supporting SSL: Basic)</li>
</ul>

<h2 id="step-1-install-certbot-openssl">Step 1: Install Certbot &amp; OpenSSL</h2>

<p>The tools you need to create the certificate with LetsEncrypt and convert it to a format Azure accepts are</p>

<ul>
  <li>Certbot: Sets up the challenge with LetsEncrypt to verify your domain</li>
  <li>OpenSSL: Converts the certificates created by Certbot to a format that Azure accepts (PFX)</li>
</ul>

<p>I’ve installed these tools in the <a href="https://www.microsoft.com/en-us/p/ubuntu/9nblggh4msv6">Ubuntu app</a> on my Windows Machine using the following commands:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">sudo </span>apt-get <span class="nb">install </span>software-properties-common
<span class="nb">sudo </span>add-apt-repository ppa:certbot/certbot
<span class="nb">sudo </span>apt-get <span class="nb">install </span>certbot
<span class="nb">sudo </span>apt-get <span class="nb">install </span>openssl
</code></pre></div></div>

<h2 id="step-2-setup-a-challenge-with-letsencrypt">Step 2: Setup a challenge with LetsEncrypt</h2>

<p>Now we’ve installed Certbot we can tell it to setup a challenge with the LetsEncrypt servers to verify you’re the owner of the domain. In this example I will use the HTTP challenge.</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">sudo </span>certbot certonly <span class="nt">--preferred-challenges</span> http <span class="nt">-d</span> ourmixtape.net <span class="nt">--manual</span>
</code></pre></div></div>

<p>We use the flag <em>manual</em> to indicate we’re doing this on behalf of a different server, since we’re not running this command from web server itself (Azure doesn’t allow this).</p>

<p>Note: you should replace ourmixtape.net with your own domain.</p>

<p><strong>Please note that these steps will generate the certificate for the exact domain you enter. It matters if you enter</strong> <a href="http://www.yourdomain.com"><strong>www.yourdomain.com</strong></a> <strong>or yourdomain.com! If you want both, complete the steps twice.</strong></p>

<p>You’ll see instructions on your screen on what file and contents you should create.</p>

<p>Create the file and use the .txt extension . Why? You’ll see in the next step.</p>

<h2 id="step-3-upload-the-challenge-file-to-your-azure-webapp">Step 3: Upload the challenge file to your Azure Web App</h2>

<p>So now you have a .txt file with the contents that you were supposed to add. You upload this file into a directory on your app service plan. Upload it any way you like (I used FTP).</p>

<p>Since I have a .NET core application I had to upload into the wwwroot folder in the wwwroot of my Azure website. This is the folder for your static files in .NET core.</p>

<p>Check if you can access the file in your browser by going to the full url with the .txt extension.</p>

<h2 id="step-4-modify-your-webconfig-to-rewrite-the-challenge-file-without-extension">Step 4: Modify your web.config to rewrite the challenge file without extension</h2>

<p>As you can see in the instructions in Step 1. The servers of LetsEncrypt will visit your challenge file without the .txt extension. By default this isn’t supported by .NET / IIS and that’s why we add an IIS rewrite rule to redirect the url LetsEncrypt checks to the .txt file we’ve uploaded.</p>

<div class="language-xml highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="cp">&lt;?xml version="1.0" encoding="utf-8"?&gt;</span>
<span class="nt">&lt;configuration&gt;</span>
<span class="nt">&lt;system.webServer&gt;</span>
<span class="nt">&lt;handlers&gt;</span>
<span class="nt">&lt;add</span> <span class="na">name=</span><span class="s">"aspNetCore"</span> <span class="na">path=</span><span class="s">"*"</span> <span class="na">verb=</span><span class="s">"*"</span> <span class="na">modules=</span><span class="s">"AspNetCoreModule"</span> <span class="na">resourceType=</span><span class="s">"Unspecified"</span> <span class="nt">/&gt;</span>
<span class="nt">&lt;/handlers&gt;</span>
<span class="nt">&lt;aspNetCore</span> <span class="na">processPath=</span><span class="s">"dotnet"</span> <span class="na">arguments=</span><span class="s">".\OMT.Web.dll"</span> <span class="na">stdoutLogEnabled=</span><span class="s">"false"</span> <span class="na">stdoutLogFile=</span><span class="s">".\logs\stdout"</span> <span class="nt">/&gt;</span>
<span class="nt">&lt;rewrite&gt;</span>
<span class="nt">&lt;rules&gt;</span>
<span class="nt">&lt;rule</span> <span class="na">name=</span><span class="s">"wildcard"</span><span class="nt">&gt;</span>
<span class="nt">&lt;match</span> <span class="na">url=</span><span class="s">".*well-known/acme-challenge/(?!.*?\.txt$)(.*)$"</span> <span class="nt">/&gt;</span>
<span class="nt">&lt;action</span> <span class="na">type=</span><span class="s">"Redirect"</span> <span class="na">url=</span><span class="s">"/.well-known/acme-challenge/{R:1}.txt"</span> <span class="nt">/&gt;</span>
<span class="nt">&lt;/rule&gt;</span>
<span class="nt">&lt;/rules&gt;</span>
<span class="nt">&lt;/rewrite&gt;</span>
<span class="nt">&lt;/system.webServer&gt;</span>
<span class="nt">&lt;/configuration&gt;</span>
</code></pre></div></div>

<p>Now you should be able to visit the <strong>exact</strong> <strong>url</strong>:</p>

<p><img src="/assets/images/add-ssl-to-azure-web-app-using-letsencrypt/0-gfwvwmgtcsu4e7dl.png" alt="" /></p>

<p>When successful (you see the contents of the .txt file) you can press enter in your Ubuntu console to complete the challenge and generate the certificate.</p>

<h2 id="step-5-convert-the-certificate-to-pfx-usingopenssl">Step 5: Convert the certificate to PFX using OpenSSL</h2>

<p><img src="/assets/images/add-ssl-to-azure-web-app-using-letsencrypt/0-gzyrasozhe5do-k8.png" alt="" /></p>

<p>When you’ve done this you can convert the certificates using the following command.</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">sudo </span>openssl pkcs12 <span class="nt">-export</span> <span class="nt">-out</span> /etc/letsencrypt/live/ourmixtape.net/ourmixtape.pfx <span class="nt">-inkey</span> /et c/letsencrypt/live/ourmixtape.net/privkey.pem <span class="nt">-in</span> /etc/letsencrypt/live/ourmixtape.net/cert.pem
</code></pre></div></div>

<p>It will ask you for a password (remember this) and will generate a .pfx file you can upload into the Azure portal.</p>

<p>If you want to copy the PFX file from your Windows Ubuntu app to your Windows Environment you can use the following folder</p>

<div class="language-text highlighter-rouge"><div class="highlight"><pre class="highlight"><code>%userprofile%\AppData\Local\Packages
</code></pre></div></div>

<p>Search for the <em>CanonicalGroupLimited.UbuntuonWindows</em> folder and navigate to the following path in that folder.</p>

<div class="language-text highlighter-rouge"><div class="highlight"><pre class="highlight"><code>%userprofile%\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_(YOUR_POSTFIX)\LocalState\rootfs\etc\letsencrypt\live\ourmixtape.net
</code></pre></div></div>

<p>There you’ll find the generated PFX file. Copy it to somewhere convenient.</p>

<h2 id="step-6-upload-your-pfx-certificate-into-the-azure-portal-and-add-the-sslbinding">Step 6: Upload your PFX certificate into the Azure Portal and add the SSL binding</h2>

<p>Go to the SSL settings of your web app and press ‘upload certificate’</p>

<p><img src="/assets/images/add-ssl-to-azure-web-app-using-letsencrypt/0-wrhyg3jtcqbo3sv6.png" alt="" /></p>

<p>Upload your .pfx file and enter the password you remembered from Step 4.</p>

<p><img src="/assets/images/add-ssl-to-azure-web-app-using-letsencrypt/0-pteu8f7ygts2rmtp.png" alt="" /></p>

<p>Add the SSL binding to the uploaded certificate</p>

<p><img src="/assets/images/add-ssl-to-azure-web-app-using-letsencrypt/0-0m5r-o8jnezrspd1.png" alt="" /></p>

<p>Wait a few minutes and visit your website using https and you’ll see that it’s served with the LetsEncrypt certificate.</p>

<p><img src="/assets/images/add-ssl-to-azure-web-app-using-letsencrypt/0-5oiq7fklxfcghrco.png" alt="" /></p>

<p><strong>Remember to do these steps for each subdomain</strong></p>

<hr />

<p><em>Originally published at</em> <a href="https://marcmathijssen.nl/add-ssl-azure-web-app-letsencrypt/"><em>marcmathijssen.nl</em></a> <em>on June 30, 2018.</em></p>]]></content><author><name>Marc Mathijssen</name></author><category term="azure" /><category term="ssl" /><category term="letsencrypt" /><summary type="html"><![CDATA[If you’re interested in adding SSL / HTTPS to your Azure Web App you can buy a certificate within Azure, but if you use LetsEncrypt you…]]></summary></entry><entry><title type="html">Running a .NET core application in an Azure Container Instance</title><link href="https://www.marcmathijssen.nl/2018/06/27/running-a-net-core-application-in-an-azure-container-instance/" rel="alternate" type="text/html" title="Running a .NET core application in an Azure Container Instance" /><published>2018-06-27T00:00:00+00:00</published><updated>2018-06-27T00:00:00+00:00</updated><id>https://www.marcmathijssen.nl/2018/06/27/running-a-net-core-application-in-an-azure-container-instance</id><content type="html" xml:base="https://www.marcmathijssen.nl/2018/06/27/running-a-net-core-application-in-an-azure-container-instance/"><![CDATA[<p>Even though containers have been a popular way to ship applications for a couple of years it was only until recently I found the perfect problem to solve with a container.</p>

<p>A while ago I created the little web app <a href="http://ourmixtape.net/">ourmixtape.net</a> that allows you to create a shared playlist based on the favorite Spotify tracks of you and your friends / colleagues / family members. A feature of ourmixtape.net is you can let it regenerate the playlist every night or every week, so when your favorite songs change, so will your shared playlist.</p>

<p>Traditionally I would execute this background task inside a Windows Service, but I didn’t want to buy and maintain a VM or VPS because of the costs and the overhead it would generate. I really don’t need a fullblown server that’s always running.</p>

<p>After investigating some options (Azure Webjobs, Azure Functions) I decided that using <a href="https://azure.microsoft.com/en-us/services/container-instances/">Azure Container Instances</a> (ACI) was the easiest and cheapest way to run this background task in the cloud. Why?</p>

<ul>
  <li>Per second billing</li>
  <li>No need to maintain a server (or cluster)</li>
</ul>

<p>So I created a simple .NET Core console application called <em>OMT.TaskRunner</em> which executes all background tasks of ourmixtape.net and closes down when done.</p>

<p>In 3 steps I will show you what I did to run this application inside a Docker container that runs as an Azure Container Instance.</p>

<p><strong>Before I started I had the following stuff:</strong></p>

<ul>
  <li>Docker for Windows (I used the Docker Toolbox since I could not install Hyper-V on my machine)</li>
  <li>A .NET Core console application</li>
  <li>An Azure subscription</li>
  <li>A Docker account</li>
</ul>

<h2 id="step-1-turn-yournet-core-console-application-into-a-dockerimage">Step 1: Turn your .NET core console application into a Docker image</h2>

<p>The first thing to do is to turn your .NET core console application into a docker image. This is done by creating a <a href="https://docs.docker.com/engine/reference/builder/">docker file</a>. The docker file contains the build instruction of your application.</p>

<p>This is the docker file I used.</p>

<div class="language-dockerfile highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">FROM</span><span class="w"> </span><span class="s">microsoft/dotnet:2.0-sdk</span><span class="w"> </span><span class="k">AS</span><span class="w"> </span><span class="s">build-env</span>
<span class="k">WORKDIR</span><span class="s"> /app # copy everything else and build</span>
<span class="k">COPY</span><span class="s"> /OMT.Core/. ./OMT.Core/</span>
<span class="k">COPY</span><span class="s"> /OMT.TaskRunner/. ./OMT.TaskRunner/</span>

<span class="k">RUN </span>dotnet restore ./OMT.TaskRunner/OMT.TaskRunner.csproj
<span class="k">RUN </span>dotnet publish ./OMT.TaskRunner/OMT.TaskRunner.csproj <span class="nt">-c</span> Release <span class="nt">-o</span> out <span class="c"># build runtime image</span>

<span class="k">FROM</span><span class="s"> microsoft/dotnet:2.0-runtime</span>
<span class="k">WORKDIR</span><span class="s"> /app</span>
<span class="k">COPY</span><span class="s"> --from=build-env /app/OMT.TaskRunner/out ./</span>
<span class="k">ENTRYPOINT</span><span class="s"> ["dotnet", "OMT.TaskRunner.dll"]</span>
</code></pre></div></div>

<p>It copies the source files of the application (OMT.TaskRunner) and the source files of a referenced project it depends on (OMT.Core) to a directory of the .NET 2.0 SDK docker image. When you run this image it will build your application and create a Docker Image with your application on top the the .NET 2.0 runtime image.</p>

<p>I put this Docker file in the root of my solution folder and build the image with the following command</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>docker build <span class="nt">-t</span> omt.taskrunner <span class="nb">.</span>
</code></pre></div></div>

<p>After the build succeeds I have a Docker image called <em>omt.taskrunner</em> locally<em>.</em> I can run my image on my local machine using the following command</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>docker run omt.taskrunner:latest
</code></pre></div></div>

<h2 id="step-2-push-your-docker-image-to-a-private-repository">Step 2: Push your Docker Image to a private repository</h2>

<p>Since I want my application to run in the cloud I have to publish this image to a repository. I decided to use the private Docker repository that allows you to have one free private container.</p>

<p>To publish to a private registry you first have to authenticate docker with your private registry (done through <a href="https://docs.docker.com/engine/reference/commandline/login/"><em>docker login</em></a> ). Once you’ve authenticated you can tag your image using the following command:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>docker tag omt.taskrunner:latest marcmathijssen/omt
</code></pre></div></div>

<p>With this command I tag my local image (omt.taskrunner) with the name of my docker private repo (marcmathijssen/omt). Afterwards I can push the container to the private repository.</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>docker push marcmathijssen/omt:latest
</code></pre></div></div>

<p>This will ‘upload’ the image to the private repository.</p>

<h2 id="step-3-schedule-azure-container-instances-using-azure-logicapps">Step 3: Schedule Azure Container Instances using Azure Logic Apps</h2>

<p>When you look into the <a href="https://docs.microsoft.com/en-us/azure/container-instances/container-instances-tutorial-deploy-app">documentation of the Azure Container Instances</a> you’ll read about starting container instances by using the command line. Since I want to run my container periodically I need something else. I turned to Azure Logic Apps.</p>

<p>You can schedule your container easily with <a href="https://azure.microsoft.com/en-us/services/logic-apps/">Azure Logic Apps</a>. Azure Logic Apps allow you to visually create workflows with all kinds of predefined tasks. I created an Azure Logic App that runs my container at a predefined time (recurrence trigger) and send me an email afterwards.</p>

<p>Every task I needed was already defined in Azure Logic Apps and all I had to do was editing the properties (container name, credentials etc.) and link the tasks together. This is my Azure Logic App.</p>

<p>I’ve been running the <a href="http://ourmixtape.net/">ourmixtape.net</a> background tasks inside a docker container for 6 months now. The things I like the most are:</p>

<ul>
  <li>Easy deployment: Just build &amp; push the container. The Azure Logic App will download the new image the next time it runs</li>
  <li>Pay what you use: Currently I pay average € 0,18 per month for my container that runs for a few minutes per day. These costs will increase as my app gets more users (or the other way around :-))</li>
</ul>

<p>Hope you enjoyed this little tutorial. <a href="https://twitter.com/marcmathijssen">Tweet me</a> or send me an <a href="mailto:marcmathijssen@gmail.com">email</a> if you have any questions or remarks.</p>]]></content><author><name>Marc Mathijssen</name></author><category term="dotnet" /><category term="docker" /><category term="azure" /><summary type="html"><![CDATA[Even though containers have been a popular way to ship applications for a couple of years it was only until recently I found the perfect…]]></summary></entry><entry><title type="html">Breaking up the big application</title><link href="https://www.marcmathijssen.nl/2018/06/25/breaking-up-the-big-application/" rel="alternate" type="text/html" title="Breaking up the big application" /><published>2018-06-25T00:00:00+00:00</published><updated>2018-06-25T00:00:00+00:00</updated><id>https://www.marcmathijssen.nl/2018/06/25/breaking-up-the-big-application</id><content type="html" xml:base="https://www.marcmathijssen.nl/2018/06/25/breaking-up-the-big-application/"><![CDATA[<p><strong>Cross post from the</strong> <a href="https://www.abf.store/i/nl/news/blog-breaking-up-the-big-application-2/"><strong>company blog</strong></a> <strong>where I posted this as a lesson learned from visiting NDC Oslo.</strong></p>

<p>The last couple of years there has been a strong focus on microservices in about every architecture talk I’ve heard or seen. I believe every developer, project manager and business owner sees advantages in having multiple small services over one big application. I also believe there are big advantages but like anything in IT there are always trade offs.</p>

<h2 id="whats-a-microservice">What’s a (micro)service?</h2>

<p>I believe the term microservice is easy to misunderstand. It has the word micro in it, and we developers easily relate that to the amount of code that runs the service. For me that always felt weird, why do all the hassle to expose some kind of functionality (over HTTP for instance) that could have easily been managed as a regular dependency. When I attended <a href="https://ndcoslo.com/">NDC Oslo</a> last week I gained more knowledge on this topic by doing a workshop on how to create a service oriented architecture. It started of by defining what a service actually is:</p>

<p><strong><em>A service is the technical authority for a specific business capability</em></strong></p>

<p>A business capability usually involves retrieving or modifying data and doing some business logic before or after. When you split up your application into smaller services you should strive for the smallest autonomous design. A single service can cross all technical boundaries. A part of it may be deployed as an iOS app, another part exposes a REST API, and another part can be a .dll that’s loaded into a windows application. All these parts make up the business service. The team owning the service should be able to modify all parts (which clearly involves various types of expertise) and also be autonomous in it’s work.</p>

<p><img src="/assets/images/breaking-up-the-big-application/0-8-f6svbxjvfjnprr.png" alt="" /></p>

<p><em>The S1, S2 and S3 columns are business services that cross multiple technical boundaries. Slide from the ‘SOA architecture done right’ workshop by Adam Ralph and Jimmy Bogard.</em></p>

<p>I believe that for most companies this is too hard to achieve (it differs from any common organizational structure), but it made me realize that <strong>‘doing’ microservices really isn’t about the code</strong>. It’s about thinking about what services your business really exposes to it’s customers or internally. The code should eventually resemble those business services and every line of code should eventually belong to one of those business services.</p>

<p>Creating microservices for the sake of it will only add more complexity and will eventually lead to bigger problems large monolithic applications have when it comes to changing requirement or adding new features.</p>

<h2 id="our-story">Our story</h2>

<p>When I joined ABF I quickly became solely responsible of &gt; 200.000 lines of code running a dozen applications. Besides the code I also had to manage the infrastructure running these components. Like any developer I felt the urge to break up this monolith into smaller ‘services’, but I also wanted to automate the builds and deployments, create automated tests and add value to the business. I realized that if I wanted to completely break up this application I’d basically doing a rewrite, and there was no justification for that. The applications worked fine and most users were happy with it. The existing code only made it harder to add new features. It felt better to making the monolith easier to deploy first.</p>

<p>Over the 3 years I worked at ABF (and luckily became part of a team of developers ) we slowly started breaking off chunks of the big application and put them in separate components (which we call ‘domains’). We added messages and queues between the domains to make them operate more autonomous and make certain business events more traceable. We still have large parts of the ‘big application’ in place because there hasn’t been a good reason (usually a change or new feature) to move them into smaller components.</p>]]></content><author><name>Marc Mathijssen</name></author><category term="architecture" /><category term="microservices" /><summary type="html"><![CDATA[Cross post from the company blog where I posted this as a lesson learned from visiting NDC Oslo.]]></summary></entry><entry><title type="html">Migrating corsozundert.nl to Azure</title><link href="https://www.marcmathijssen.nl/2018/06/22/migrating-corsozundert-nl-to-azure/" rel="alternate" type="text/html" title="Migrating corsozundert.nl to Azure" /><published>2018-06-22T00:00:00+00:00</published><updated>2018-06-22T00:00:00+00:00</updated><id>https://www.marcmathijssen.nl/2018/06/22/migrating-corsozundert-nl-to-azure</id><content type="html" xml:base="https://www.marcmathijssen.nl/2018/06/22/migrating-corsozundert-nl-to-azure/"><![CDATA[<p><strong>This a crosspost of the write-up I created after we (a small team of volunteers) migrated the website</strong> <a href="https://corsozundert.nl/"><strong>corsozundert.nl</strong></a> <strong>to Azure to prepare it for the yearly high traffic weekend. First posted</strong> <a href="http://corsozundert.nl/en/nieuws/migrating-corsozundert-nl-to-azure/"><strong>here</strong></a><strong>.</strong></p>

<p>On the first sunday in september the small town of Zundert (The Netherlands) receives a lot of visitors. On this day the <a href="https://corsozundert.nl/en/our-corso/">biggest flower parade of the world</a> takes place in the streets of Zundert. Volunteers (and mostly inhabitants of Zundert) have been working on giant floats covered in flowers for almost half a year!</p>

<p><img src="/assets/images/migrating-corsozundert-nl-to-azure/1-mfx6o8tlzl-njk69xincwg.png" alt="A float displaying the famous painter ‘Vincent van Gogh’ covered entirely in flowers. Vincent van Gogh was born in Zundert." />
<em>A float displaying the famous painter ‘Vincent van Gogh’ covered entirely in flowers. Vincent van Gogh was born in Zundert.</em></p>

<h2 id="the-first-weekend-of-september">The first weekend of september</h2>

<p><img src="/assets/images/migrating-corsozundert-nl-to-azure/0-8awcnifwarj65v2z.png" alt="" /></p>

<p>Just before, after and during this weekend, corsozundert.nl gets a lot of visitors:</p>

<ul>
  <li>On sunday morning people are looking for information about the entrance fees, parking options, and at what time the parade will start.</li>
  <li>On sunday evening people visit the website to see how the floats ranked.</li>
  <li>All weekend we have a lot of visitors showing interest after they’ve read or seen something in the dutch media</li>
</ul>

<p>For corsozundert.nl it all comes down to the first weekend in september!</p>

<p>Last year corsozundert.nl wasn’t able to handle the amount of visitors and let them down with ugly PHP error messages. Those errors weren’t doing any justice to the beautifull floats, so that’s why we (a small team of volunteers with an IT background) decided this year we would try to take corsozundert.nl to the next level.</p>

<p>Corsozundert.nl ran on a single VPS (running PHP and MySQL). It made the WordPress perform great during times traffic was low, but had no options to handle the traffic spike during this weekend. That’s why we decided to move corsozundert.nl to the cloud. Since we had some experience in our day-to-day jobs with Microsoft technologies and our organisation met all conditions to apply for the <a href="https://nonprofit.microsoft.com/">Microsoft for Nonprofits program</a>, Microsoft’s Azure was the obvious choice.</p>

<h2 id="optimizing-wordpress-forazure">Optimizing WordPress for Azure</h2>

<p>We started of with thefollowing resources to move the WordPress installation to:</p>

<ul>
  <li><a href="https://azure.microsoft.com/nl-nl/services/app-service/">App Service (Linux)</a></li>
  <li><a href="https://azure.microsoft.com/en-us/services/mysql/">Database for MySQL</a></li>
</ul>

<p>We had it up and running pretty quicky. So now we had this scalable platform for corsozundert.nl. In the Azure Portal we could easily create more instances (scale out) or upgrade to better plans (scale up). There is only one downside to this: you have to pay for this 🙂</p>

<p>We needed to make sure we were getting as much as we could from every euro spent and that’s why we investigated if we could optimize our WordPress installation.</p>

<p>What we already had was:</p>

<ul>
  <li>The <a href="https://nl.wordpress.org/plugins/wp-super-cache/">WP Super Cache</a> plugin which creates static files for your WordPress pages so the server won’t have to get to the database.</li>
</ul>

<p>What we did to make more efficient use of the resources was:</p>

<ul>
  <li>Checking the WP Super Cache plugin. It turned out another plugin (<a href="https://nl.wordpress.org/plugins/polylang/">Polylang</a>) forced the homepage not to be cached. Any visitor of the homepage would take the server more resources than necessary.</li>
  <li>Replacing the plugins <a href="https://nl.wordpress.org/plugins/really-simple-ssl/">Really Simple SSL</a> and <a href="https://nl.wordpress.org/plugins/simple-301-redirects/">Simple 301 redirects</a> with code in .htaccess. This is much and much faster because you get the redirect before you hit the PHP execution.</li>
  <li>Setup <a href="https://azure.microsoft.com/en-us/services/cache/">Azure Redis Cache</a> as a distributed object cache for WordPress.</li>
  <li>Moving our uploads directory to <a href="https://azure.microsoft.com/en-us/services/storage/">Azure Storage</a> and make it act like a CDN. The images are directly served from the Azure Storage servers which leverages our webserver and enables the browser to asynchronously load resources from 2 different servers.</li>
</ul>

<p>After these optimizations we noticed the homepage performed way better. The Chrome Developer Console showed us the following rendering times of the homepage (with browser caching disabled)</p>

<ul>
  <li>VPS: 1.77 seconds</li>
  <li>Azure: 0.55 seconds</li>
</ul>

<h2 id="simulate-lots-oftraffic">Simulate lots of traffic</h2>

<p>To check if we were doing any good we knew we had to simulate a busy day. We did that using <a href="https://github.com/JoeDog/siege">Siege</a>. This really nice open source tool helps you generate a lot of requests to a website and reports back how long it took and how many requests were succesfull. We ran a few simple test scenarios against our VPS and our Azure setup (1 x S1 App Service, 1 x MySQL B1, Redis C0) to compare the results.</p>

<p><strong>100 concurrent users for 1 minute randomly visiting a page every 0 to 3 seconds</strong></p>

<p><img src="/assets/images/migrating-corsozundert-nl-to-azure/1-tygj6hpkyjjdtio-jsl6rg.png" alt="" /></p>

<p><strong>200 concurrent users for 1 minute randomly visiting a page every 0 to 3 seconds</strong></p>

<p><img src="/assets/images/migrating-corsozundert-nl-to-azure/1-befd1qvljiipr-nskloyew.png" alt="" /></p>

<p><strong>500 concurrent users for 1 minute randomly visiting a page every 0 to 3 seconds</strong></p>

<p><img src="/assets/images/migrating-corsozundert-nl-to-azure/1-wphf4-k3sh987mngvwchxw.png" alt="" /></p>

<p>After these tests we were confident our Azure setup was outperforming the old VPS. Even though it was slowing down at 500 concurrent users it still had a &gt;99% availability.</p>

<h2 id="scale-up-orout">Scale up or out?</h2>

<p>The next step was to experiment with different setups to see what would give the best performance under load. We examined the logs of previous load tests and saw in the metrics the MySQL database didn’t consume a lot of resources. Therefore we focussed on the App Service</p>

<p>We added the price of running all weekend for each setup just to check what it it would cost to run this setup during the busiest weekend of the year.</p>

<p>These were the setups we tried and the results when for 1 minute, 500 concurrent users visit a page every 0 to 3 seconds.</p>

<p><img src="/assets/images/migrating-corsozundert-nl-to-azure/1-wgqijnanojnqph04hdhrkg.png" alt="" /></p>

<p>As you can see our WordPress installation gained more performance (and value for money) when we scaled up to a P1v2 compared to scaling out to an extra instance of the S1. We think this is due to the fact the P App Services have a SSD hard drive whereas the S App Services have a HDD hard drive. Since the WP Super Cache plugin makes sure most of the pages are served from disk, we believe our WordPress really benefits from the SSD drives.</p>

<h2 id="after-theevent">After the event…</h2>

<p>Corsozundert.nl ended up serving twice the number of pages compared to 2017 in 25% of the average page download time</p>

<h2 id="what-did-wemonitor">What did we monitor?</h2>

<p>We created an Azure dashboard with some very simple metrics of the servers running corsozundert.nl</p>

<p><img src="/assets/images/migrating-corsozundert-nl-to-azure/0-6-vv-hx-e6dwvqrb.png" alt="" /></p>

<p>Obviously we needed to know if the servers were running out of resources so we started monitoring the CPU/Memory. To get a sense of what our visitors were experiencing we also monitored</p>

<ul>
  <li>The number of requests that resulted in an error</li>
  <li>The average response time of the app service</li>
  <li>The egress of our storage account that serves as a poor mans CDN for corsozundert.nl media</li>
</ul>

<p>We setup some alerts in Azure to warn us when some of the metrics went bad. To monitor the website from the outside world we setup <a href="https://statuscake.com/">StatusCake</a> which is a great and simple monitoring tool for your website. It checked the most important corsozundert.nl pages from data centers across the world.</p>

<h2 id="before-theevent">Before the event</h2>

<p>A week before the event would take place we already noticed an increase of 10% in traffic compared to last year. A sign that we would be heading towards a busier than ever weekend for corsozundert.nl . The weather forecast was great, and it seemed a lot of people were planning their visits.</p>

<p>We decided to rule out any change to fail and scaled up and out our App Service S1 plan to 3 instances of the P1v2. That’s a pretty expensive setup but we had plenty of budget and needed to succeed. We didn’t use auto scaling because we really wanted to get a sense of control and see the impact of our scaling actions.</p>

<p>The Saturday before the event we already hit a record high number of visitors according to Google Analytics. This was already a success for the migration we did because last year the server collapsed under this load.</p>

<h2 id="during-theevent">During the event</h2>

<p>All of the team members were scattered around the village of Zundert during the event to watch the parade. We didn’t receive any down notification from our monitoring system StatusCake. It was fun to keep checking Google Analytics to see the the number of realtime visitors on corsozundert.nl , and it was fun to check the site itself and see it still responded very fast.</p>

<p><img src="/assets/images/migrating-corsozundert-nl-to-azure/0-kxa4dwr0n8dyik71.jpg" alt="" /></p>

<p><em>Winner of Corso Zundert 2018: Iguana (inter)action</em></p>

<h2 id="after-theevent-1">After the event</h2>

<p>We scaled back to 1 instance of the S1 App Service. We wrote down our scaling steps (what, when and who) and gathered some key performance metrics for future reference like:</p>

<ul>
  <li>Number of requests (Azure)</li>
  <li>Average response time (Azure)</li>
  <li>Total egress (Azure)</li>
  <li>Average page load time (Google Analytics)</li>
</ul>]]></content><author><name>Marc Mathijssen</name></author><category term="azure" /><category term="migration" /><summary type="html"><![CDATA[This a crosspost of the write-up I created after we (a small team of volunteers) migrated the website corsozundert.nl to Azure to prepare…]]></summary></entry></feed>