<?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: Mikhail Salosin</title>
    <description>The latest articles on DEV Community by Mikhail Salosin (@alphab).</description>
    <link>https://dev.to/alphab</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%2F866152%2Fc03ff3c6-a587-4667-88d0-0f2f536316cb.jpeg</url>
      <title>DEV Community: Mikhail Salosin</title>
      <link>https://dev.to/alphab</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/alphab"/>
    <language>en</language>
    <item>
      <title>AWS CloudFront on Rails</title>
      <dc:creator>Mikhail Salosin</dc:creator>
      <pubDate>Tue, 14 Jun 2022 21:57:43 +0000</pubDate>
      <link>https://dev.to/alphab/aws-cloudfront-on-rails-57ld</link>
      <guid>https://dev.to/alphab/aws-cloudfront-on-rails-57ld</guid>
      <description>&lt;p&gt;Content Delivery Network is a useful tool to reduce the latency of delivering images, scripts, and stylesheets to your customer. Since we at Revealbot are using AWS as our cloud provider we decided to give Amazon's own CDN CloudFront a try. &lt;/p&gt;

&lt;p&gt;In this post I'll describe how to setup Rails and CloudFront to work with each other. &lt;/p&gt;

&lt;p&gt;On the Rails side configuration is pretty straightforward. To enable CDN we need to add one line to our production.rb config file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;config.asset_host = 'cdn.revealbot.com'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we need to set up CloudFront. Go to CloudFront &lt;a href="https://console.aws.amazon.com/cloudfront/v3/home"&gt;page&lt;/a&gt; in the AWS console. Click on Create distribution. Fill in the Origin domain, with the site domain select protocol that CloudFront will use to access your sites.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GwDeGADP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/28zl4q54iglng7br1ilr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GwDeGADP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/28zl4q54iglng7br1ilr.png" alt="Image description" width="880" height="754"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the Settings tab enter the domain name that will be used as the CDN subdomain and request an SSL certificate to enable HTTPS.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vnzCeNbD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mjq6ju0hs4nymo6qrzq0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vnzCeNbD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mjq6ju0hs4nymo6qrzq0.png" alt="Image description" width="880" height="774"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then click Create Distribution. It will take AWS a couple of minutes to roll up distribution to all regions, in the meantime, we can continue our setup. Click on created distribution and go to the Origins tab. Since we only want to serve our assets through CDN we can add additional "fake" origin &lt;code&gt;invalid.invalid&lt;/code&gt; that will help us reject all requests except for assets.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dtaKFn8L--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/osr38j0momsh1zy5fvud.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dtaKFn8L--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/osr38j0momsh1zy5fvud.png" alt="Image description" width="880" height="744"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ok, almost done, now let's set up path rules, go to Behavior and create rules that will define how CDN is processing different paths. This is our current setup:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Bvc60KDI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gk83os6iq90awwcqiruy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Bvc60KDI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gk83os6iq90awwcqiruy.png" alt="Image description" width="880" height="332"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Notice that the Default (*) path is set to &lt;code&gt;invalid.invalid&lt;/code&gt; that we set up earlier, this will prevent CDN from serving anything else besides assets - images, fonts, stylesheets, and js files.&lt;/p&gt;

&lt;p&gt;And that's it, redeploy your production app and all assets will be served through CloudFront CDN.  &lt;/p&gt;

</description>
      <category>aws</category>
      <category>cdn</category>
      <category>rails</category>
    </item>
    <item>
      <title>Easy migration to Ansible Vault id</title>
      <dc:creator>Mikhail Salosin</dc:creator>
      <pubDate>Tue, 14 Jun 2022 13:49:37 +0000</pubDate>
      <link>https://dev.to/alphab/easy-migration-to-ansible-vault-id-43ap</link>
      <guid>https://dev.to/alphab/easy-migration-to-ansible-vault-id-43ap</guid>
      <description>&lt;p&gt;To keep all our tokens secure we use &lt;a href="https://docs.ansible.com/ansible/latest/user_guide/vault.html"&gt;the Ansible vault&lt;/a&gt; to encrypt them. Historically all files with secrets were encrypted with a single password instead of using a vault id and password file. This week we decided to migrate to vault id.&lt;/p&gt;

&lt;p&gt;All files encrypted with a password and without vault id specified will have the header &lt;code&gt;$ANSIBLE_VAULT;1.1;AES256&lt;/code&gt;. We can use grep to find all files with this header. To do that run&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;grep "\$ANSIBLE_VAULT;1.1;AES256" group_vars/**/*.yml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we have a list of files that looks like that:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;group_vars/staging/amazon.yml:$ANSIBLE_VAULT;1.1;AES256
group_vars/staging/db.yml:$ANSIBLE_VAULT;1.1;AES256
group_vars/staging/docker_registry.yml:$ANSIBLE_VAULT;1.1;AES256
....
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Grep adds matched string at the end of every file. We can use the &lt;code&gt;cut&lt;/code&gt; command to remove this part since we only need file names. &lt;code&gt;cut -d: -f1&lt;/code&gt; will leave only the file name.&lt;/p&gt;

&lt;p&gt;And finally, we can use &lt;code&gt;xargs&lt;/code&gt; to pass the file list to the &lt;code&gt;ansible-vault rekey&lt;/code&gt; command to convert all encrypted files to encrypted files with vault id.&lt;/p&gt;

&lt;p&gt;The full command will look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;grep "\$ANSIBLE_VAULT;1.1;AES256" group_vars/**/*.yml | cut -d: -f1 | xargs ansible-vault rekey --new-vault-id vaultID@vaultfile
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>ansible</category>
      <category>devops</category>
    </item>
  </channel>
</rss>
