<?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>DEV Community: sinz</title>
    <description>The latest articles on DEV Community by sinz (@sinz).</description>
    <link>https://dev.to/sinz</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4283289%2F0977be8b-8794-47ad-b9f1-1ec71fc69dd3.jpg</url>
      <title>DEV Community: sinz</title>
      <link>https://dev.to/sinz</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sinz"/>
    <language>en</language>
    <item>
      <title>Catch .env drift before a staging deploy</title>
      <dc:creator>sinz</dc:creator>
      <pubDate>Fri, 04 Dec 2026 17:32:43 +0000</pubDate>
      <link>https://dev.to/sinz/catch-env-drift-before-a-staging-deploy-5alc</link>
      <guid>https://dev.to/sinz/catch-env-drift-before-a-staging-deploy-5alc</guid>
      <description>&lt;p&gt;&lt;em&gt;Disclosure: AI generated this article. The examples use synthetic files and were run against EnvLatch 0.9.0.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Three configuration failures can look alike from a deployment log. A token is missing, a port contains a placeholder, or environments disagree on a setting that should be the same. Each calls for a different fix. Printing the entire &lt;code&gt;.env&lt;/code&gt; file to find out which one happened also puts credentials in the build log.&lt;/p&gt;

&lt;p&gt;This example uses &lt;a href="https://github.com/sinzbtw/envlatch" rel="noopener noreferrer"&gt;EnvLatch&lt;/a&gt;, a small Python CLI, to report those failures against one contract. The input represents a fictional service. The token strings are deliberately fake.&lt;/p&gt;

&lt;h2&gt;
  
  
  Define the contract and two environments
&lt;/h2&gt;

&lt;p&gt;Install the published version in a Python 3.10+ environment:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python -m pip install &lt;span class="nv"&gt;envlatch&lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;0.9.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create &lt;code&gt;template.env.example&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;API_TOKEN=
PORT=
API_MODE=
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create &lt;code&gt;dev.env&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;API_TOKEN=dummy-dev-token-for-demo
PORT=8080
API_MODE=sync
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create &lt;code&gt;staging.env&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;PORT=unset
API_MODE=async
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Save this as &lt;code&gt;envlatch.json&lt;/code&gt; alongside the three files:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"template"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"template.env.example"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"environments"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;"dev"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"dev.env"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"staging"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"staging.env"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"strict"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"types"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"PORT"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"port"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"compare_values"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"API_MODE"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The template lists required keys. &lt;code&gt;strict&lt;/code&gt; turns additional keys into errors, and &lt;code&gt;PORT&lt;/code&gt; must have valid port syntax. &lt;code&gt;compare_values&lt;/code&gt; selects a setting whose literal value must match. Here, the application expects the same mode in both environments, but each environment can have its own token and port.&lt;/p&gt;

&lt;h2&gt;
  
  
  Read the result without opening both env files
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;envlatch compare --config envlatch.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Exit code &lt;code&gt;1&lt;/code&gt; means discrepancies need attention. The output includes these three diagnostics. File paths are shortened in this excerpt.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ERROR [missing_key] staging.env: [staging] Required key 'API_TOKEN' is missing.
ERROR [invalid_type] staging.env:1: [staging] Key 'PORT' must have type 'port'.
ERROR [value_mismatch] &amp;lt;comparison&amp;gt;: Setting 'API_MODE' differs across environments; values are hidden.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace the staging file with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;API_TOKEN=dummy-staging-token-for-demo
PORT=8443
API_MODE=sync
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run the same command. It exits &lt;code&gt;0&lt;/code&gt;: both environments satisfy the contract, and the selected mode matches. The different tokens and port numbers are expected here. EnvLatch checks that both tokens are present and both ports have valid syntax, then reports without printing their values.&lt;/p&gt;

&lt;h2&gt;
  
  
  Put the check where it can help
&lt;/h2&gt;

&lt;p&gt;For a script that reads structured results, use &lt;code&gt;envlatch compare --config envlatch.json --format json&lt;/code&gt;. For a single environment, run &lt;code&gt;envlatch --template template.env.example --env staging.env --strict --format github&lt;/code&gt; in GitHub Actions to get annotations. If that single-environment workflow also needs type checks, use &lt;a href="https://github.com/sinzbtw/envlatch/blob/main/docs/reference.md#optional-type-checks" rel="noopener noreferrer"&gt;an explicit JSON config&lt;/a&gt; with the same &lt;code&gt;PORT&lt;/code&gt; rule.&lt;/p&gt;

&lt;p&gt;Keep the contract in version control. In a real application, point the check at local files or files generated by your existing deployment tooling. EnvLatch checks file contents and syntax. Credential validity, service reachability, available ports, and values resolved later by the application still need their own checks.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/sinzbtw/envlatch" rel="noopener noreferrer"&gt;Source, installation, and examples&lt;/a&gt; · &lt;a href="https://github.com/sinzbtw/envlatch/blob/main/docs/reference.md#compare-dev-staging-and-production" rel="noopener noreferrer"&gt;Configuration and comparison reference&lt;/a&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>devops</category>
      <category>opensource</category>
      <category>cli</category>
    </item>
  </channel>
</rss>
