<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Justin Patriquin</title>
    <description>The latest articles on Forem by Justin Patriquin (@justin1121).</description>
    <link>https://forem.com/justin1121</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F323367%2Ffc3c33ae-36fc-4ddc-a045-f75ad3f67a6a.png</url>
      <title>Forem: Justin Patriquin</title>
      <link>https://forem.com/justin1121</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/justin1121"/>
    <language>en</language>
    <item>
      <title>Releasing Rust Binaries with GitHub Actions - Part 2</title>
      <dc:creator>Justin Patriquin</dc:creator>
      <pubDate>Mon, 21 Nov 2022 14:50:36 +0000</pubDate>
      <link>https://forem.com/justin1121/releasing-rust-binaries-with-github-actions-part-2-180d</link>
      <guid>https://forem.com/justin1121/releasing-rust-binaries-with-github-actions-part-2-180d</guid>
      <description>&lt;p&gt;In this part I'm going to go over how I ended up releasing binaries for MacOS and Windows MSVC.&lt;/p&gt;

&lt;h2&gt;
  
  
  Cross Compilation
&lt;/h2&gt;

&lt;p&gt;Ideally, we could use the cross compilation to build all of the binaries on the same runner type in GitHub Actions. This allows you to build binaries on one platform (e.g. Linux x86_64) that can then run on other platforms. Being able to do this would make our GitHub Action easier to write and maintain. But, there was issue I ran into that prevented cross compilation with Nitrogen from being able to build for different platforms.&lt;/p&gt;

&lt;p&gt;The AWS Rust library we were using as a dependency depended on a cryptography library called &lt;a href="https://github.com/briansmith/ring"&gt;ring&lt;/a&gt;. This library leverages C and assembly code to implement its cryptographic primitives. Unfortunately, cross compiling when C is involved can add complexity to the build process. While it might've been possible to overcome these issues I decided that it wasn't worth digging into more.&lt;/p&gt;

&lt;h2&gt;
  
  
  Implementation
&lt;/h2&gt;

&lt;p&gt;Fortunately, the GitHub Action implementation I ended up going with wasn't that complicated. I just had to use separate runners. One for MacOS Arm and one for Windows MSVC. Here are the steps I had to do for each release type.&lt;/p&gt;

&lt;h3&gt;
  
  
  Build the binary
&lt;/h3&gt;

&lt;p&gt;For Windows it was as simple as running a release build:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ cargo build --release
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The MacOS Arm build is just slightly more complex because the GitHub Actions runner isn't running on Arm architecture so we have to add the separate toolchain and target.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ rustup toolchain install stable-aarch64-apple-darwin
$ rustup target add aarch64-apple-darwin
$ cargo build --release --target aarch64-apple-darwin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Compress the binary
&lt;/h3&gt;

&lt;p&gt;We use &lt;code&gt;tar&lt;/code&gt; to compress the binaries:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ tar --directory=target/release -cf archive.tar.gz nitrogen.exe
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The MacOS &lt;code&gt;tar&lt;/code&gt; command differs slightly because of the cross compilation required to build for Arm.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ tar --directory=target/aarch64-apple-darwin/release -cf archive.tar.gz nitrogen
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Upload the artifact
&lt;/h3&gt;

&lt;p&gt;Since the release is already created we need to query the release ID and then upload the archived binary to the release using the GitHub API.&lt;/p&gt;

&lt;p&gt;The Windows and MacOS version of these differs slightly because Windows has to run in the PowerShell where MacOS would be using bash. You can select the bash shell in the Windows runner but I had an issue with this where it couldn't find the &lt;code&gt;gh&lt;/code&gt; command line tool.&lt;/p&gt;

&lt;p&gt;Windows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ $id = gh api -H "Accept: application/vnd.github+json" /repos/capeprivacy/nitrogen/releases/tags/${{ github.ref_name }} --jq .id
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note: cURL command is edited here for brevity see &lt;a href="https://github.com/capeprivacy/nitrogen/blob/main/.github/workflows/release.yaml#L45"&gt;here&lt;/a&gt; for the full command&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ curl -X POST --data-binary "@archive.tar.gz" "https://uploads.github.com/repos/capeprivacy/nitrogen/releases/$id/assets?name=nitrogen_${{ github.ref_name }}_x86_64-pc-windows-msvc.tar.gz"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;MacOS:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ id=$(gh api -H "Accept: application/vnd.github+json" /repos/capeprivacy/nitrogen/releases/tags/${{ github.ref_name }} --jq .id)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note: cURL command is edited here for brevity see &lt;a href="https://github.com/capeprivacy/nitrogen/blob/main/.github/workflows/release.yaml#L65"&gt;here&lt;/a&gt; for the full command&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ curl -X POST --data-binary @"archive.tar.gz" "https://uploads.github.com/repos/capeprivacy/nitrogen/releases/$id/assets?name=nitrogen_${{ github.ref_name }}_aarch64-apple-darwin.tar.gz"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Check out the full implementation &lt;a href="https://github.com/capeprivacy/nitrogen/blob/main/.github/workflows/release.yaml"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;This was an interesting problem to work on and I learned a lot. Let me know if you have any questions!&lt;/p&gt;

&lt;p&gt;Thanks for reading! If Nitrogen sounds cool to you check it out and give it a star &lt;a href="https://github.com/capeprivacy/nitrogen"&gt;here&lt;/a&gt;, check out the quick installation guide &lt;a href="https://www.capeprivacy.com/nitrogen?utm_source=devto&amp;amp;utm_medium=blog+post&amp;amp;utm_term=nitrogen&amp;amp;utm_content=blog+educational&amp;amp;utm_campaign=blog+ongoing"&gt;here&lt;/a&gt; and come see what's going on on &lt;a href="https://discord.gg/nQW7YxUYjh"&gt;Discord&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>rust</category>
      <category>github</category>
      <category>webdev</category>
      <category>opensource</category>
    </item>
    <item>
      <title>Releasing Rust Binaries with GitHub Actions - Part 1</title>
      <dc:creator>Justin Patriquin</dc:creator>
      <pubDate>Wed, 16 Nov 2022 17:38:48 +0000</pubDate>
      <link>https://forem.com/justin1121/releasing-rust-binaries-with-github-actions-part-1-34jh</link>
      <guid>https://forem.com/justin1121/releasing-rust-binaries-with-github-actions-part-1-34jh</guid>
      <description>&lt;p&gt;GitHub Actions is an amazing tool for CI/CD. Having it built in directly with where your code lives is super convenient. Like most CI/CD systems I've used it can sometimes be tough to build stuff on it in a timely manner. For me it can take a bit of experimentation and time to actually get something to work. Once it does work though it's rock solid.&lt;/p&gt;

&lt;p&gt;In this two part post I'm going to go over the process I went through to release new Rust binaries for our open-source project &lt;a href="https://github.com/capeprivacy/nitrogen" rel="noopener noreferrer"&gt;Nitrogen&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  GitHub Marketplace
&lt;/h2&gt;

&lt;p&gt;GitHub Marketplace has a ton of Actions that can be used right off the shelf and this is where I first go when I'm looking to add a new Action to our CI. &lt;/p&gt;

&lt;p&gt;For Nitrogen I wanted to get binaries released as fast as possible and I found a &lt;a href="https://github.com/marketplace/actions/rust-release-binary" rel="noopener noreferrer"&gt;Rust Binary Release&lt;/a&gt; action in the marketplace. This action was incredibly easy to use and got us binary releases generated almost immediately. One issue with this action though was that it only supported a limited amount of Rust targets (i.e. OS and CPU architecture triples. See &lt;a href="https://doc.rust-lang.org/nightly/rustc/platform-support.html" rel="noopener noreferrer"&gt;here&lt;/a&gt; for more details.). There were two more targets we wanted to support.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;MacOS Arm - with the new Mac CPUs people running on top of the ARM architecture is becoming more and more common so supporting this is becoming more important.&lt;/li&gt;
&lt;li&gt;Windows MSVC (Powershell) - while using &lt;a href="https://learn.microsoft.com/en-us/windows/wsl/install" rel="noopener noreferrer"&gt;WSL&lt;/a&gt; or even something like Git Bash would've worked we wanted to make it possible to use more natively with windows.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the next post I'm going to go over how to added these new targets to our releases and some issues I ran into along the way.&lt;/p&gt;

&lt;p&gt;Thanks for reading! Nitrogen sounds cool to you check it out and give it a star &lt;a href="https://github.com/capeprivacy/nitrogen" rel="noopener noreferrer"&gt;here&lt;/a&gt;, check out the quick installation guide &lt;a href="https://www.capeprivacy.com/nitrogen?utm_source=devto&amp;amp;utm_medium=blog+post&amp;amp;utm_term=nitrogen&amp;amp;utm_content=blog+educational&amp;amp;utm_campaign=blog+ongoing" rel="noopener noreferrer"&gt;here&lt;/a&gt; and come see what's going on on &lt;a href="https://discord.gg/nQW7YxUYjh" rel="noopener noreferrer"&gt;Discord&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>abotwrotethis</category>
    </item>
    <item>
      <title>TLS with Nitrogen</title>
      <dc:creator>Justin Patriquin</dc:creator>
      <pubDate>Mon, 07 Nov 2022 14:46:28 +0000</pubDate>
      <link>https://forem.com/justin1121/tls-with-nitrogen-3gi3</link>
      <guid>https://forem.com/justin1121/tls-with-nitrogen-3gi3</guid>
      <description>&lt;p&gt;I was recently reminded about the tool &lt;a href="https://github.com/FiloSottile/mkcert"&gt;mkcert&lt;/a&gt; and it inspired me to add a TLS example to the &lt;a href="https://github.com/capeprivacy/nitrogen"&gt;Nitrogen&lt;/a&gt;. &lt;code&gt;mkcert&lt;/code&gt; makes its incredibly easy to test TLS with your application during local development. Its &lt;strong&gt;very&lt;/strong&gt; important to note that the TLS certificates generated by mkcert should only be used for development and never production applications.&lt;/p&gt;

&lt;h2&gt;
  
  
  mkcert
&lt;/h2&gt;

&lt;p&gt;Just a quick overview of &lt;code&gt;mkcert&lt;/code&gt;. Before doing anything you must install the CA to your local machine:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkcert -install
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then generating a certificate for localhost is as simple as running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkcert localhost
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  nginx
&lt;/h2&gt;

&lt;p&gt;Adding TLS certificates requires editing a &lt;code&gt;nginx.conf&lt;/code&gt; file and putting the file in the proper place for &lt;code&gt;nginx&lt;/code&gt; to read.&lt;/p&gt;

&lt;p&gt;Example nginx configuration file with TLS enabled:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;server {
  listen 443 ssl default_server;

  ssl_certificate /etc/ssl/certs/nitrogen.pem;
  ssl_certificate_key /etc/ssl/private/nitrogen.key;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then in the Dockerfile we would have some entries like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;COPY nginx.conf /etc/nginx/conf.d/nginx.conf
COPY nitrogen.key /etc/ssl/private/nitrogen.key
COPY nitrogen.pem /etc/ssl/certs/nitrogen.pem
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Nitrogen Example
&lt;/h2&gt;

&lt;p&gt;Check out the full example &lt;a href="https://github.com/capeprivacy/nitrogen/tree/main/examples/nginx-tls"&gt;here&lt;/a&gt;. This is a condensed version.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note: also useful to checkout the nitrogen &lt;a href="https://github.com/capeprivacy/nitrogen#readme"&gt;README.md&lt;/a&gt; first as well&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note: you'll also need an AWS account :D&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;First you'll need to clone the repo and install &lt;code&gt;nitrogen&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git clone https://github.com/capeprivacy/nitrogen
$ curl -fsSL https://raw.githubusercontent.com/capeprivacy/nitrogen/main/install.sh | sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then from the root of the repo (&lt;code&gt;cd nitrogen&lt;/code&gt;) you can run the following commands and hopefully see some glorious HTML served over TLS:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ nitrogen setup nitrogen-nginx-tls ~/.ssh/id_rsa.pub
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From setup you should see an ec2 hostname which needs to be used in the next command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ mkcert -install
$ mkcert -cert-file nitrogen.pem -key-file nitrogen.key &amp;lt;HOSTNAME FROM ABOVE&amp;gt;
$ cp nitrogen.pem nitrogen.key examples/nginx-tls
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ nitrogen build examples/nginx-tls/
$ nitrogen deploy nitrogen-nginx-tls ~/.ssh/id_rsa
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally you can run &lt;code&gt;curl&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$curl https://&amp;lt;HOSTNAME FROM ABOVE&amp;gt;:5000/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally finally, tear down your cloud formation stack so you don't get charged unnecessarily:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ nitrogen delete nitrogen-nginx-tls
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Thanks for reading! We'd love to hear what you think in the comments below. &lt;a href="https://github.com/capeprivacy/nitrogen/"&gt;Please star Nitrogen on GitHub&lt;/a&gt;, and come chat on &lt;a href="https://discord.gg/nQW7YxUYjh"&gt;Discord&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>nginx</category>
      <category>opensource</category>
    </item>
    <item>
      <title>Do you have any ideas for confidential computing?</title>
      <dc:creator>Justin Patriquin</dc:creator>
      <pubDate>Tue, 01 Nov 2022 16:04:37 +0000</pubDate>
      <link>https://forem.com/justin1121/what-would-you-like-to-experiment-with-confidential-computing-3479</link>
      <guid>https://forem.com/justin1121/what-would-you-like-to-experiment-with-confidential-computing-3479</guid>
      <description>&lt;p&gt;Confidential computing allows us to protect data and code while it’s being processed. It’s an important set of technologies, but today it’s difficult to use. We created Nitrogen so you can easily deploy enclaves to AWS Nitro Enclaves to run web services confidentially. Nitrogen easily handles the set up for you and you can quickly be up and running with something you can experiment with.&lt;/p&gt;

&lt;p&gt;Checkout out the &lt;a href="https://github.com/capeprivacy/nitrogen"&gt;README&lt;/a&gt;!&lt;/p&gt;

&lt;p&gt;Do you have any ideas for confidential computing once it becomes easier with tools like Nitrogen?&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>opensource</category>
      <category>devops</category>
      <category>discuss</category>
    </item>
  </channel>
</rss>
