<?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.josemaia.pt/feed.xml" rel="self" type="application/atom+xml" /><link href="https://www.josemaia.pt/" rel="alternate" type="text/html" /><updated>2026-01-22T16:03:37+00:00</updated><id>https://www.josemaia.pt/feed.xml</id><title type="html">josemaia’s blog</title><subtitle>josemaia&apos;s blog</subtitle><author><name>José Maia</name></author><entry><title type="html">Moving away from ingress-nginx: F5 NGINX Ingress Controller</title><link href="https://www.josemaia.pt/F5-NGINX" rel="alternate" type="text/html" title="Moving away from ingress-nginx: F5 NGINX Ingress Controller" /><published>2026-01-22T00:00:00+00:00</published><updated>2026-01-22T00:00:00+00:00</updated><id>https://www.josemaia.pt/F5-NGINX</id><content type="html" xml:base="https://www.josemaia.pt/F5-NGINX"><![CDATA[<h2 id="context">Context</h2>

<p>In November 2025, the Kubernetes SIG Network and Security Response Committee announced the <a href="https://kubernetes.io/blog/2025/11/11/ingress-nginx-retirement/">retirement of ingress-nginx</a>, the widely beloved Ingress Controller (IC) responsible for a good chunk of Ingress handling in Kubernetes. Its Gateway API successor InGate never got enough momentum, and development also stopped for it.</p>

<p>With this retirement happening in March 2026, this is a tight window for most teams, causing a scrambling for alternatives. Some highlights are Chainguard’s <a href="https://www.chainguard.dev/unchained/keeping-ingress-nginx-alive">continued maintenance</a> of the solution through their EmeritOSS program and Traefik’s strong marketing campaign and <a href="https://traefik.io/blog/the-ultimate-ingress-nginx-migration-kit">handy migration tool</a>.</p>

<p>For my specific context at work, with a very heterogenous environment with 400+ clusters in multiple cloud providers, we would like to go forward to Gateway API, with Cilium. However…</p>

<h2 id="why-not-cilium-gateway-api">Why not Cilium Gateway API?</h2>

<p>Cilium is a very powerful networking tool that implements the Container Network Interface (CNI) standard, serving as a highly scalable ‘backbone’ for the networking side of Kubernetes. My team has adopted it as its chosen CNI, and it has been deployed for a few years and fulfilling its purpose very well. Of course, when Gateway API first showed up, Cilium was one of the obvious choices to investigate.</p>

<p>At that time (Nov ‘24), Gateway API spec was still relatively early in development (v1.2), but already had a wide array of implementations - Traefik, Kong, Istio, kgateway, etc. With Cilium being used as CNI, it was the easiest solution to adapt and was quickly provided as a feature flag.</p>

<p>Adoption was in the single digit % in the last year and a bit, and looking at it now, migrating fully is still not viable. The Cilium team mostly tries to stick to the upstream spec for Gateway API, and this comes with multiple restrictions:</p>

<p>1) Authentication/Authorization (see <a href="https://gateway-api.sigs.k8s.io/geps/gep-1494/">GEP-1494</a>)</p>

<p>2) Self-servicing Certificates via cert-manager (see <a href="https://gateway-api.sigs.k8s.io/geps/gep-1713/">GEP-1713</a>)</p>

<p>3) TCP/UDP routes <a href="https://github.com/cilium/cilium/issues/21929">are not implemented in Cilium</a> yet, even though they are in upstream GW API</p>

<p><a href="https://gateway.envoyproxy.io/">Envoy Gateway</a> also uses Envoy underneath, like Cilium’s Gateway API implementation, and could be an option to explore. Still, we decided to move forward with an Ingress Controller, and that exploration eventually led us to decide on the F5 NGINX.</p>

<h2 id="f5-nginx-ic-what-it-is-why-pick-it">F5 NGINX IC: what it is, why pick it?</h2>

<p>The company that owns NGINX, F5, has maintained an Ingress Controller based on it for a very long time. Confusingly, it’s named <strong>nginx-ingress-controller</strong>, which makes SEO terrible and will make you confuse it with the <strong>ingress-nginx</strong> maintained in the Kubernetes organization.</p>

<p>Both implement the same Ingress API spec, write NGINX configuration files, and run an NGINX binary, but the F5 controller comes with an optional “NGINX Plus” closed-source binary that you pay for, and includes some additional neat features like using cookies for session persistence and API-driven reloads instead of the traditional SIGHUP-based config reloads.</p>

<p>A huge plus of these similarities is that if you’re doing something very specific and want it to keep working, you can “crack open the hood” by going inside an <strong>ingress-nginx</strong> pod and try to copy those configs over to the new IC.</p>

<p>These similarities led us to bet on this tool as opposed to Traefik, HAProxy or others, and we quickly migrated all our own workloads to it.</p>

<p>One of our focuses was to try to do the migration avoiding CRDs entirely, and using just the Ingress object itself and related annotations. As this will end up being an intermediary step before what I hope is a more definitive move to Gateway API in the future, we did not want to force users to learn new resources if they didn’t have to.</p>

<p>A huge feature of this IC is the ability to define <a href="https://docs.nginx.com/nginx-ingress-controller/configuration/ingress-resources/custom-annotations/">custom annotations</a> and a custom NGINX configuration template. If you’re afraid of fully opening up NGINX configs with snippets, creating your own curated annotations and blocking snippets with something like Kyverno may be an easier way out.</p>

<p>In this blog post I’ll go over a few of the biggest issues we faced during the migration and how we solved them.</p>

<h3 id="authenticationauthorization">Authentication/Authorization</h3>

<p>We use oauth2-proxy extensively, and together with Keycloak it forms the authentication layer protecting a good chunk of our Ingresses. Some tools like Grafana have direct integration with Keycloak, but others like Prometheus or the Kubernetes Dashboard don’t.</p>

<p>This was the most important part of migrating for us, and unfortunately it requires some ugly code 😭. Here we follow the <a href="https://oauth2-proxy.github.io/oauth2-proxy/configuration/integrations/nginx#configuring-for-use-with-the-nginx-auth_request-directive">reference documentation</a> adapted for our experience.</p>

<h4 id="defaults-and-global-configs">Defaults and global configs</h4>

<p>First, we set some sane defaults in the ConfigMap. Not setting these caused issues, even if we set them in each of the Ingresses we migrated.</p>

<div class="language-yaml highlighter-rouge"><div class="highlight"><pre class="highlight"><code>  <span class="na">proxy-buffer-size</span><span class="pi">:</span> <span class="s">128k</span>
  <span class="na">proxy-buffers</span><span class="pi">:</span> <span class="s">8 128k</span>
  <span class="na">proxy-busy-buffers-size</span><span class="pi">:</span> <span class="s">256k</span>
</code></pre></div></div>

<h4 id="oauth2proxy--keycloak">OAuth2Proxy &amp; Keycloak</h4>

<p>Both oauth2proxy and Keycloak (our selected IAM tool) have their own Ingresses. Naturally, they are not protected by themselves 😊. Keycloak configurations are mostly out-of-the-box supported, note the replacement of <strong>nginx.ingress.kubernetes.io/app-root</strong> by a location-wide snippet:</p>

<div class="language-yaml highlighter-rouge"><div class="highlight"><pre class="highlight"><code>    <span class="na">nginx.org/location-snippets</span><span class="pi">:</span> <span class="pi">|</span>
      <span class="s">location = / {</span>
        <span class="s">return 301 /auth/;</span>
      <span class="s">}</span>
    <span class="na">nginx.org/ssl-services</span><span class="pi">:</span> <span class="s">keycloak</span>
</code></pre></div></div>

<p>And for the oauth2proxy ingress itself, we need no configuration.</p>

<h4 id="protecting-each-ingress">Protecting each Ingress</h4>

<p>Then, the configuration that was previously handled by the elegant <strong>nginx.ingress.kubernetes.io/auth-signin</strong> and <strong>auth-url</strong> annotations needs to be written with snippets. If you consider giving end users access to snippets a security risk, please consider going to Traefik and using its ForwardAuth middleware.</p>

<div class="language-yaml highlighter-rouge"><div class="highlight"><pre class="highlight"><code>    <span class="na">annotations</span><span class="pi">:</span>
      <span class="na">nginx.org/location-snippets</span><span class="pi">:</span> <span class="pi">|</span>
        <span class="s">auth_request /_oauth2_validate;</span>
        <span class="s">auth_request_set $auth_cookie $upstream_http_set_cookie;</span>
        <span class="s">add_header Set-Cookie $auth_cookie;</span>
        <span class="s">error_page 401 = @oauth2_redirect;</span>
      <span class="na">nginx.org/server-snippets</span><span class="pi">:</span> <span class="pi">|</span>
        <span class="s">location = /_oauth2_validate {</span>
          <span class="s">internal;</span>
          <span class="s">proxy_pass http://oauth2-proxy.\{\{ .Values.oauth_namespace \}\}.svc.cluster.local/oauth2/auth;</span>
          <span class="s">proxy_pass_request_body off;</span>
          <span class="s">proxy_set_header Content-Length "";</span>
          <span class="s">proxy_set_header X-Original-URI $request_uri;</span>
          <span class="s">proxy_set_header X-Original-Method $request_method;</span>
          <span class="s">proxy_set_header Host $host;</span>
        <span class="s">}</span>
        <span class="s">location @oauth2_redirect {</span>
          <span class="s">internal;</span>
          <span class="s">add_header Set-Cookie $auth_cookie;</span>
          <span class="s">return 302 https://oauth2-proxy.apps.\{\{ .Values.dns_subdomain \}\}/oauth2/start?rd=$scheme://$http_host$request_uri;</span>
        <span class="s">}</span>
</code></pre></div></div>

<p>In the above snippet, we have one instance of oauth2proxy installed in the namespace identified by <em>.Values.oauth_namespace</em>, and publicly available to our users at <em><a href="https://oauth2-proxy.apps.">https://oauth2-proxy.apps.</a></em>. If you’re using any kind of network policies/filters, make sure that the namespace where the F5 NGINX IC is installed can reach the <em>oauth_namespace</em>.</p>

<p>We could only get things working properly with Redis as the storage for oauth2proxy’s sessions, as huge cookies of 4+ KB are a huge pain in oauth2-proxy, involving ugly cookie splitting and joining configs inside the snippets. We strongly recommend doing the same if you’re facing similar issues.</p>

<h3 id="basic-auth">Basic Auth</h3>

<p>Some of our Ingresses (e.g. Prometheus /federate endpoint) were using HTTP Basic Auth. It works in a very similar way, but needs a specific secret type <strong>nginx.org/htpasswd</strong>, and the secret contents must be named <strong>htpasswd</strong>! If you were using a Secret for this before, you will need to migrate to something like htis before using the annotation <strong>nginx.org/basic-auth-secret</strong>:</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">v1</span>
<span class="na">kind</span><span class="pi">:</span> <span class="s">Secret</span>
<span class="na">metadata</span><span class="pi">:</span>
    <span class="na">name</span><span class="pi">:</span> <span class="s">prometheus-federation-auth</span>
    <span class="na">namespace</span><span class="pi">:</span> <span class="s">&lt;namespace&gt;</span>
    <span class="na">labels</span><span class="pi">:</span>
    <span class="na">prometheus-federation-auth</span><span class="pi">:</span> <span class="s2">"</span><span class="s">true"</span>
<span class="na">type</span><span class="pi">:</span> <span class="s">nginx.org/htpasswd</span>
<span class="na">data</span><span class="pi">:</span>
    <span class="na">htpasswd</span><span class="pi">:</span> <span class="s">blahblahblah</span>
</code></pre></div></div>

<h3 id="grpc-tls">GRPC, TLS</h3>

<p>This is stated pretty clearly in the <a href="https://docs.nginx.com/nginx-ingress-controller/install/migrate-ingress-nginx/#migration-with-kubernetes-ingress-resources">migration docs</a>, but I’d like to highlight it again as it’s not very obvious.</p>

<p>If you were using <strong>nginx.ingress.kubernetes.io/backend-protocol</strong> before, you now have to specify the <strong>Kubernetes Service</strong> that was being targeted by that Backend Protocol annotation. For example, if you are accessing Keycloak behind an Ingress, you might have to move from <strong>nginx.ingress.kubernetes.io/backend-protocol: “HTTPS”</strong> to <strong>nginx.org/ssl-services: “keycloak”</strong>.</p>

<h2 id="conclusion">Conclusion</h2>

<p>No plan survives contact with the enemy, so I expect when deploying this to real environments people will discover more things that are not working. For header manipulation (e.g. CORS), mTLS, rate limiting, and other complex Ingress configurations, F5 pushes you towards using their Custom Resources - Policy, VirtualServer, TransportServer…, but I hope to avoid their usage in most scenarios.</p>

<p>Maybe I’ll make another blog post when I find out more bugbears!</p>]]></content><author><name>José Maia</name></author><category term="work" /><category term="english" /><summary type="html"><![CDATA[Context]]></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://www.josemaia.pt/2026-01/512px-Shibuya_scramble_crossing_during_Halloween_2023,_actually_less_crowded_than_usual,_high_police_presence_2.jpg" /><media:content medium="image" url="https://www.josemaia.pt/2026-01/512px-Shibuya_scramble_crossing_during_Halloween_2023,_actually_less_crowded_than_usual,_high_police_presence_2.jpg" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">Bôla de Carne D. Lídia | D. Lídia Meat Bread</title><link href="https://www.josemaia.pt/Bola-D-Lidia" rel="alternate" type="text/html" title="Bôla de Carne D. Lídia | D. Lídia Meat Bread" /><published>2025-04-16T00:00:00+00:00</published><updated>2025-04-16T00:00:00+00:00</updated><id>https://www.josemaia.pt/Bola-D-Lidia</id><content type="html" xml:base="https://www.josemaia.pt/Bola-D-Lidia"><![CDATA[<h1 id="portuguese">Portuguese</h1>
<h2 id="ingredientes">Ingredientes:</h2>
<ul>
  <li>500 g de farinha</li>
  <li>0.25 L de leite</li>
  <li>100 g de margarina (derretida, se necessário)</li>
  <li>1 saqueta fermento de padeiro (normalmente 11g, marca Fermipan)</li>
  <li>4 ovos</li>
  <li>approx. 400g de carne a gosto (presunto, fiambre, linguiça, bacon, etc.)</li>
</ul>

<h2 id="instruções">Instruções</h2>
<ol>
  <li>Mistura-se a farinha com o leite</li>
  <li>Adiciona-se a margarina e continua-se a misturar até esfarelar</li>
  <li>Adicionar-se o fermento e ovos, continuando a misturar bastante tempo com as mãos, sovando bem.</li>
  <li>Untar uma forma e polvihar de farinha</li>
  <li>Misturar bem a carne, para garantir consistência mais uniforme entre carne e pão</li>
  <li>Colocar na forma e deixar levedar pelo menos 1h</li>
  <li>Cozer em forno brando, 1h a 1h30.</li>
</ol>

<p>Pode-se escalar a receita à quantidade necessária, alimenta quantos forem precisos. Pode ser cozinhada numa forma redonda ou mais quadrada / rectangular. Redonda fica assim:</p>

<p><img src="/assets/img/2025-04/bola-cozinhada.png" alt="Eu sei que a imagem é pequena, ok?" /></p>

<h1 id="english">English</h1>
<p>TBD</p>]]></content><author><name>José Maia</name></author><category term="recipes" /><category term="portugues" /><summary type="html"><![CDATA[Portuguese Ingredientes: 500 g de farinha 0.25 L de leite 100 g de margarina (derretida, se necessário) 1 saqueta fermento de padeiro (normalmente 11g, marca Fermipan) 4 ovos approx. 400g de carne a gosto (presunto, fiambre, linguiça, bacon, etc.)]]></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://www.josemaia.pt/2025-04/bola-wip.png" /><media:content medium="image" url="https://www.josemaia.pt/2025-04/bola-wip.png" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">Mousse de Manga Tia Lena | Tia Lena Mango Mousse</title><link href="https://www.josemaia.pt/Mousse-de-manga" rel="alternate" type="text/html" title="Mousse de Manga Tia Lena | Tia Lena Mango Mousse" /><published>2025-04-16T00:00:00+00:00</published><updated>2025-04-16T00:00:00+00:00</updated><id>https://www.josemaia.pt/Mousse-de-manga</id><content type="html" xml:base="https://www.josemaia.pt/Mousse-de-manga"><![CDATA[<h1 id="portuguese">Portuguese</h1>
<h2 id="ingredientes">Ingredientes:</h2>
<ul>
  <li>4 folhas de gelatina neutra</li>
  <li>850g de polpa de manga</li>
  <li>500g iogurte grego</li>
  <li>370g de leite condensado magro</li>
</ul>

<h2 id="instruções">Instruções</h2>
<ol>
  <li>Demolhar as folhas de gelatina em água fria</li>
  <li>Deitar os iogurtes numa taça e mexer bem</li>
  <li>Juntar a polpa de manga e o leite condensado, voltando a mexer bem até ficar consistente</li>
  <li>Escorrer a gelatina e derreter no microondas, com alguma água fria (uma colher de sopa basta)</li>
  <li>Juntar a gelatina e misturar bem, garantindo que fica uma mistura uniforme</li>
  <li>Deixar no frigorífico pelo menos 4h, idealmente de um dia para o outro.</li>
</ol>

<p>Também fica boa congelada.</p>

<h1 id="english">English</h1>
<p>TBD</p>]]></content><author><name>José Maia</name></author><category term="recipes" /><category term="portugues" /><summary type="html"><![CDATA[Portuguese Ingredientes: 4 folhas de gelatina neutra 850g de polpa de manga 500g iogurte grego 370g de leite condensado magro]]></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://www.josemaia.pt/2025-04/mousse-manga.jpg" /><media:content medium="image" url="https://www.josemaia.pt/2025-04/mousse-manga.jpg" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">Do the Impossible</title><link href="https://www.josemaia.pt/Do-the-impossible" rel="alternate" type="text/html" title="Do the Impossible" /><published>2020-07-09T00:00:00+00:00</published><updated>2020-07-09T00:00:00+00:00</updated><id>https://www.josemaia.pt/Do-the-impossible</id><content type="html" xml:base="https://www.josemaia.pt/Do-the-impossible"><![CDATA[<h2 id="better-things-arent-possible">Better things aren’t possible</h2>

<p><em>“The prison is one of the most important features of our image environment. This has caused us to take the existence of prisons for granted. The prison has become a key ingredient of our common sense. It is there, all around us. We do not question whether it should exist. It has become so much a part of our lives that it requires a great feat of the imagination to envision life beyond the prison.” - Angela Davis (Are Prisons Obsolete?)</em></p>

<p><em>“Do the impossible, see the invisible / Raw! Raw! Fight the power!” - Libera me from Hell (Gurren Lagann OST)</em></p>

<p>There’s a thought that’s been biting away at my brain ever since I read Are Prisons Obsolete (well, there are a lot of them, but I’m just talking about one this time), and it got dislodged today after a work meeting. It’s that we do not <strong><em>question things</em></strong> nearly as often as we should. We take the current state of things for the state of things as they always were, and as always will be.</p>

<p><img src="../centrism.png" alt="Better things aren't possible" /></p>

<p>There are multiple things my team does at work that are seen as unusual by colleagues. Most of them are agile methodology related, because we are essentially fully self-organized. This self-organization arose partly as a response to our material reality: our manager is busy and can’t take care of the backlog, so we will. Others happened gradually as the team grew in size and familiarity with each other. Ultimately they’re all things that are not particularly complex, such as the aforementioned backlog management or everyone sharing responsibility for scrum events.</p>

<p>How did we do it? We <strong>didn’t know it was (supposed to be) impossible</strong>. We just did it and it worked.</p>

<p>Often when discussing a political topic, I feel stuck when trying to get my (not even particularly radical) views through to the other person - it’s the end of history after all, what are you talking about? Of course we can’t leave NATO, or prosecute corrupt millionaires, or improve public transit. It’s <strong>Just The Way Things Are</strong>.</p>

<p>Fuck that. Every time someone tells you it’s just not feasible tell them to <strong>imagine a better world</strong>. When did we give up on that?</p>]]></content><author><name>José Maia</name></author><category term="nonwork" /><category term="english" /><summary type="html"><![CDATA[Better things aren’t possible]]></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://www.josemaia.pt/nonwork-default.jpg" /><media:content medium="image" url="https://www.josemaia.pt/nonwork-default.jpg" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">Fiambre Assado c/Mel | Roasted Ham w/ Honey</title><link href="https://www.josemaia.pt/Fiambre-Assado-c-Mel" rel="alternate" type="text/html" title="Fiambre Assado c/Mel | Roasted Ham w/ Honey" /><published>2020-02-10T00:00:00+00:00</published><updated>2020-02-10T00:00:00+00:00</updated><id>https://www.josemaia.pt/Fiambre-Assado-c-Mel</id><content type="html" xml:base="https://www.josemaia.pt/Fiambre-Assado-c-Mel"><![CDATA[<h1 id="portuguese">Portuguese</h1>
<h2 id="ingredientes">Ingredientes:</h2>
<ul>
  <li>1 fiambre de porco inteiro com cerca de 2 Kg</li>
  <li>Sumo de laranja q.b. p/ cobrir a quantidade desejada de fiambre</li>
  <li>Mel a gosto</li>
  <li>6 Cravinhos</li>
</ul>

<h2 id="instruções">Instruções</h2>
<ol>
  <li>Ligar o forno a uma temperatura não muito alta (e.g. 150ºC, 180ºC), para gradualmente reduzir até 100ºC ao longo do processo</li>
  <li>Golpear ligeiramente o fiambre de forma diagnonal, para que pareça uma grelha</li>
  <li>Colocar num Pyrex que possa ir ao forno, de tamanho semelhante ao do fiambre</li>
  <li>Colocar a mistura e deixar pelo menos 1h de molho antes de ir ao forno, virando o fiambre durante este tempo, para distribuir o tempero</li>
  <li>Levar ao forno</li>
  <li>Ir virando o fiambre até ganhar uma cor acastanhada e evaporar a maior parte da mistura</li>
  <li>Servir, ainda quente ou frio. Aguenta no frigorífico alguns dias.</li>
</ol>

<h1 id="english">English</h1>
<p>TBD</p>]]></content><author><name>José Maia</name></author><category term="recipes" /><category term="portugues" /><summary type="html"><![CDATA[Portuguese Ingredientes: 1 fiambre de porco inteiro com cerca de 2 Kg Sumo de laranja q.b. p/ cobrir a quantidade desejada de fiambre Mel a gosto 6 Cravinhos]]></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://www.josemaia.pt/2025-04/fiambre.png" /><media:content medium="image" url="https://www.josemaia.pt/2025-04/fiambre.png" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">SignalR in .NET Core - File Downloads</title><link href="https://www.josemaia.pt/SignalR-In-Dotnet-Core-File-Downloads" rel="alternate" type="text/html" title="SignalR in .NET Core - File Downloads" /><published>2018-07-01T00:00:00+00:00</published><updated>2018-07-01T00:00:00+00:00</updated><id>https://www.josemaia.pt/SignalR-In-Dotnet-Core-File-Downloads</id><content type="html" xml:base="https://www.josemaia.pt/SignalR-In-Dotnet-Core-File-Downloads"><![CDATA[<p>This is just a small example of how to use the new <a href="https://github.com/aspnet/signalr">SignalR</a> version distributed with .NET Core from 2.1 onwards in order to perform a file download between a client and a server.</p>

<p>The usage scenario here was a server with a Web API/MVC logic that hosts a SignalR hub, combined with a series of clients that exist in machines distributed across the world that are connected to that hub. It should be possible for the hub to trigger a file download on those clients, sending them a zip, or a JPG, or whatever.</p>

<p>This sample is of the <strong>server-side</strong> code:</p>
<div class="language-csharp highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">public</span> <span class="n">ChannelReader</span><span class="p">&lt;</span><span class="kt">byte</span><span class="p">[</span><span class="k">]&gt;</span> <span class="nf">DownloadFileStream</span><span class="p">(</span><span class="kt">string</span> <span class="n">path</span><span class="p">)</span>
<span class="p">{</span>
    <span class="n">Guard</span><span class="p">.</span><span class="n">Against</span><span class="p">&lt;</span><span class="n">FileNotFoundException</span><span class="p">&gt;(!</span><span class="n">File</span><span class="p">.</span><span class="nf">Exists</span><span class="p">(</span><span class="n">path</span><span class="p">),</span> <span class="s">$"No file found at </span><span class="p">{</span><span class="n">path</span><span class="p">}</span><span class="s">"</span><span class="p">);</span>
    <span class="kt">var</span> <span class="n">channel</span> <span class="p">=</span> <span class="n">Channel</span><span class="p">.</span><span class="n">CreateUnbounded</span><span class="p">&lt;</span><span class="kt">byte</span><span class="p">[</span><span class="k">]&gt;</span><span class="p">();</span>
    <span class="n">_</span> <span class="p">=</span> <span class="nf">WriteToChannel</span><span class="p">(</span><span class="n">channel</span><span class="p">,</span> <span class="n">path</span><span class="p">);</span>
    <span class="k">return</span> <span class="n">channel</span><span class="p">.</span><span class="n">Reader</span><span class="p">;</span>
    <span class="k">async</span> <span class="n">Task</span> <span class="nf">WriteToChannel</span><span class="p">(</span><span class="n">ChannelWriter</span><span class="p">&lt;</span><span class="kt">byte</span><span class="p">[</span><span class="k">]&gt;</span> <span class="n">writer</span><span class="p">,</span> <span class="kt">string</span> <span class="n">filePath</span><span class="p">)</span>
    <span class="p">{</span>
        <span class="k">using</span> <span class="p">(</span><span class="n">FileStream</span> <span class="n">fs</span> <span class="p">=</span> <span class="n">File</span><span class="p">.</span><span class="nf">OpenRead</span><span class="p">(</span><span class="n">filePath</span><span class="p">))</span>
        <span class="p">{</span>
            <span class="kt">byte</span><span class="p">[]</span> <span class="n">buffer</span> <span class="p">=</span> <span class="k">new</span> <span class="kt">byte</span><span class="p">[</span><span class="m">8</span> <span class="p">*</span> <span class="m">1024</span><span class="p">];</span>
            <span class="kt">int</span> <span class="n">len</span><span class="p">;</span>
            <span class="k">while</span> <span class="p">((</span><span class="n">len</span> <span class="p">=</span> <span class="k">await</span> <span class="n">fs</span><span class="p">.</span><span class="nf">ReadAsync</span><span class="p">(</span><span class="n">buffer</span><span class="p">,</span> <span class="m">0</span><span class="p">,</span> <span class="n">buffer</span><span class="p">.</span><span class="n">Length</span><span class="p">))</span> <span class="p">&gt;</span> <span class="m">0</span><span class="p">)</span>
            <span class="p">{</span>
                <span class="k">await</span> <span class="n">writer</span><span class="p">.</span><span class="nf">WriteAsync</span><span class="p">(</span><span class="n">buffer</span><span class="p">);</span>
                <span class="k">await</span> <span class="n">Task</span><span class="p">.</span><span class="nf">Delay</span><span class="p">(</span><span class="m">1000</span><span class="p">);</span>
            <span class="p">}</span>
            <span class="n">writer</span><span class="p">.</span><span class="nf">Complete</span><span class="p">();</span>
        <span class="p">}</span>
    <span class="p">}</span>
<span class="p">}</span>
</code></pre></div></div>

<p>And on the <strong>client-side</strong>:</p>
<div class="language-csharp highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">private</span> <span class="k">async</span> <span class="n">Task</span> <span class="nf">BeginStreamingFile</span><span class="p">(</span><span class="kt">string</span> <span class="n">path</span><span class="p">)</span>
<span class="p">{</span>
    <span class="kt">string</span> <span class="n">fileName</span> <span class="p">=</span> <span class="n">Path</span><span class="p">.</span><span class="nf">GetFileName</span><span class="p">(</span><span class="n">path</span><span class="p">);</span>
    <span class="kt">var</span> <span class="n">channel</span> <span class="p">=</span> <span class="k">await</span> <span class="n">_connection</span><span class="p">.</span><span class="n">StreamAsChannelAsync</span><span class="p">&lt;</span><span class="kt">byte</span><span class="p">[</span><span class="k">]&gt;</span><span class="p">(</span><span class="s">"DownloadFileStream"</span><span class="p">,</span> <span class="n">path</span><span class="p">,</span> <span class="n">CancellationToken</span><span class="p">.</span><span class="n">None</span><span class="p">);</span>
    <span class="k">while</span> <span class="p">(</span><span class="k">await</span> <span class="n">channel</span><span class="p">.</span><span class="nf">WaitToReadAsync</span><span class="p">())</span>
    <span class="p">{</span>
        <span class="k">using</span> <span class="p">(</span><span class="n">FileStream</span> <span class="n">fs</span> <span class="p">=</span> <span class="n">File</span><span class="p">.</span><span class="nf">OpenWrite</span><span class="p">(</span><span class="n">fileName</span><span class="p">))</span> <span class="p">{</span> 
            <span class="k">while</span> <span class="p">(</span><span class="n">channel</span><span class="p">.</span><span class="nf">TryRead</span><span class="p">(</span><span class="k">out</span> <span class="kt">byte</span><span class="p">[]</span> <span class="n">buffer</span><span class="p">))</span>
            <span class="p">{</span>
                <span class="k">await</span> <span class="n">fs</span><span class="p">.</span><span class="nf">WriteAsync</span><span class="p">(</span><span class="n">buffer</span><span class="p">,</span> <span class="m">0</span><span class="p">,</span> <span class="n">buffer</span><span class="p">.</span><span class="n">Length</span><span class="p">);</span>
            <span class="p">}</span>
        <span class="p">}</span>
    <span class="p">}</span>
<span class="p">}</span>
</code></pre></div></div>

<p>The solution I had to begin the streaming was for the client to get a message with the path of the file it wanted to download from a helper method in a controller I’d do a HTTP POST on. Before I was able to develop something cleverer, we decided that, for the purposes of the feature we were designing, we could just use a feature we already had designed and do the download of a ZIP file from the API with what we needed. Hopefully in the future we’ll come back to this!</p>

<h3 id="references--read-more">References / Read More</h3>

<ul>
  <li>https://radu-matei.com/blog/signalr-core/ - Please check out Radu Matei’s post on ASP.NET SignalR. It was really helpful in getting us started with it, especially as we began this work before a stable version of .NET Core 2.1 was even out, so the documentation didn’t cover a lot of what we needed.</li>
</ul>]]></content><author><name>José Maia</name></author><category term="work" /><category term="csharp" /><category term="dotnet" /><category term="english" /><summary type="html"><![CDATA[This is just a small example of how to use the new SignalR version distributed with .NET Core from 2.1 onwards in order to perform a file download between a client and a server.]]></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://www.josemaia.pt/work-default.jpg" /><media:content medium="image" url="https://www.josemaia.pt/work-default.jpg" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">Optimizing ASP.NET Core Docker images</title><link href="https://www.josemaia.pt/Optimizing-ASP.NET-Core-Docker-images" rel="alternate" type="text/html" title="Optimizing ASP.NET Core Docker images" /><published>2017-12-15T00:00:00+00:00</published><updated>2017-12-15T00:00:00+00:00</updated><id>https://www.josemaia.pt/Optimizing%20ASP.NET%20Core%20Docker%20images</id><content type="html" xml:base="https://www.josemaia.pt/Optimizing-ASP.NET-Core-Docker-images"><![CDATA[<p>With ASP.NET Core 2.0, Microsoft included a new NuGet Package to manage your projects’ dependencies on the ASP.NET Core framework, the <a href="https://docs.microsoft.com/en-us/aspnet/core/fundamentals/metapackage">Microsoft.AspNetCore.All</a> metapackage.</p>

<p>The advantages of using this package instead of individually referencing the packages you need are twofold:</p>
<ul>
  <li>
    <p>You save up time looking for specific minor versions of the packages. Referencing AspNetCore.All 2.0.0 and upgrading to 2.0.3 is going to ensure you get all the bugfixes without having to worry about looking for individual package updates.</p>
  </li>
  <li>
    <p>You save up space in published applications. This requires, however, an installation on the target of the ASP .NET Core Runtime Store - an installable manifest-defined directory that contains the relevant packages, and that can be installed in deployment targets for your application.</p>
  </li>
</ul>

<p>With this last point, especially, the advantages are clear for Docker users. If you look at the definition of the <a href="https://github.com/aspnet/aspnet-docker/blob/master/2.0/jessie/runtime/Dockerfile">official Microsoft ASP.NET Core docker images</a>, you can see that the runtime store is being setup. What does this mean? Well, it means that if you have 1, 5, or 300 different docker images based off the official microsoft/aspnetcore image, you will only download these packages once - any other layers beyond that, defined in your own Dockerfile, will not be redownloaded.</p>

<p>This makes for huge savings in space (and, directly, time). In my quick experiment, the savings were astoundingly high - a relatively simple microservice with its only NuGet dependencies being Newtonsoft.Json, MediatR and AspNetCore libraries went from 54 MB to 6.</p>

<h3 id="things-im-looking-into-next">Things I’m looking into next</h3>

<ul>
  <li>
    <p>Using the <a href="https://www.nuget.org/packages/Microsoft.Packaging.Tools.Trimming/1.1.0-preview1-25818-01">Microsoft.Packaging.Tools.Trimming</a> library to cut some more size off. It sounds <a href="https://github.com/dotnet/standard/blob/release/2.0.0/Microsoft.Packaging.Tools.Trimming/docs/trimming.md">really good</a>, but the fact that it’s still in pre-release worries me a bit. We’ll see.</p>
  </li>
  <li>
    <p>Creating my own base image that inherits from aspnetcore and fills the runtime store with some more packages that may be common to all my images (Newtonsoft.Json is always going to be there, and that’s another few megabytes we can save!). This would probably have to have a dedicated build step before the rest of my build, to ensure I keep up with the minor updates Microsoft publishes to its aspnetcore version.</p>
  </li>
</ul>

<h3 id="references--read-more">References / Read More</h3>

<ul>
  <li>https://andrewlock.net/the-microsoft-aspnetcore-all-metapackage-is-huge-and-thats-awesome-thanks-to-the-net-core-runtime-store-2/</li>
</ul>]]></content><author><name>José Maia</name></author><category term="work" /><category term="csharp" /><category term="docker" /><category term="english" /><summary type="html"><![CDATA[With ASP.NET Core 2.0, Microsoft included a new NuGet Package to manage your projects’ dependencies on the ASP.NET Core framework, the Microsoft.AspNetCore.All metapackage.]]></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://www.josemaia.pt/work-default.jpg" /><media:content medium="image" url="https://www.josemaia.pt/work-default.jpg" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">Hello, World!</title><link href="https://www.josemaia.pt/Hello-World" rel="alternate" type="text/html" title="Hello, World!" /><published>2017-12-13T00:00:00+00:00</published><updated>2017-12-13T00:00:00+00:00</updated><id>https://www.josemaia.pt/Hello-World</id><content type="html" xml:base="https://www.josemaia.pt/Hello-World"><![CDATA[<p>Hello!</p>

<p>My name is José Maia. I’m a software developer from the north of Portugal, deeply passionate about a bunch of things, such as pro wrestling, video games, history and DevOps.</p>

<p>I setup this blog so I’d have a place to post about interesting things that happen to me during the working week that I can share with other people, as well as random thoughts and reviews of media.</p>]]></content><author><name>José Maia</name></author><category term="english" /><summary type="html"><![CDATA[Hello!]]></summary></entry></feed>