<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Hugo on Geek Cabinet</title>
    <link>https://geekcabi.net/tags/hugo/</link>
    <description>Recent content in Hugo on Geek Cabinet</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-us</language>
    <lastBuildDate>Tue, 21 Nov 2023 00:00:00 +0000</lastBuildDate><atom:link href="https://geekcabi.net/tags/hugo/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Using 1Password Secrets to Deploy Hugo to S3</title>
      <link>https://geekcabi.net/posts/1password-secrets-with-hugo/</link>
      <pubDate>Tue, 21 Nov 2023 00:00:00 +0000</pubDate>
      
      <guid>https://geekcabi.net/posts/1password-secrets-with-hugo/</guid>
      <description>&lt;p&gt;Hugo helpfully supports the deployment of processed files to an S3 bucket, and the 1Password &lt;code&gt;op&lt;/code&gt; command line utility makes injecting AWS access keys super easy and secure. This is far superior to the &lt;code&gt;aws s3 sync&lt;/code&gt; command I &lt;strong&gt;had&lt;/strong&gt; been running until now! 🤷‍♂️️&lt;/p&gt;</description>
      <content:encoded><![CDATA[<p>Hugo helpfully supports the deployment of processed files to an S3 bucket, and the 1Password <code>op</code> command line utility makes injecting AWS access keys super easy and secure. This is far superior to the <code>aws s3 sync</code> command I <strong>had</strong> been running until now! 🤷‍♂️️</p>
<h2 id="set-up">Set up</h2>
<ol>
<li>
<p><a href="https://developer.1password.com/docs/cli/get-started/" rel="noopener" target="_blank" class="external">Install 1Password cli and enable desktop app integration</a>.</p>
</li>
<li>
<p>Create IAM credentials, with permissions to perform S3 actions and store them in 1Password.</p>
</li>
</ol>
<p>This is left as an exercise to the reader. 😄️</p>
<ol start="3">
<li>
<p><a href="https://developer.1password.com/docs/cli/secret-references#step-1-copy-secret-references" rel="noopener" target="_blank" class="external">Copy the 1Password secret references</a> to the AWS Access Key ID and AWS Secret Access Key items.</p>
</li>
<li>
<p>Create an environment variable file with those two links.</p>
</li>
</ol>
<p>1Password&rsquo;s <a href="https://developer.1password.com/docs/cli/secrets-environment-variables#use-environment-env-files" rel="noopener" target="_blank" class="external">full documentation of the environment variable file</a> is simple and the file is flexible for all kinds of use cases. But for this example, it will only contain two lines:</p>
<pre tabindex="0"><code>AWS_ACCESS_KEY_ID = &#34;op://Vault/blahblahblahblahblahblah/access key id&#34;
AWS_SECRET_ACCESS_KEY = &#34;op://Vault/blahblahblahblahblahblah/secret access key&#34;
</code></pre><p>Save this file as <code>prod.env</code> (or whatever suits your fancy).</p>
<ol start="4">
<li>Update <code>hugo.yaml</code> to include deployment target.</li>
</ol>
<p>At the bottom of <code>hugo.yaml</code>, include a <code>deployment</code> section:</p>
<pre tabindex="0"><code>deployment:
    targets:
        - name: production
          URL: &#34;s3://s3-bucket-name/&#34;
          cloudFrontDistributionID: &#34;0A1B2C3D4E5F6G&#34;
</code></pre><p>The <code>cloudFrontDistributionID</code> element is optional, but helpful. But if you DO include it, take note of the warning below during deployment.</p>
<p>If your site content is in a subfolder of the S3 bucket, the URL would look more like this:</p>
<pre tabindex="0"><code>URL: &#34;s3://s3-bucket-name/?prefix=foldername/&#34;
</code></pre><p>(Refer to the <a href="https://gohugo.io/hosting-and-deployment/hugo-deploy/" rel="noopener" target="_blank" class="external">Hugo Docs</a> for more info on S3 configuration details for Hugo deployment.)</p>
<h2 id="deploy">Deploy!</h2>
<ol>
<li>Build the static pages</li>
</ol>
<p>Run from the root of the repo:</p>
<pre tabindex="0"><code>hugo --loglLevel info --destination public/
</code></pre><p>(I like to include the log level for visibility, but to each his own!)</p>
<ol start="2">
<li>Validate</li>
</ol>
<p>For the cautious among you: validate the actions to be taken, using the <code>--dryRun</code> flag:</p>
<pre tabindex="0"><code>op run --env-file prod.env -- hugo deploy --logLevel info --confirm --dryRun --target production
</code></pre><ol start="3">
<li>Deploy</li>
</ol>
<p>Or skip straight to the <strong>actual</strong> deployment if you&rsquo;re fearless:</p>
<pre tabindex="0"><code>op run --env-file prod.env -- hugo deploy --logLevel info --target production
</code></pre><div class="notice warning" >
<p class="first notice-title"><span class="icon-notice baseline"><svg><use href="#warning-notice"></use></svg></span>Warning</p><p>If you&rsquo;ve included the CloudFront Distribution ID in the Hugo deployment target, the deployment will invalidate the distribution cache, by default. Add the flag <code>--invalidateCDN=false</code> to the deploy command above to avoid that, if required.</p></div>

<hr>
<h2 id="additional-references">Additional References</h2>
<ul>
<li><a href="https://gohugo.io/hosting-and-deployment/hugo-deploy/" rel="noopener" target="_blank" class="external">Hugo Docs - Deployment Configuration</a></li>
<li><a href="https://developer.1password.com/docs/cli" rel="noopener" target="_blank" class="external">1Password Docs - CLI</a></li>
<li><a href="https://developer.1password.com/docs/cli/secret-references/" rel="noopener" target="_blank" class="external">1Password Docs - Secret References</a></li>
<li><a href="https://developer.1password.com/docs/cli/secret-references#with-op-run" rel="noopener" target="_blank" class="external">1Password Docs - op run</a></li>
</ul>]]></content:encoded>
    </item>
    
  </channel>
</rss>
