<?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: Aidan Samuel</title>
    <description>The latest articles on DEV Community by Aidan Samuel (@cyclotron3k).</description>
    <link>https://dev.to/cyclotron3k</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%2F211912%2F9c568d48-33d1-4050-a227-b66a3501ec15.png</url>
      <title>DEV Community: Aidan Samuel</title>
      <link>https://dev.to/cyclotron3k</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/cyclotron3k"/>
    <language>en</language>
    <item>
      <title>Moving your Rails app from Google App Engine Flex to Standard environment</title>
      <dc:creator>Aidan Samuel</dc:creator>
      <pubDate>Mon, 19 Aug 2019 04:21:12 +0000</pubDate>
      <link>https://dev.to/cyclotron3k/moving-your-rails-app-from-google-app-engine-flex-to-standard-environment-2pcb</link>
      <guid>https://dev.to/cyclotron3k/moving-your-rails-app-from-google-app-engine-flex-to-standard-environment-2pcb</guid>
      <description>&lt;p&gt;&lt;strong&gt;tl;dr&lt;/strong&gt; Default GAE config for Standard Environment prevents Rails apps from running. It's because &lt;code&gt;skip_files&lt;/code&gt; is preventing a key file from being uploaded.&lt;/p&gt;

&lt;p&gt;Google App Engine currently has two environments: Standard and Flex. Without going into too much detail, the Flex environment is more flexible and can run anything that runs in a docker container. The Standard environment is more restrictive (restricting you to specific languages), but it has other benefits such as much faster deploy times (~4mins instead of ~15mins), faster scaling, and it can even scale to zero.&lt;/p&gt;

&lt;p&gt;Until recently, the standard environment hasn't been available to Rubyists, but in &lt;a href="https://cloud.google.com/appengine/docs/standard/ruby/release-notes"&gt;June 2019&lt;/a&gt;, Google announced that a Ruby 2.5 runtime is available.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why move from Flex to Standard?
&lt;/h2&gt;

&lt;p&gt;By moving your Ruby project from Flex to Standard, you can expect the following benefits:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Likely to be significantly cheaper&lt;/li&gt;
&lt;li&gt;Much faster deployments ~4mins vs ~15mins&lt;/li&gt;
&lt;li&gt;Much faster scaling&lt;/li&gt;
&lt;li&gt;Can scale to zero - i.e. zero cost&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;NOTE: Look at the &lt;a href="https://cloud.google.com/appengine/docs/the-appengine-environments"&gt;comparison page&lt;/a&gt; to know if it's right for you.&lt;/p&gt;

&lt;h2&gt;
  
  
  Migrating to Standard
&lt;/h2&gt;

&lt;p&gt;To move from Flex to Standard there are a few changes you'll need to make.&lt;/p&gt;

&lt;h3&gt;
  
  
  Ruby 2.5 only
&lt;/h3&gt;

&lt;p&gt;You may already be using Ruby 2.6 in the Flex environment, or maybe your application is using an older version of Ruby, but the Standard environment only provides Ruby 2.5 and nothing else. You will need to make sure your application can run in a 2.5 environment. This means that if you're using any of the &lt;a href="https://www.rubyguides.com/2018/11/ruby-2-6-new-features/"&gt;new features in 2.6&lt;/a&gt; then you'll need to take them back out.&lt;/p&gt;

&lt;p&gt;Here's a checklist:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Delete &lt;code&gt;.ruby-version&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;If you were using 2.6 in Flex, make sure you you aren't using any features that only appear in 2.6&lt;/li&gt;
&lt;li&gt;Your &lt;code&gt;Gemfile&lt;/code&gt; may specify a Ruby version with something like &lt;code&gt;ruby '~&amp;gt; 2.6.2'&lt;/code&gt;. You will need to change that to &lt;code&gt;ruby '~&amp;gt; 2.5'&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Update app.yaml
&lt;/h3&gt;

&lt;p&gt;The three main requirements are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;remove &lt;code&gt;env: flex&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;replace &lt;code&gt;runtime: ruby&lt;/code&gt; with &lt;code&gt;runtime: ruby25&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Provide &lt;code&gt;skip_files&lt;/code&gt; configuration (see below)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;(&lt;a href="https://cloud.google.com/appengine/docs/standard/ruby/config/appref"&gt;Full app.yaml documentation&lt;/a&gt;)&lt;/p&gt;

&lt;h3&gt;
  
  
  skip_files
&lt;/h3&gt;

&lt;p&gt;In your &lt;code&gt;app.yaml&lt;/code&gt;, there is a parameter &lt;code&gt;skip_files&lt;/code&gt; which tells &lt;code&gt;gcloud app deploy&lt;/code&gt; which files not to upload to GAE. If you do not override &lt;code&gt;skip_files&lt;/code&gt; (you probably aren't), it uses a default set of exclude patterns and prevents any &lt;code&gt;dot-files&lt;/code&gt; being uploaded. This is often a useful thing, but it will break any Rails deployments because it prevents the sprockets-manifest file from being uploaded. This causes your application to throw the &lt;code&gt;The asset "somefile.jpg" is not present in the asset pipeline.&lt;/code&gt; error that probably brought you to this page.&lt;/p&gt;

&lt;p&gt;The default &lt;code&gt;skip_files&lt;/code&gt; configuration looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# BAD
skip_files:
- ^(.*/)?#.*#$
- ^(.*/)?.*~$
- ^(.*/)?.*\.py[co]$
- ^(.*/)?.*/RCS/.*$
- ^(.*/)?\..*$
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;It's that final line that prevents &lt;code&gt;public/assets/.sprockets-manifest-5y483543959430890.json&lt;/code&gt; from being uploaded, and thus causes Rails to think that assets haven't been precompiled.&lt;/p&gt;

&lt;p&gt;You need to override it by adding something like the following to &lt;code&gt;app.yaml&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# GOOD
skip_files:
- ^(.*/)?#.*#$
- ^(.*/)?.*~$
- ^(.*/)?.*/RCS/.*$
- ^(.*/)?\.git/.*$
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://cloud.google.com/appengine/docs/standard/python/config/appref#skip_files"&gt;Read the documentation&lt;/a&gt; for further information on the format of &lt;code&gt;app.yaml&lt;/code&gt; for the Standard environment. Notice that (as of 2018-08-19) the section on &lt;code&gt;skip_files&lt;/code&gt; only appears in the Python version of the document, and not in the Ruby, despite it being relevant to both.&lt;/p&gt;

</description>
      <category>rails</category>
      <category>ruby</category>
      <category>googleappengine</category>
      <category>googlecloud</category>
    </item>
  </channel>
</rss>
