<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[NewDay Technology - Medium]]></title>
        <description><![CDATA[We help our customers be better with credit, providing products that responsibly meet their needs. Join us on our journey and meet the team behind our intelligent FinTech credit platform. - Medium]]></description>
        <link>https://medium.com/newday-technology?source=rss----15fa3c1fe40f---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>NewDay Technology - Medium</title>
            <link>https://medium.com/newday-technology?source=rss----15fa3c1fe40f---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 15 Nov 2026 07:40:34 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/newday-technology" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Easily making internal libraries debuggable in .NET]]></title>
            <link>https://medium.com/newday-technology/easily-making-internal-libraries-debuggable-in-net-84dcb0804b5e?source=rss----15fa3c1fe40f---4</link>
            <guid isPermaLink="false">https://medium.com/p/84dcb0804b5e</guid>
            <category><![CDATA[development]]></category>
            <category><![CDATA[dotnet]]></category>
            <category><![CDATA[debug]]></category>
            <category><![CDATA[engineering]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[Alessio Franceschelli]]></dc:creator>
            <pubDate>Thu, 15 Dec 2022 14:51:02 GMT</pubDate>
            <atom:updated>2022-12-15T14:51:02.260Z</atom:updated>
            <content:encoded><![CDATA[<h3>Easily making internal libraries debuggable in .NET</h3><p>At NewDay, we deeply care about software testing and, while we are big fans of TDD, there is no denying that being able to debug software effectively is a crucial aspect of software engineering.</p><p>Favouring a debugging session instead of writing a new unit test is a big topic on its own, so here we will only focus on a specific aspect: being able to step into an internal library from a consuming application or service in .NET.</p><p>.NET has a long history of providing a fully featured debugger via Visual Studio. When working with Microsoft libraries or many open-source ones, we get the ability to step into the code, how is that possible? And how we can achieve the same behaviour for our company internal libraries?</p><h3>Leveraging debug symbols</h3><p>In general, to debug a compiled language, on top of having access to the source code, you need the debug symbols, which map the binary to the original source code. In .NET, this role is fulfilled by the Portable Database (or PDB).</p><p>For Microsoft libraries or many open-source ones, the PDBs are automatically retrieved by Visual Studio from the Microsoft public symbols server or from the <a href="https://nuget.org/">NuGet.org</a> symbol packages (<em>.snupkg</em>) feed, respectively.</p><p>When working in an enterprise scenario, we don’t usually have either of those mechanism available for our internal libraries: symbols servers have never been popular and are tricky to setup. On the other hand, while <em>snupkg</em> are the standard for modern .NET libraries, they are not supported by the most popular software used to host internal package feeds, like <a href="https://jfrog.com/artifactory/">JFrog Artifactory</a> or <a href="https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-nuget-registry">GitHub Packages registry</a>. For this reason, the best approach is to include the PDBs as part of our actual library NuGet package.</p><h3>Including PDBs in a NuGet package</h3><p>The common solution to provide debug symbols for private packages used to be to include the PDBs in the NuGet packages alongside the dll.<br>For example, in early versions of .NET Core you could add a, admittedly quite hard to remember, line to your csproj to achieve this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/79c91aae9d443230a648d9745a9b0912/href">https://medium.com/media/79c91aae9d443230a648d9745a9b0912/href</a></iframe><p>Unfortunately, with changes in .NET Core 3.0 to the project system, <a href="https://github.com/dotnet/sdk/issues/1458">it is no longer possible to consume the PDB files included in NuGet packages</a>.</p><p>Luckly, we can rely on another mechanism that, while deeply different in nature, allow us to achieve the same result: embedding the PDB inside the DLL. It has a few drawbacks, like having larger packages and not being able to easily strip out PDBs from deployables, however these problems are rarely relevant for internal libraries, especially when used in internal microservices and APIs.</p><p>In current .NET versions, this is easily achievable by adding the &lt;DebugType&gt;embedded&lt;/DebugType&gt; property to your library csproj, which is much easier to remember than the previous technique and one day it could become the <a href="https://github.com/dotnet/sdk/issues/2679">default behaviour</a>.</p><p>There is a final aspect that we need to mention when talking about including a PDB: making sure it is deterministic. While .NET builds have become deterministic by default in .NET, ensuring the same DLL is produced no matter where it is built, to have PDBs with normalized paths to our source file, we also need to add the &lt;ContinuousIntegrationBuild&gt;true&lt;/ContinuousIntegrationBuild&gt; property, usually with a conditional to only apply the normalization when building in CI, but we will look into an easy way to achieve all these later on.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/27d1b417e0d9b9096cda84d2e51f012a/href">https://medium.com/media/27d1b417e0d9b9096cda84d2e51f012a/href</a></iframe><h3>Getting the source code</h3><p>Now that our library contains the required metadata to map the DLL to the source code, we need to be able to easily retrieve it. Nowadays we all use version control systems, so the easier way is to retrieve it directly from it. The .NET platform provides <a href="https://github.com/dotnet/sourcelink"><em>Source Link</em></a>, a nifty tool integrated into Visual Studio, which provides the ability to automatically include metadata into NuGet packages that point to the source code hosted in our version control hosting platform of choice from which Visual Studio can then automatically download it when stepping into the code. Thanks to the support to multiple authentication mechanism as well as on-premises solutions like <em>GitHub Enterprise</em>, this works well in the enterprise scenario, allowing us to leverage the same tool as the opensource community without extra configuration, as easy as adding a package reference and a couple of project properties. But can it be even easier to integrate it?</p><h3>Putting it all together</h3><p>As we had seen, by putting a few pieces together and using the right configuration, we can provide a brilliant debugging experience for our internal libraries which has nothing to envy to opensource or Microsoft libraries. Of course, we would not want to have to replicate a bunch of settings across every project and, while creating shared props or targets is an option, there is no need for it.</p><p>In fact, there is a .NET Foundation’s package called <a href="https://github.com/dotnet/reproducible-builds">D<em>otNet.ReproducibleBuilds</em></a> that takes care of all these steps necessary to get Source Link fully working and CI builds deterministic, including logic to <a href="https://github.com/dotnet/reproducible-builds/blob/956ec68ee3572d3c29e62c7d37aaf076647ab8c8/src/DotNet.ReproducibleBuilds/DotNet.ReproducibleBuilds.props#L15-L76">detect your correct CI server</a>. All you need to do is to add this package either to your csproj, or more convenient if you have multiple projects published as library in the same solution, to your Directory.Build.props` file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1456ace46a46798b7bc977bd17abd96b/href">https://medium.com/media/1456ace46a46798b7bc977bd17abd96b/href</a></iframe><h3>Investigating Source Link issues</h3><p>If you are having issues in navigating to the source code, you should check the logs in <em>Navigate to External Sources</em> in the Visual Studio’s<em> Output View</em>.<br>Also make sure you have <em>Enable Source Link support </em>enabled and consider enabling the integration with <em>Git Credential Manager</em> if you experience authentication issues.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LcdbZIxvjxxDhYzVUz5FqA.png" /><figcaption>Output from Navigate to External Sources</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/743/1*MNoA-i5W6TVUspTJcdSa1g.png" /><figcaption>Source Link options in Visual Studio 2022</figcaption></figure><p>Furthermore, don’t forget that to be able to step into libraries, apart from thrown exceptions, you need to disable <em>Just My Code</em> and set the <em>Symbols loading</em> rules appropriately.</p><h3>Extra goodies</h3><p>In recent versions of Visual Studio 2022 there is now the ability to use <em>“Go To Definition”</em> on references of our internal libraries and magically go to the source code relying on the same mechanism previously described used during debugging. While the feature is still not perfect, it works in most scenarios, and it keeps getting refined with each feature update!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/538/1*MHbPskGybBThcDBqBlYEuw.png" /><figcaption>Visual Studio 2022 — Go To Definition</figcaption></figure><h3>So easy!</h3><p>Thanks to the ability of the IDE to automatically retrieve debug symbols and the source code, allowing both to <em>“step in”</em> during debug as well as using <em>“Go To Definition”</em> when navigating the codebase, working with private libraries has never been so easy!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=84dcb0804b5e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/newday-technology/easily-making-internal-libraries-debuggable-in-net-84dcb0804b5e">Easily making internal libraries debuggable in .NET</a> was originally published in <a href="https://medium.com/newday-technology">NewDay Technology</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[API’s from Dev to Production — Part 4]]></title>
            <link>https://medium.com/newday-technology/apis-from-dev-to-production-part-4-e423abf4b777?source=rss----15fa3c1fe40f---4</link>
            <guid isPermaLink="false">https://medium.com/p/e423abf4b777</guid>
            <category><![CDATA[github]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[dotnet]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[csharp]]></category>
            <dc:creator><![CDATA[Pete King]]></dc:creator>
            <pubDate>Mon, 08 Mar 2021 12:15:25 GMT</pubDate>
            <atom:updated>2021-03-08T16:55:16.866Z</atom:updated>
            <content:encoded><![CDATA[<h3>API’s from Dev to Production — Part 4</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*JvDGqlE3MH6OB1hBNVUh2Q.png" /></figure><p>Welcome to Part 4 of this blog series that will go from the most basic example of a .net 5 webapi in C#, and the journey from development to production with a <a href="https://dev.to/newday-technology/shift-left-engineering-4fpp"><strong>shift-left</strong></a> mindset. We will use <strong>Azure</strong>, <strong>Docker</strong>, <strong>GitHub</strong>, <strong>GitHub Actions</strong> for CI/C-Deployment and Infrastructure as Code using <strong>Pulumi</strong>.</p><p>In this post we will be looking at:</p><ul><li>Add container scanning to our GitHub Action workflow</li><li>Resolve security vulnerabilities</li></ul><h3>TL;DR</h3><p>We add the <strong>Azure Container</strong> Scan GitHub Action to our actions’ workflow file, before pushing the container image to our registry. Add a group and user to our Dockerfile and use the USER command to specify the user for the process to run; ensuring our copied files can be accessed by this user. The security attack surface is reduced by running as non-root, and this is raised in CIS; the linting provided by <strong>Dockle</strong>. We resolved some slightly older CVE’s as examples; these can be raised by <strong>Trivy </strong>and can be allowed through or not based on configuration. Both Trivy and Dockle are wrapped by the Azure Container Scan GitHub Action.</p><p><a href="https://github.com/peteking/Samples.WeatherForecast-Part-4">peteking/Samples.WeatherForecast-Part-4</a></p><h3>Introduction</h3><p>In Part 3 we were able to get into GitHub Actions and build and push our Docker image to the GitHub Container registry. This is a great start, we are producing a Docker image in CI and it’s a consistent image, however, <strong>what about vulnerabilities</strong>?</p><h3>Requirements</h3><p>We will be picking-up where we left off in <a href="https://dev.to/newday-technology/api-s-from-dev-to-production-part-3-7dn">Part 3</a>, which means you’ll need the end-result from <a href="https://github.com/peteking/Samples.WeatherForecast-Part-3">GitHub Repo — Part 3</a> to start with.</p><p>If you have followed this series all the way through, and I would encourage you to do so, but it isn’t necessary if previous posts are knowledge to you already.</p><h3>Vulnerabilities</h3><p>A software vulnerability is a glitch, flaw, or weakness that is present in software or in an Operating System. CVE (<strong>C</strong>ommon <strong>V</strong>ulnerabilities and <strong>E</strong>xposures), contains a <a href="https://cve.mitre.org/cve/">list</a> of records each containing an identification number, a description, and at least one public reference — for publicly known cybersecurity vulnerabilities.</p><p>CVE Records are used in numerous cybersecurity <a href="https://cve.mitre.org/about/faqs.html#what_types_of_products_use_cve">products and services</a> from around the world, including the U.S. National Vulnerability Database (<a href="https://cve.mitre.org/about/cve_and_nvd_relationship.html">NVD</a>).</p><p>There are many open source and commercial tools specifically designed for CI purposes; to be used before pushing a Docker image to a container registry. This can ensure any CVE’s of certain thresholds can be caught a build time.</p><blockquote>Commercial tools can also scan containers at runtime and apply custom mediating actions.</blockquote><h3>CIS (Center for Internet Security)</h3><p>CIS is a community of cybersecurity experts, who have developed CIS Benchmarks: more than 100 configuration guidelines across 25+ vendor product families to safeguard systems against today’s evolving cyber threats.</p><blockquote>CIS also produced a list of hardened images — <a href="https://www.cisecurity.org/cis-hardened-image-list/">https://www.cisecurity.org/cis-hardened-image-list/</a></blockquote><h3>Why is this important?</h3><p>It’s important because the software we design, build, and ship needs to be secure, we want to ensure safety of our end users’ data and be responsible. We <strong>must </strong>take security seriously and both CVE and CIS provide a trusted source of information.</p><p>The open source community has done an amazing job of utilising the information and provided fantastic tooling we can all take advantage of.</p><p><em>To continue reading this post, please visit our blog </em><a href="https://dev.to/newday-technology/api-s-from-dev-to-production-part-4-49g8"><em>here</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e423abf4b777" width="1" height="1" alt=""><hr><p><a href="https://medium.com/newday-technology/apis-from-dev-to-production-part-4-e423abf4b777">API’s from Dev to Production — Part 4</a> was originally published in <a href="https://medium.com/newday-technology">NewDay Technology</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[API’s from Dev to Production — Part 3]]></title>
            <link>https://medium.com/newday-technology/apis-from-dev-to-production-part-3-6fc2cd0b3b00?source=rss----15fa3c1fe40f---4</link>
            <guid isPermaLink="false">https://medium.com/p/6fc2cd0b3b00</guid>
            <category><![CDATA[github]]></category>
            <category><![CDATA[dotnet]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[csharp]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Pete King]]></dc:creator>
            <pubDate>Mon, 01 Mar 2021 15:16:39 GMT</pubDate>
            <atom:updated>2021-03-08T12:19:08.243Z</atom:updated>
            <content:encoded><![CDATA[<h3>API’s from Dev to Production — Part 3</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*JvDGqlE3MH6OB1hBNVUh2Q.png" /></figure><p>Welcome to Part 3 of this blog series that will go from the most basic example of a .net 5 webapi in C#, and the journey from development to production with a <a href="https://dev.to/newday-technology/shift-left-engineering-4fpp"><strong>shift-left</strong></a> mindset. We will use <strong>Azure</strong>, <strong>Docker</strong>, <strong>GitHub</strong>, <strong>GitHub Actions</strong> for CI/C-Deployment and Infrastructure as Code using <strong>Pulumi</strong>.</p><p>In this post we will be looking at:</p><ul><li>GitHub Actions:</li><li>Build the docker image</li><li>Publish the docker image to the GitHub Container Registry</li></ul><h3>TL;DR</h3><p>Instead of building locally like we did previously, we utilised GitHub Actions and the GitHub Container Registry to store our Docker image. GitHub Actions workflow is basic YAML, and we used a few actions to achieve what we needed. We checked-out the repository, docker build, logged into our GitHub Container Registry and executed a docker push command. We used a Personal Access token and stored it in GitHub secrets to use in our workflow, and finally, we pulled down our public image from the GitHub Container Registry and tested locally using Postman.</p><p><a href="https://github.com/peteking/Samples.WeatherForecast-Part-3">peteking/Samples.WeatherForecast-Part-3</a></p><h3>Requirements</h3><p>We will be picking-up where we left off in <a href="https://medium.com/newday-technology/apis-from-dev-to-production-part-2-f7d91a4180f">Part 2</a>, which means you’ll need the end-result from <a href="https://github.com/peteking/Samples.WeatherForecast-Part-2">GitHub Repo from — Part 2</a> to start with.</p><h3>What are GitHub Actions?</h3><p>GitHub Actions makes it easy to automate all kinds of software workflows, right inside GitHub. You can build, test, and deploy your code and more. Workflows can be triggered off many GitHub events like push, issue creation and more. There is support for Linux, macOS, Windows, ARM and of course containers Even matrix builds — so you can build the same software across multiple OS’s. There are live logs, secret store and more, plus the UX is rather nice too! All of this is driven by YAML files, nice and neat, and stored under source control management.</p><p>There is also GitHub Packages which has various package management providers like npm, nuget and more. For containers, there is a new GitHub Container Registry, so images no longer need to be stored in GitHub Packages but there is a real container registry — We will use this in this blog post :D</p><p><em>To continue reading this post, please visit our blog </em><a href="https://dev.to/newday-technology/api-s-from-dev-to-production-part-3-7dn"><em>here</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6fc2cd0b3b00" width="1" height="1" alt=""><hr><p><a href="https://medium.com/newday-technology/apis-from-dev-to-production-part-3-6fc2cd0b3b00">API’s from Dev to Production — Part 3</a> was originally published in <a href="https://medium.com/newday-technology">NewDay Technology</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[API’s from Dev to Production — Part 2]]></title>
            <link>https://medium.com/newday-technology/apis-from-dev-to-production-part-2-f7d91a4180f?source=rss----15fa3c1fe40f---4</link>
            <guid isPermaLink="false">https://medium.com/p/f7d91a4180f</guid>
            <category><![CDATA[csharp]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[dotnet]]></category>
            <category><![CDATA[github]]></category>
            <dc:creator><![CDATA[Pete King]]></dc:creator>
            <pubDate>Fri, 19 Feb 2021 12:09:34 GMT</pubDate>
            <atom:updated>2021-03-08T12:23:56.491Z</atom:updated>
            <content:encoded><![CDATA[<h3>API’s from Dev to Production — Part 2</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*JvDGqlE3MH6OB1hBNVUh2Q.png" /></figure><p>Welcome to Part 2 of this blog series that will go from the most basic example of a .net 5 webapi in C#, and the journey from development to production with a <a href="https://medium.com/newday-technology/shift-left-engineering-175a4bcc89ce"><strong>shift-left</strong></a> mindset. We will use <strong>Azure</strong>, <strong>Docker</strong>, , <strong>GitHub Actions</strong> for CI/C-Deployment and Infrastructure as Code using <strong>Pulumi</strong>.</p><p>In this post we will be looking at:</p><ul><li>Optimising the Docker image size</li></ul><h3>TL;DR</h3><p>We managed to optimise the resulting Docker image from 210MB down to 109MB; this 109MB could be even smaller if you were happy not to use AOT (ahead of time compiling) with .net — you can get this down to ~69MB. We did this by using Alpine Linux — a small, lightweight Linux distribution, using the .net 5 SDK to restore, build, publish, and then we used the minimal .net runtime dependencies image (which is only 9MB!). We took advantage of self-contained, PublishReadyToRun and PublishTrimmed.</p><pre>--self-contained=true \ -p:PublishReadyToRun=true \ -p:PublishTrimmed=true</pre><p><a href="https://github.com/peteking/Samples.WeatherForecast-Part-2">peteking/Samples.WeatherForecast-Part-2</a></p><h3>Requirements</h3><p>We will be picking-up where we left off in <a href="https://medium.com/newday-technology/apis-from-dev-to-production-d9ba4e214fe2"><strong>Part 1</strong></a>, which means you’ll <strong>need the end-result from </strong><a href="https://medium.com/newday-technology/apis-from-dev-to-production-d9ba4e214fe2"><strong>Part 1</strong></a><strong> to start with</strong>.</p><p>We have the same requirements as last time, but to save you some time, I’ve put them below anyway :)</p><ul><li>Git — <a href="https://git-scm.com/downloads">https://git-scm.com/downloads</a></li><li>Visual Studio Code — <a href="https://code.visualstudio.com/download">https://code.visualstudio.com/download</a></li><li>Docker — <a href="https://www.docker.com/products/docker-desktop">https://www.docker.com/products/docker-desktop</a></li><li>.net 5 — <a href="https://dotnet.microsoft.com/download/dotnet/5.0">https://dotnet.microsoft.com/download/dotnet/5.0</a></li><li>WSL 2 (Windows 10 only) — <a href="https://docs.microsoft.com/en-us/windows/wsl/install-win10">https://docs.microsoft.com/en-us/windows/wsl/install-win10</a></li></ul><blockquote><strong>I’m using Windows 10, for other OS’s like MacOS and Linux, there will be small differences that are not covered here.</strong></blockquote><h4>VS code extensions</h4><ul><li>C# — <a href="https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csharp">https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csharp</a></li><li>.gitignore Generator — <a href="https://marketplace.visualstudio.com/items?itemName=piotrpalarz.vscode-gitignore-generator">https://marketplace.visualstudio.com/items?itemName=piotrpalarz.vscode-gitignore-generator</a></li><li>Docker — <a href="https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-docker">https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-docker</a></li></ul><h3>Dockerfile optimisation</h3><p>Dockerfiles works in distinct layers and each of the following commands creates a new layer.</p><p>In relation to a previous file which is below.</p><p>FROM creates a layer from the mcr.microsoft.com/dotnet/aspnet:5.0 Docker image.</p><p>COPY adds files from your source to destination directory.</p><p>RUN in our case will restore, build and publish using dotnet.</p><pre>FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base<br>WORKDIR /app<br>EXPOSE 80<br><br>FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build<br>WORKDIR /app<br>COPY . .<br><br>WORKDIR /app/src/Samples.WeatherForecast.Api<br><br>RUN dotnet restore &quot;Samples.WeatherForecast.Api.csproj&quot;<br><br>RUN dotnet build &quot;Samples.WeatherForecast.Api.csproj&quot; -c Release -o /app/build --no-restore<br><br>FROM build AS publish<br>RUN dotnet publish &quot;Samples.WeatherForecast.Api.csproj&quot; -c Release -o /app/publish<br><br>FROM base AS final<br>WORKDIR /app<br>COPY --from=publish /app/publish .<br>ENTRYPOINT [&quot;dotnet&quot;, &quot;Samples.WeatherForecast.Api.dll&quot;]</pre><h3>Docker build cache</h3><p>When building an image, Docker steps through the instructions in your Dockerfile, executing each in the order specified. As each instruction is examined, Docker looks for an existing image in its cache that it can reuse, rather than creating a new (duplicate) image.</p><p>If you do not want to use the cache at all, you can use the --no-cache=true option on the docker build command. However, if you do let Docker use its cache, it is important to understand when it can, and cannot, find a matching image. The basic rules that Docker follows are outlined below:</p><ul><li>Starting with a parent image that is already in the cache, the next instruction is compared against all child images derived from that base image to see if one of them was built using the exact same instruction. If not, the cache is invalidated.</li><li>In most cases, simply comparing the instruction in the Dockerfile with one of the child images is sufficient. However, certain instructions require more examination and explanation.</li><li>For the ADD and COPY instructions, the contents of the file(s) in the image are examined and a checksum is calculated for each file. The last-modified and last-accessed times of the file(s) are not considered in these checksums. During the cache lookup, the checksum is compared against the checksum in the existing images. If anything has changed in the file(s), such as the contents and metadata, then the cache is invalidated.</li><li>Aside from the ADD and COPY commands, cache checking does not look at the files in the container to determine a cache match. For example, when processing a RUN apt-get -y update command the files updated in the container are not examined to determine if a cache hit exists. In that case just the command string itself is used to find a match.</li></ul><p>Once the cache is invalidated, all subsequent Dockerfile commands generate new images and the cache is not used.</p><blockquote><em>It’s preferable to use COPY instead of ADD.</em></blockquote><blockquote><em>This is simply because the term </em><em>COPY is more transparent in terms of what it is doing, whereas </em><em>ADD supports features like local-only tar extraction and remote URL support that are not immediately obvious.</em></blockquote><p>See references <strong>[1]</strong></p><h3>How can we optimise?</h3><p>For starters, we can use a different base image, a different OS (Operating System), one of the smallest is <strong>Alpine Linux</strong>. Alpine is great, it’s small, is not bloated with anything extra, even curl isn&#39;t installed!</p><p>With .net, the question becomes — How do I know what’s available?</p><p>Well, <a href="https://hub.docker.com/">DockerHub</a> is your best friend, it has everything you need to find out about the image that companies and individuals have published.</p><p>Let’s take a look at .net 5 from Microsoft.</p><p>You can see there are over <strong>1 billion downloads</strong> overall!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nTyXYkCTR2_dmKD0XnWRHA.png" /></figure><h4>The build</h4><p>What do we actually need to build? When you think about it, you need the SDK (Software Development Kit) in order to build your projects.</p><p>If you navigate to ‘dotnet/sdk’ you’ll see a page with all the relevant information you need about the SDK.</p><p>From there you can see the various versions (tags) are available, we want Alpine. There are various tags there, but they all equate to the same Dockerfile; therefore, the same image. For us, using the tag, ‘5.0-alpine’ is enough.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jxMA1Lf-zvrpUq6jrEggvQ.png" /></figure><blockquote><em>Always specify a version</em></blockquote><blockquote><em>It’s best practice to pin a version, it is then a known thing — You don’t want to be caught out by using ‘latest’ tag. i.e. if you build later on, and the version with the ‘latest’ tag has changed, but you haven’t tested it, you may find some issues.</em></blockquote><h4>Rewrite the Dockerfile</h4><p>Let’s start by rewriting our Dockerfile, don&#39;t worry, it will still only be about 20 lines of code.</p><pre>ARG VERSION=5.0-alpine</pre><pre>FROM mcr.microsoft.com/dotnet/sdk:${VERSION} AS build<br>WORKDIR /app</pre><p>Here you can see a couple of things, we are using ARG to hold 5.0-alpine and we use that variable in the FROM statement with the dollar sign and curly braces ${ }</p><p>If you’re wondering what this FROM is and why we have more than one (even in our generated Dockerfile from <a href="https://medium.com/newday-technology/apis-from-dev-to-production-d9ba4e214fe2">Part 1</a>), this is known as a multi-stage build - We essentially take advantage of different base images to do certain things, and use another final image to ensure it is the most optimal it can be. For more information about multi-stage builds, please see, <a href="https://docs.docker.com/develop/develop-images/multistage-build/">Docker Docs - Multistage Build</a></p><h4>DotNet restore</h4><p>Next up is dotnet restore we want to restore because if that fails, there is certainly no point in going any further with the build. We will also optimise for the runtime too, because we are targeting x64 Linux, we can specify the -r or -runtime for more information about the options available for dotnet restore please see, <a href="https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-restore">Microsoft Docss - dotnet restore</a></p><p>Our Dockerfile now looks like:</p><pre># Copy and restore as distinct layers<br>COPY . .<br>WORKDIR /app/src/Samples.WeatherForecast.Api<br>RUN dotnet restore Samples.WeatherForecast.Api.csproj -r linux-musl-x64</pre><p>Here you can see a few more things, one the COPY command and two, the WORKDIR command. We copy everything from the source to our destination, hence the period . for the source and the period . for the destination. Next, the WORKDIR changes the current directory.</p><h4>DotNet duild (publish)</h4><p>Now we move on to the build, or rather <em>publish</em>, we do this because <em>publish</em> will also build as well, but what we don’t want it to do is restore, so we use the option of --no-restore. I feel it is down to personal preference, you may want to do a dotnet build before a dotnet publish and then in addition specify --no-build, but I&#39;ll leave it up to you to decide. Here, I&#39;m going to go straight to publish.</p><pre>FROM build AS publish<br>RUN dotnet publish \<br>    -c Release \<br>    -o /out \<br>    -r linux-musl-x64 \<br>    --self-contained=true \<br>    -- no-restore \<br>    -p:PublishReadyToRun=true \<br>    -p:PublishTrimmed=true</pre><p>There are a few more dotnet publish options happening here.</p><p>-c defines the build configuration, in our case Release.</p><p>-o specifies the path for the output directory.</p><p>-r or -runtime specifies the given runtime, just like in dotnet restore</p><p>Please see the RID catalogue for more information. <a href="https://docs.microsoft.com/en-us/dotnet/core/rid-catalog">https://docs.microsoft.com/en-us/dotnet/core/rid-catalog</a></p><p>--self-contained publishes the .net runtime with the application so the runtime doesn&#39;t need to be installed in the image.</p><p>--no-restore doesn&#39;t execute an implicit restore when running the command.</p><p>-p:PublishReadyToRun=true compiles the apps assemblies as ReadyToRun (R2R) format. R2R is a form of ahead-of-time (AOT) compilation.</p><blockquote><strong>This will make our start-up time a great deal faster, but it comes at the cost of size</strong><em>.</em></blockquote><p>-p:PublishTrimmed=true trims unused libraries to reduce the deployment size of an app when publishing a self-contained executable.</p><blockquote><strong>Take great care in using this option</strong><em><br> For more information, please see, </em><a href="https://docs.microsoft.com/en-us/dotnet/core/deploying/trim-self-contained"><em>Microsoft Docs — dotnet trim-self-contained</em></a></blockquote><blockquote><strong><em>What is linux-musl-x64 ?</em></strong></blockquote><blockquote><em>Lightweight distributions using musl like Alpine Linux</em></blockquote><p>See references <strong>[2]</strong></p><h3>The final stage</h3><p>With the new commands we have recently used, we can use the `FROM` to indicate a different base image. This is the most important part to take note around Docker multi-stage builds.</p><p>We don’t want the SDK in the final runtime image, for one reason, it’s too large, but most importantly we don’t actually even need it!</p><p>We have compiled AOT (Ahead-of-time) and including the .net runtime as part of our app.</p><p>We go to Docker Hub again and we can find the runtime dependency images. It’s name is mcr.microsoft.com/dotnet/runtime-deps and it has a bunch of tags like we&#39;ve seen previously. So we&#39;ll attach ${VERSION} to it.</p><p>For more information, please see, <a href="https://hub.docker.com/_/microsoft-dotnet-runtime-deps/">Microsoft Docs — dotnet Runtime Dependencies</a></p><pre># Final stage/image<br>FROM mcr.microsoft.com/dotnet/runtime-deps:${VERSION}<br>WORKDIR /app<br>COPY --from=publish /out .</pre><p>We set the WORKDIR again and COPY the output from publish, and if you noted the directory with the -o option, this is where we specified the output from the dotnet publish command.</p><p>Finally, we can expose the port and specify an entry point.</p><pre>EXPOSE 8080<br>ENTRYPOINT [&quot;./Samples.WeatherForecast.Api&quot;]</pre><blockquote><em>However, you may have clocked it, but if you haven’t, our </em><em>ENTRYPOINT looks a little different compared to what it was in </em><a href="https://medium.com/newday-technology/apis-from-dev-to-production-d9ba4e214fe2"><em>Part 1</em></a><em>. This is because we are taking advantage of - </em><em>p:PublishReadyToRun=true.</em></blockquote><h3>Full Dockerfile</h3><pre>ARG VERSION=5.0-alpine<br><br>FROM mcr.microsoft.com/dotnet/sdk:${VERSION} AS build<br>WORKDIR /app<br><br># Copy and restore as distinct layers<br>COPY . .<br>WORKDIR /app/src/Samples.WeatherForecast.Api<br>RUN dotnet restore Samples.WeatherForecast.Api.csproj -r linux-musl-x64<br><br>FROM build AS publish<br>RUN dotnet publish \<br>    -c Release \<br>    -o /out \<br>    -r linux-musl-x64 \<br>    --self-contained=true \<br>    -- no-restore \<br>    -p:PublishReadyToRun=true \<br>    -p:PublishTrimmed=true<br><br># Final stage/image<br>FROM mcr.microsoft.com/dotnet/runtime-deps:${VERSION}<br>WORKDIR /app<br>COPY --from=publish /out .<br><br>EXPOSE 8080<br>ENTRYPOINT [&quot;./Samples.WeatherForecast.Api&quot;]</pre><h3>Let’s build it</h3><p>Navigate to your repo root directory and execute the docker build command.</p><p>docker build -t samples.weatherforecast:v2 .</p><p>We have changed the tag so we can compare from <a href="https://medium.com/newday-technology/apis-from-dev-to-production-d9ba4e214fe2">Part 1</a>.</p><p>Now, execute a docker image ls to see your images.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e9JJxkTTgH9Yeh6-f3Wy2Q.png" /></figure><p>Notice the <strong>size</strong> different, we’ve been able to optimise the size from <strong>210MB</strong> down to <strong>109MB!</strong>; and this includes .</p><blockquote><em>With AOT, you do pay a size price, you need to determine if this size is worth paying for in terms of execution speed, or you’d rather an even smaller image size and the JIT compile.</em></blockquote><blockquote><em>If you prefer the image size is more important, simply remove the option and adjust your </em><em>ENTRYPOINT.</em></blockquote><blockquote><em>You end image size will be about </em><strong><em>69MB!</em></strong></blockquote><p><em>Image size is **not</em>* everything and does not equate to an increase in security hardening — However, it does help, the less bloat an base image has, i.e. less tooling etc. including in an image, the slightly less likely a hacker could take advantage of any vulnerabilities of those.*</p><p>You’ll also notice the <strong>TAG</strong>, and hopefully seeing this will really hit home about what it really is, and the concept of using latest can be misleading. You can see latest is 25 hours old, whereas v2 is about 1 hour, the tag can be anything, just because I’ve used the <em>term</em> latest, it doesn’t actually mean anything. In our case, the latest version is really the image with the v2 tag.</p><blockquote><em>It comes down to </em>good practice<em> around the image tag — Using latest should point to the latest production image, however, using </em>latest<em> is no longer </em><strong>good practice</strong><em>.</em></blockquote><h3>Let’s test it</h3><p>We should test the image to make sure it serves requests as we expect.</p><p>docker run -it --rm -p 8080:8080 samples-weatherforecast:v2</p><p>Don’t forget the tag change to v2.</p><p>Let’s use Postman again… It works!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TXlZJtbr7V30JZljAA_Fhg.png" /></figure><h3>What have we learned?</h3><p>We have learned about multi-stage builds in Docker, how the build cache works, and how to really optimise your final image. There are many different base images supporting different OS’s, Alpine, Buster, Ubuntu and more. This give engineers the ultimate flexibility to chooser what is right for their solution. For this example, we’ve opted for something very minimal and lightweight.</p><p>If you’re new to Docker, I recommend that you spend further time to understand more docker commands that are available in the Dockerfile.</p><h3>Up next</h3><p><strong>Part 3</strong> in this series will be about:</p><ul><li>GitHub Actions — Build the docker image</li><li>GitHub Actions — Publish the docker image to the GitHub Container Registry</li></ul><h3>More information</h3><ul><li><a href="https://www.azure.com/">https://www.azure.com</a></li><li><a href="https://dotnet.microsoft.com/">https://dotnet.microsoft.com/</a></li><li><a href="https://www.github.com/">https://www.github.com</a></li><li><a href="https://www.docker.com/">https://www.docker.com</a></li><li><a href="https://www.pulumi.com/">https://www.pulumi.com</a></li></ul><h3>References</h3><p><strong>[1]</strong> — <a href="https://docs.docker.com/develop/develop-images/dockerfile_best-practices/">https://docs.docker.com/develop/develop-images/dockerfile_best-practices/</a></p><p><strong>[2]</strong> — <a href="https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-publish">https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-publish</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f7d91a4180f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/newday-technology/apis-from-dev-to-production-part-2-f7d91a4180f">API’s from Dev to Production — Part 2</a> was originally published in <a href="https://medium.com/newday-technology">NewDay Technology</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Interview Techniques]]></title>
            <link>https://medium.com/newday-technology/interview-techniques-968a37644081?source=rss----15fa3c1fe40f---4</link>
            <guid isPermaLink="false">https://medium.com/p/968a37644081</guid>
            <category><![CDATA[career-advice]]></category>
            <category><![CDATA[beginner]]></category>
            <category><![CDATA[interview-tips]]></category>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[job-interview]]></category>
            <dc:creator><![CDATA[Pete King]]></dc:creator>
            <pubDate>Fri, 19 Feb 2021 11:41:33 GMT</pubDate>
            <atom:updated>2021-02-19T11:41:33.225Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Eoh3xUBGOvrb_Ouj4mxNaA.jpeg" /></figure><h3>Introduction</h3><p>Interview techniques, it’s a subject that we don’t like to really talk about, but in reality we should, it is a skill many of us need to learn; not everyone is born with it.</p><p>We will go through the what, and how of the usual, famous last stage interview, the <em>behavioural / competency-based</em> interview.</p><h3>Behavioural, competency-based interview</h3><h4>What is it?</h4><p>Competency-based interviews are based on the premise that past behaviour is the best predictor of future performance. During an interview, the interviewer will ask questions where you will be required to answer based on your <em>previous experience</em>.</p><blockquote>Do not<em> talk about what you </em><strong><em>would do</em></strong><em>, it’s more geared towards what you </em><strong><em>have done</em></strong><em>, what </em><strong><em>you have experienced</em></strong><em>.</em></blockquote><p>These style of questions could include challenges you have faced and how you have handled them, opportunities you spotted and taken advantage of, or successes and failures and what you have learned from them.</p><blockquote><em>It’s important to be honest, even in failure, showing humility, recognising those failures, and how you’d react to such a situation in the future is something you can lean on; turning a </em>negative into a positive<em>.</em></blockquote><h4>How?</h4><p>First of all, acknowledge the fact you need to prepare, prepare, prepare!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/0*YNboCN_BilIKl6Rn.gif" /></figure><p>Remember, the competency-based interviewer are seeking answers that are based on your past experience in certain situations, and you need to have a detailed answer.</p><p>One method you should consider utilising is known as, <strong>STAR</strong>.</p><ul><li><strong>S</strong>ituation — Describe the context within which you performed a job or faced a challenge at work.</li><li><strong>T</strong>ask — Describe your responsibility in that situation.</li><li><strong>A</strong>ction — Describe how you completed the task or deal with the challenge.</li><li><strong>R</strong>esult — Explain the outcome/result. It may be helpful to emphasize what you accomplished, or what you learned.</li></ul><p>It may feel quite repetitive as you answer the ongoing questions from the interviewer, but it’s a good method to keep focused, on-track, and to the point; being concise in this style of interview is a good thing.</p><p>When a question is asked, you can structure your response something like the following ( <em>by no means this is the only way of course</em>):</p><blockquote><em>“The </em><strong><em>S</em></strong><em>ituation I found myself in was </em><strong><em>X</em></strong><em>, and because of this situation, I was responsible for </em><strong><em>X</em></strong><em>; given my objective of </em><strong><em>O</em></strong><em>. The </em><strong><em>A</em></strong><em>ctions I took for these where, </em><strong><em>A</em></strong><em>, </em><strong><em>B</em></strong><em>, and </em><strong><em>C</em></strong><em>. After taking these decisive actions, the end </em><strong><em>R</em></strong><em>esult was </em><strong><em>Y</em></strong><em> (and I learned </em><strong><em>Z</em></strong><em>).</em></blockquote><p>You can of course mix it up and use different words than I to keep it slightly less repetitive, more <em>your own style</em> and a <strong>lot less rigid</strong>, but please ensure you use the STAR method in <em>sequential order</em>.</p><p>The example phrases I give is small, but remember you are telling a <strong>story</strong>, make your interviewer feel that way, express the actions you took, and ensure there is a connection to the situation you’ve described in <strong>just enough detail</strong>.</p><p>If you can attribute any metric in your story, make sure you highlight it in your situation and in the end result, again so there is a connection between the two.</p><blockquote><em>Your goal is to help your interviewer understand the situational context all the way through to the end result.</em></blockquote><p>Once you understand this method, it’s time to put in a real effort to prepare yourself.</p><p>Open up your favourite word processor etc. and find a bunch of sample questions, and go through and answer each one using the STAR method.</p><p>Below is a small list, but there are many you can Google for, and over time, you can build your back catalogue:</p><ul><li>Tell me about an occasion when you provided exceptional service to a client or stakeholder.</li><li>Tell me about a time when you failed to deliver.</li><li>Give me an example of a time when you successfully persuaded others to do something.</li><li>Describe a situation where you have identified the need for change in a business.</li></ul><h4>Why do this?</h4><ul><li>This will help reinforce the STAR method</li><li>Provide yourself a good sum of situations you’ve been in in the past. It’s important to have a back catalogue if you will, of <em>ready</em> situations you can draw upon.</li></ul><p>You of course cannot prepare for everything, which is why putting in this effort now will give you the tools at your disposal to be more agile on day.</p><p>Be prepared for follow-up questions, some, but not all questions, the interviewer may dive further into a situation you have described, this is just a warning, and another thing to prepare for. It’s hard, because you may not remember further information about that particular situation. Be honest with the interviewer if that is the case; otherwise, describe another thin layer of detail that you believe will satisfy the follow-up question.</p><h3>Final thoughts</h3><p>I cannot stress enough that preparation is quite necessary, if however, you are sitting many interviews, you <em>may</em> not need to prepare as much each time. This is where your previous preparation becomes a <em>valuable asset</em>.</p><blockquote><em>Before each competency interview, scan through your prep-material the night before and/or just before the interview.</em></blockquote><p>Utilise the <strong>STAR</strong> method, yes, it’s repetitive (I keep saying that :P), I know, but interviews for a lot of people can be stressful, by utilising a method that you can follow each time can really relieve a little bit of stress.</p><blockquote><em>Your back catalogue will prove useful for years to come, you can refer back to your content and it will help you recall situations that occurred in previous job roles you’ve held.</em></blockquote><p>Now, go on, prepare yourself, you can do it!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/0*WnOTlPLnVpaDu6EJ.gif" /></figure><h3>Vacancies at NewDay</h3><p>For open vacancies, please visit, <a href="https://www.newday.co.uk/working-at-newday/">Working at NewDay</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=968a37644081" width="1" height="1" alt=""><hr><p><a href="https://medium.com/newday-technology/interview-techniques-968a37644081">Interview Techniques</a> was originally published in <a href="https://medium.com/newday-technology">NewDay Technology</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[API’s from Dev to Production — Part 1]]></title>
            <link>https://medium.com/newday-technology/apis-from-dev-to-production-d9ba4e214fe2?source=rss----15fa3c1fe40f---4</link>
            <guid isPermaLink="false">https://medium.com/p/d9ba4e214fe2</guid>
            <category><![CDATA[github]]></category>
            <category><![CDATA[csharp]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[dotnet]]></category>
            <dc:creator><![CDATA[Pete King]]></dc:creator>
            <pubDate>Fri, 12 Feb 2021 13:42:56 GMT</pubDate>
            <atom:updated>2021-03-08T12:24:25.069Z</atom:updated>
            <content:encoded><![CDATA[<h3>API’s from Dev to Production — Part 1</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*JvDGqlE3MH6OB1hBNVUh2Q.png" /></figure><p>Welcome to a blog post series that will go from the most basic example of a .net 5 webapi in C#, and the journey from development to production with a <a href="https://medium.com/newday-technology/shift-left-engineering-175a4bcc89ce"><strong>shift-left</strong></a> mindset. We will use <strong>Azure</strong>, <strong>Docker</strong>, , <strong>GitHub Actions</strong> for CI/C-Deployment and Infrastructure as Code using <strong>Pulumi</strong>.</p><blockquote><em>It will be a long multi-part series covering pretty much everything… I hope!</em></blockquote><p>Our goal is to have an API that follows modern practices, including everything as code with the shift-left philosophy, inclusive of testing, security and infrastructure; in order to facilitate the ability to have an increased level of autonomy as an engineering team.</p><p>We will host our services in Microsoft Azure using PaaS services, now you may think how? Surely we need Kubernetes, well the answer is no. There are other options that provide a good middle-ground before going into full-blown Kubernetes. The AppService in Azure supports containers (and there are other products too; such as ACI). This is a fantastic product, those of you who are experienced with the “standard” AppService will know the benefits it provides such as SSL, scaling and much, much more. If you couple this with the benefits of containers, it becomes a good stepping stone into containerised workloads; before taking the leap into Kubernetes such as AKS (Azure Kubernetes Service).</p><blockquote><strong>This is a practical hands-on journey from Dev to Production.</strong></blockquote><h3>TL;DR</h3><p>Visual Studio Code is great to use as an editor and take advantage of various extensions to make working with Docker and more much easier. We use dotnet new to create our C# project, generate our Dockerfile, modify it just a little bit, build, run and test to ensure it works. We learn some basic commands of the dotnet CLI and Docker CLI.</p><p><a href="https://github.com/peteking/Samples.WeatherForecast-Part-1">peteking/Samples.WeatherForecast-Part-1</a></p><h3>Why Docker?</h3><h4>Consistent and Isolated Environment</h4><p>Using containers developers can create predictable environments that are isolated from other apps. Regardless of where the app is deployed, everything remains consistent and this leads to massive productivity: less time debugging, and more time launching fresh features and functionality for users.</p><h4>Cost-effectiveness with Fast Deployment</h4><p>Docker-powered containers are known for decreasing deployment time to seconds. That’s an impressive feat by any standard. Traditionally, things like provisioning, getting the hardware up and running would take days or more. In addition, you faced massive overheads and extra work. When each process is put into a container, it can be shared with new apps. The process of deployment becomes swift and you are essentially ready to go.</p><h4>Mobility — Ability to Run Anywhere</h4><p>Docker images are free of environmental limitations, and that makes any deployment consistent, movable (portable), and scalable. Containers have the added benefit of running anywhere, providing it is targeted at the OS (Win, Mac OS, Linux, VMs, On-prem, in Public Cloud), which is a huge advantage for both development and deployment. The widespread popularity of the Docker image format for containers further helps. It has been adopted by leading cloud providers, including Amazon Web Services (AWS), Google Compute Platform (GCP), and Microsoft Azure. In addition, you have powerful orchestration systems such as Kubernetes, and products such as AWS ECS or Azure Container Instances are mighty useful in terms of mobility.</p><h4>Repeatability and Automation</h4><p>You are building code with repeatable infrastructure and config. This speeds up the development process tremendously. It must be pointed out that Docker images are often small. Consequently, you get fast delivery and, again, shorter deployment for new application containers. Another advantage is straightforward maintenance. When an application is containerized, it’s isolated from other apps running in the same system. In other words, apps don’t intermix and application maintenance significantly easier. It lends itself to being automated; the faster you repeat, the fewer mistakes you make, and the more you can focus on core value for a business or application.</p><h4>Test, Roll Back and Deploy</h4><p>As we said, Environments remain more consistent in Docker, from start to finish. Docker images are easily versioned, which makes them easy to roll back if you need to do so. If there is a problem with the current iteration of the image, just roll back to the older version. The whole process means you are creating the perfect environment for continuous integration and continuous deployment (CI/CD). Docker containers are set to retain all configs and dependencies internally. Now, you have a fast and easy way of checking for discrepancies.</p><h4>Flexibility</h4><p>If you need to perform an upgrade during a product’s release cycle, you can easily make the necessary changes to Docker containers, test them, and roll out new containers. This sort of flexibility is another key advantage of using Docker. Docker really allows you to build, test, and release images that can be deployed across multiple servers. Even if a new security patch is available, the process remains the same. You can apply the patch, test it, and release it to production. Additionally, Docker allows you to start and stop services, or apps rapidly, which is especially useful within the cloud environment.</p><h4>Collaboration, Modularity and Scaling</h4><p>The Docker method of containerization allows you to segment an application so you can refresh, clean up, repair without even taking down the entire app. Furthermore, with Docker you can build an architecture for applications comprising of small processes that communicate with each other via APIs. From there, developers share and collaborate, solving any potential issues quickly. At this stage, the development cycle is completed and all issues are resolved, with no massive overhaul needed — this is extremely cost-effective and time-saving.</p><p>See references <strong>[1]</strong></p><h3>Requirements</h3><ul><li>Git — <a href="https://git-scm.com/downloads">https://git-scm.com/downloads</a></li><li>Visual Studio Code — <a href="https://code.visualstudio.com/download">https://code.visualstudio.com/download</a></li><li>Docker — <a href="https://www.docker.com/products/docker-desktop">https://www.docker.com/products/docker-desktop</a></li><li>.net 5 — <a href="https://dotnet.microsoft.com/download/dotnet/5.0">https://dotnet.microsoft.com/download/dotnet/5.0</a></li><li>WSL 2 (Windows 10 only) — <a href="https://docs.microsoft.com/en-us/windows/wsl/install-win10">https://docs.microsoft.com/en-us/windows/wsl/install-win10</a></li></ul><blockquote><strong>I’m using Windows 10, for other OS’s like MacOS and Linux, there will be small differences that are not covered here.</strong></blockquote><h4>VS Code Extensions</h4><ol><li>Create Repository in Git → Samples.WeatherForecast</li><li>Create ‘src’ directory</li><li>Within ‘src’ execute:</li></ol><p>dotnet new webapi -n Samples.WeatherForecast.Api</p><p>At this point you should have a nice new .net 5 webapi.</p><blockquote><em>A nifty trick to launch VS Code in your terminal, simple type </em><em>code .</em></blockquote><blockquote><em>. refers to the the file path. In this case: current directory. You can specify alternative location, OR even simply write code at the terminal, which will open code with last workspace.</em></blockquote><p>If you are prompted to install the C# extension, be sure to select, ‘yes’ if prompted; this will create a .vscode folder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N2Be4IAOIgygHgDUBaORmg.png" /></figure><h3>GitIgnore</h3><p>I assume you probably haven’t created a .gitignore file yet, there is a really useful extension in VS Code called, &quot;.gitignore Generator&quot;. <strong><em>I recommend you install it</em></strong>.</p><blockquote><em>In VS Code — Command Palette — Windows (Ctrl+Shift+P) → .gitignore Generator.</em></blockquote><p>For this project, it’s best we select 4 items form the list:</p><ul><li>visualstudiocode</li><li>visualstudio</li><li>Dotnetcore</li><li>csharp</li></ul><p>Once you have your .gitignore file, it should look something like the below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LusoODEhHg6RP67z1Woj6Q.png" /></figure><h3>Dockerfile</h3><p>The good thing about the Docker extension is that it can do loads of things for you, it is a fantastic timesaver; a real Docker companion.</p><p>As a first step, we can generate our Dockerfile, and it can generate a docker-compose file too!</p><blockquote><em>VS Code — Command Palette — Windows (Ctrl+Shift+P) → Docker: Add Docker Files to Workspace</em></blockquote><p><em>Select </em><strong>.NET: ASP.NET Core</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l68T8DB0q6P6smt-nDRElQ.png" /></figure><p><em>Select</em> <strong>Linux</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5sZ828wJBc-DoYqDkrs6Qw.png" /></figure><p><em>Specify</em> <strong><em>port 80</em></strong>, lets deal with SSL later.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KWKuEVNpD0i7GLYa_AESjA.png" /></figure><p><em>Select</em> ‘<strong><em>yes</em></strong>’ to include docker-compose files, we’ll need them later.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bdvOrvWp4_jW_By75x1kJA.png" /></figure><p>At the end of this, you should have the following files all generated for you:</p><ol><li>Dockerfile</li><li>docker-compose.debug.yml</li><li>docker-compose.yml</li><li>.dockerignore</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D9VuptF4tj28hO2-EgIawA.png" /></figure><p>Now, if you carried this operation out in the src/Samples.WeatherForecast.API directory (like I did), these files would have been created there. However, we should move them...</p><blockquote><strong>It is best practice to have your Dockerfile etc. in the root directory of your repository</strong><em>.</em></blockquote><p>Let’s move them up into the root directory, if you open VS Code in the root directory, it should appear like below, and we should also move the ignore files; both .gitignore, and .dockerignore too!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YcjPD2iL8IpYSDE7a2aj6g.png" /></figure><p>Now, we have to modify the Dockerfile, why you ask? Well, given we moved it, plus it’s a little clunky. So let’s do a very quick change to make it just slightly better and then build the image.</p><p>You can see below the paths will no longer work for us.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GW8kWlw0sxWWtt7n3ju5aA.png" /></figure><p>We can simplify the file a little bit by using WORKDIR and make use of COPY . . to copy everything from source to destination.</p><p>In addition, if you look carefully, you can see it is doing a dotnet restore then a dotnet build, which means it&#39;s going to check to see if it needs to restore again. As part of this initial optimisation (and there will be more to come), we can make use of the --no-restore option.</p><p>Your final Dockerfile should appear as the below — Don’t worry if you’ve already spotted further optimisations at this point, there are many we will do in future posts in this series.</p><pre>FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base<br>WORKDIR /app<br>EXPOSE 80<br><br>FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build<br>WORKDIR /app<br>COPY . .<br><br>WORKDIR /app/src/Samples.WeatherForecast.Api<br><br>RUN dotnet restore &quot;Samples.WeatherForecast.Api.csproj&quot;<br><br>RUN dotnet build &quot;Samples.WeatherForecast.Api.csproj&quot; -c Release -o /app/build --no-restore<br><br>FROM build AS publish<br>RUN dotnet publish &quot;Samples.WeatherForecast.Api.csproj&quot; -c Release -o /app/publish<br><br>FROM base AS final<br>WORKDIR /app<br>COPY --from=publish /app/publish .<br>ENTRYPOINT [&quot;dotnet&quot;, &quot;Samples.WeatherForecast.Api.dll&quot;]</pre><p>At this point, I think we are good to go!</p><p>If you haven’t already done so, this will be a really good time to commit your code to your git repository. For this you can use git directly from your command line, use a VS Code extension, or even use GitHub Desktop; this choice is yours.</p><h3>Let’s build the image</h3><p>The command you need to build a docker image is:</p><p>docker build -t samples-weatherforecast:latest .</p><p>Note, you’ll need to run this in the root directory where the Dockerfile is located, if not, it won’t be able to find it — there is a -f option available to specify the location of the Dockerfile if you ever need to.</p><p>-t is the name of the image and tag in <strong>name:tag</strong> format.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uP7-PqslyI4I2Pf9w3gr0A.png" /></figure><blockquote><em>If you’ve followed along to this point, everything should build just fine, if not, please carefully go over the steps, it doesn’t take long.</em></blockquote><h3>Docker image built — Now what?</h3><p>We have built the image, so what do we do next, let’s list the images in our local repository and see what we have there.</p><p>Type the follow command in your terminal:</p><p>docker image ls</p><p>You should see something like the below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dGiXRReDkgVcDRHmG0Sb6A.png" /></figure><p>There is a single image called samples-weatherforecast with a <strong>Tag</strong> of latest, it has an <strong>Image ID</strong>, and we can even see the Size; 210MB - <em>Don&#39;t worry about this size, we will optimise this further later</em>.</p><h3>Let’s run it!</h3><p>We can see our image there, it all looks good, so let’s run it and make sure it works. We can do this a couple of way, my preferred is the terminal with the below command, however, Docker Desktop has improved so much recently, it has become much more user friendly, in particular for first time users, or just for those people who either prefer a UI, or just can’t be bothered with more commands.</p><p>docker run -it --rm -p 8080:80 samples-weatherforecast:latest</p><p>You can see we are using a few options on the command, and we can break these down so you can understand why we have used them.</p><p>-i is for interactive mode; so our terminal will wait.</p><p>-t is to allocate a pseudo-TTY</p><p>--rm automatically removes the container image once the command is terminated.</p><p>-p specifies the port configuration in the format of <strong>host:container</strong></p><blockquote><em>You can always type </em><em>--help to find out what commands are available.</em></blockquote><p>If all is well with your container and your run command, you should see a screen like mine below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JgsY_PEZ7BzR6ZEPYTQC_Q.png" /></figure><p>We now have a working container running, and there are loads of things we could do to inspect the container etc. we can get into that in another blog post.</p><blockquote><em>Don’t forget the Docker Desktop has that new UI, please check it out, it’s fantastic.</em></blockquote><h3>Send a request</h3><p>We have the container running, just waiting there to serve requests, it would be a shame not to send one to make sure it actually works.</p><p>For me, my best friend is Postman, if you haven’t heard of it, I ask you where have you been for the last 10 years! Anyway, if you send a request like the following, your container should reply and come back with the weather forecast.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1xUN3HnhjmlVdGFhAN1Vtw.png" /></figure><p><strong><em>We’re Finished!</em></strong></p><p>Unfortunately not, there is still lots we can do to optimise the size of the container, and there are also loads of Docker commands you should explore to help with your everyday engineering lives too.</p><h3>What have we learned?</h3><p>We have learned the basics of creating a brand new .net 5 webapi, ensuring you have a valid .gitignore file, and the very basics of Docker. We built and ran the image, and tested it to make sure it worked as we expected it to.</p><h3>Furthermore</h3><p>Docker cannot be understated, since 2016 there has been a lot of changes in the container ecosystem, we’ve seen Docker Swarm pretty much come and go through the container wars (Kubernetes won if you didn’t know ). Although through Docker Enterprise sale to Mirantis, Docker Swarm is still alive and kicking inside their Enterprise Container Cloud solution, in addition to a secure, zero-downtime managed Kubernetes product.</p><p>Not to mention there are other orchestrators, to mention just one, there is Nomad from Hashicorp, and there are even other containers similar to Docker like Podman too.</p><p>The benefits of containers are there and paramount no matter what you are really building, even if you’re mixing IaaS and PaaS.</p><h3>Up next</h3><p>Part 2 in this series will be about:</p><ul><li>Optimising the Docker image size</li></ul><h3>More information</h3><ul><li><a href="https://www.azure.com/">https://www.azure.com</a></li><li><a href="https://dotnet.microsoft.com/">https://dotnet.microsoft.com/</a></li><li><a href="https://www.github.com/">https://www.github.com</a></li><li><a href="https://www.docker.com/">https://www.docker.com</a></li><li><a href="https://www.docker.com/why-docker">https://www.docker.com/why-docker</a></li><li><a href="https://www.pulumi.com/">https://www.pulumi.com</a></li></ul><h3>References</h3><p><strong>[1]</strong> — <a href="https://hentsu.com/docker-containers-top-7-benefits/">https://hentsu.com/docker-containers-top-7-benefits/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d9ba4e214fe2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/newday-technology/apis-from-dev-to-production-d9ba4e214fe2">API’s from Dev to Production — Part 1</a> was originally published in <a href="https://medium.com/newday-technology">NewDay Technology</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Shift-Left Engineering]]></title>
            <link>https://medium.com/newday-technology/shift-left-engineering-175a4bcc89ce?source=rss----15fa3c1fe40f---4</link>
            <guid isPermaLink="false">https://medium.com/p/175a4bcc89ce</guid>
            <category><![CDATA[shiftleft]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[culture]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[Pete King]]></dc:creator>
            <pubDate>Thu, 11 Feb 2021 14:40:54 GMT</pubDate>
            <atom:updated>2021-02-11T14:45:01.054Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*c2Q5tmVpBMArA2pvFJHxKQ.png" /></figure><p><strong>Shift-left</strong> is a practice intended to shorten the feedback loop in the lifecycle in order to take decisive action.</p><p>The idea is to improve overall quality and security and more by moving tasks to the left as early in the lifecycle as possible.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*26JtfqFSrPNdYWDH.gif" /></figure><h3>What are the main benefits?</h3><h4>Automation</h4><ul><li>Much fewer human errors</li><li>Increased test confidence</li><li>Fewer production issues</li></ul><h4>Increased delivery speed</h4><ul><li>The time between releases can reduce significantly</li><li>The quality of software improves</li></ul><h4>Increased satisfaction</h4><ul><li>Faster delivery of software with less defects is a major benefit for all; from product owners, stakeholders and even customers!</li></ul><h3>Where are some of the places we can shift-left?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MKjQMDOSBEDdDlaia2TRYQ.png" /></figure><h3>Testing</h3><p>When building API’s for example, the team owns the API product, its design, its code, its quality, in order to ensure a high-quality product is produced for its customers (consumers), the engineering team is responsible for testing its own product. From unit-testing to performance testing and all those in-between, the list above is not an exhaustive one, and there are many other testing practices you can put in place.</p><p>I do hope many of the items listed above are being carried out by an engineering team who owns the product already, for those who are not, the next step is how? How do we, “shift-left”? Well, we need to automate, if you can automate these items, and let’s be honest, who hasn’t automated some of these before in a CI (Continuous Integration) pipeline? — but not everyone has. If you haven’t, these should be an essential items in your shift-left shopping basket!</p><h3>Security</h3><p>Security is paramount these days, and a lot of the time, InfoSec (Information Security) or security teams are on the right. Quite often, these teams are not large teams, and adopt a decentralised model, which puts the responsibility on engineering teams. This means the pressure is already on the engineering team to shift-left and bake security practices into the lifecycle, early and often.</p><p>Through automation, we can achieve fantastic results, as part of CI, it is easy to achieve static / dynamic code analysis, security scanning of internal and open source libraries, and even container scanning. This all means as an engineer, you’ll know very early on if something isn’t quite right, instead of waiting later, and possibly relying on another team.</p><p>As the world of tech continues its love affair with containerisation, security is always at the forefront of security engineers, and with shift-left, it now should also be at the forefront of every software engineer. With containers specifically, container scanning tools are abundant, and some container registries also scan images that are stored. Scanning before pushing a container and when it lands in the registry, is a typical practice to follow.</p><blockquote><strong>With great power comes great responsibility, security should never be an afterthought.</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/0*KuN0YKh9bTNDX0KQ.gif" /></figure><h3>Infrastructure</h3><p>Infrastructure is something we simply can’t avoid, even with serverless; serverless may have integration on vnets (virtual networks). Usually there will be a centralised Operations or Platform team who owns, designs, builds and operates all infrastructure. This can become a big blocker for engineering teams, teams who cannot deploy their own API’s for example, are reliant on another team, and this will in-turn break team autonomy.</p><p>So what do we do, we shift-left? Now, each group of teams will be different, each infrastructure will be different, it is likely you may not shift-left 100%, but you can easily shift-left quite a lot in most setups.</p><p>A centralised Operations / Platform team can design, build, and operate baseline, foundational, bedrock infrastructure. Thereby, product teams can build on top of this, and come together when needed, for instance, virtual networks, firewalls, a SEIM as examples.</p><p>As a product team, what can you now do? Well, now the engineering team can shift-left; they can build on top of the foundational infrastructure. This improves team autonomy, a sense of ownership, and responsibility, furthermore, you breakdown that barrier to release frequently — Deployment frequency is a key DevOps metric.</p><p>One way to achieve this is through infrastructure as code (IaC), and we treat it like any other code, it lives in git. We create PR’s (Pull Requests) and go through CI and CD (Continuous Deployment), it can all be automated, checks can be executed, linters, most tools such as Terraform and Pulumi can preview the infrastructure changes before they are applied.</p><p>If you’ve never done IaC before, don’t be afraid… It’s just like learning a new language, and as an engineer, it’s a healthy and a nice, challenging thing to do. Terraform is HCL — Hashicorp Language; although they are building cloud development kits (CDK’s) in other languages now. Then there is Pulumi, a fantastic platform where the barrier to entry is incredibly low, if you’re engineer building API’s and use C#, Go, Python or even JavaScript with NodeJS, you’ll feel at home with Pulumi. Finally, if you’re more front-end, Pulumi supports JavaScript as mentioned, and also TypeScript too! These are just two mainstream examples, cloud vendors also support IaC with their solutions, Azure with ARM Templates (Bicep is a new slimmer version that is in very early alpha), AWS with Cloud Formation etc. The point is to embrace IaC into product teams so an engineering team is more in control of their own destiny. It doesn’t mean never speak to these centralised Operations / Platform teams, if means an engineering team is less reliant and can go at their pace — which is hopefully at a good fast. One key element to remember is…</p><blockquote><strong>DevOps is not a role, it’s a culture!</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/0*DbW4lGFITW39JEnR.gif" /></figure><h3>Operations</h3><p>Once an API, or a server-side rendered web application, or even a statically generated web application is in production, it needs to be monitored; I wonder who should do that….? A centralised team…. or the team that designed it, built it and deployed it….? It’s of course the engineering team that designed it, built it etc.</p><p>In many organisations just like infrastructure above, the Operations or Platform teams operate the web applications and API’s etc., this is rather right-heavy so-to-speak. As with infrastructure, the same problems occur with operating services, they define monitoring and alerting, are on-call and more. This can work great for smaller organisations, however, if you are in an organisation that is growing and growing as rapidly as NewDay for instance, this model starts to become a hinderance. Now, what do we do, that’s right, we shift left!</p><p>As part of our normal engineering lifecycle, we define performance metrics, degradation metrics, any kind of metric we need for our apps and API’s, we go further and define alerts, anything that is perhaps close to breaching our metrics where we have clear and concise SLA’s (service level agreements) or SLO’s (service level objectives). As part of IaC, these can be baked in as code, we can test early and often in our engineering lifecycle. Once we get to production, it’s the job of the engineering team to monitor there apps and API’s, as they are the ones who designed it, built it and deployed it, the team will be the one to operate it. The engineering team will most likely be on-call if your organisation requires 24/7 operations, because if something goes wrong, the best people to fix it is the team that built it!</p><h3>What’s next?</h3><p>If you’ve reached this far, thank you, I’m sure you’re now wondering what’s next? Well, we will be showcasing practical examples as part of a series soon.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/0*5yI96Mb65Tlspymw.gif" /></figure><h3>NewDay → Shift-Left</h3><p>Here at <a href="https://www.newday.co.uk/">NewDay</a>, we are on our journey to shift-left as we scale, it’s not a short journey, but it will be an enjoyable one, one where we come together not just as individual teams, but also as a community of engineers to help drive forward-thinking, innovative change.</p><blockquote><strong><em>The shift-left philosophy will bring unprecedented value to engineers and our customers lives.</em></strong></blockquote><p><a href="https://www.newday.co.uk/">NewDay</a> embraces a culture of team autonomy, ownership, responsibility and collaboration. We always aim to do the right thing and pull together, taking on the challenge to aspire to the extraordinary and adapting as we build for the future.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=175a4bcc89ce" width="1" height="1" alt=""><hr><p><a href="https://medium.com/newday-technology/shift-left-engineering-175a4bcc89ce">Shift-Left Engineering</a> was originally published in <a href="https://medium.com/newday-technology">NewDay Technology</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>