<?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: Bloom Built</title>
    <description>The latest articles on DEV Community by Bloom Built (@bloom).</description>
    <link>https://dev.to/bloom</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%2Forganization%2Fprofile_image%2F105%2F2e8aede0-cdfe-4fbc-81b9-bf6f26fb16e6.png</url>
      <title>DEV Community: Bloom Built</title>
      <link>https://dev.to/bloom</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bloom"/>
    <language>en</language>
    <item>
      <title>Deploying Reason on AWS Elastic Beanstalk with RDS</title>
      <dc:creator>Murphy Randle</dc:creator>
      <pubDate>Wed, 13 Jun 2018 22:16:12 +0000</pubDate>
      <link>https://dev.to/bloom/deploying-reason-on-aws-ebs-with-rds-2koc</link>
      <guid>https://dev.to/bloom/deploying-reason-on-aws-ebs-with-rds-2koc</guid>
      <description>&lt;p&gt;This isn’t a step-by-step guide. It’s more like a selection of points that the author has just spent too much time getting all flamboozled over,  that have been written down now in hopes that some poor kindred spirit (including that same author) won’t have to re-experience the pain necessary just to get a Reason service running on AWS EBS.&lt;/p&gt;

&lt;p&gt;The first thing to do is get the &lt;code&gt;eb&lt;/code&gt; utility installed (&lt;code&gt;eb&lt;/code&gt; standing for “Elastic Beanstalk”, of course). You can get it on either &lt;code&gt;homebrew&lt;/code&gt; or &lt;code&gt;pip&lt;/code&gt;. The details you can figure out all on your own (good luck!).&lt;/p&gt;

&lt;p&gt;Run these commands and follow the prompts. Mostly the default values are okay.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;eb init&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;eb create&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That’s all normal stuff. Buckle up for the juicy details:&lt;/p&gt;

&lt;h1&gt;
  
  
  Bundling
&lt;/h1&gt;

&lt;p&gt;Compiled reason code depends on javascript that’s included in the &lt;code&gt;bs-platform&lt;/code&gt; NPM package. The problem is that said package also will build an entire OCaml compiler, and if you’re trying to deploy code on anything smaller than a not-small server, you’re going to have a prohibitively hard time.&lt;/p&gt;

&lt;p&gt;A relatively simple solution is to do a little bit of bundling before shipping your code. You’ll use &lt;code&gt;webpack&lt;/code&gt; to bundle up your compiled Reason code into a little neat package before deploying to EBS.&lt;/p&gt;

&lt;p&gt;On reading the mention of Webpack, you might be wiping sweat from your brow, anxiously telling yourself that you don’t feel an aching throb at the back of your skull at the thought of having to dig into yet another Webpack config. But don’t worry. It’s a tiny file that’s simple to understand:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;webpack.config.js&lt;/em&gt; -&amp;gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var nodeExternals = require('webpack-node-externals');


module.exports = {
  entry: './src/index.js',
  target: "node",
  output: {
    filename: 'bundle.js',
    libraryTarget: 'commonjs2',
    path: __dirname
  },
  externals: [nodeExternals({
    whitelist: [/^bs-platform/, /\.bs\.js$/]
  })],
  mode: "development",
  devtool: "sourcemap"
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You’ve included a Webpack plugin that automatically tells Webpack &lt;em&gt;not to bundle&lt;/em&gt; anything at all that’s found in the &lt;code&gt;node_modules&lt;/code&gt; folder. Which is good! Because most of that stuff will be provided when the deploy process runs &lt;code&gt;npm install&lt;/code&gt;, and also good because some of the things in there won’t be happily bundled.&lt;/p&gt;

&lt;p&gt;You’ll want to add that plugin to your project with the following command (assuming you’re using Yarn. If you’re using NPM you’re straight outta luck. Just kidding. You know what to do):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yarn add -D webpack-node-externals
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LbTkEQuk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/0ptcuig2u7zhbngat8w9.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LbTkEQuk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/0ptcuig2u7zhbngat8w9.jpg" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;but you’ll see that you’ve passed a config object when calling &lt;code&gt;nodeExternals(..)&lt;/code&gt; with the key &lt;code&gt;whitelist&lt;/code&gt;. This is an array of things that you &lt;em&gt;do want to be bundled&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;So, to repeat in simpler words, you set up Webpack, and used a plugin to say “don’t bundle anything in node_modules &lt;em&gt;except this list of things&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;That list of things looks like this:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;[/^bs-platform/, /\.bs\.js$/]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Those are two regular expressions. The first includes any JS used from the &lt;code&gt;bs-platform&lt;/code&gt; module, and the second is any file referenced inside of node_modules that uses the extension &lt;code&gt;.bs.js&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;That second entry is important, because when you run the &lt;code&gt;bsb&lt;/code&gt; compiler while developing, the compiled JS artifacts get dropped inside of the &lt;code&gt;node_modules&lt;/code&gt; folder (like &lt;code&gt;node_modules/bs-foo/lib/js/foo.bs.js&lt;/code&gt; for example).&lt;/p&gt;

&lt;p&gt;Now just :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yarn add -D webpack-command
#^ this is smaller and faster than webpack-cli AFAIK
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then &lt;code&gt;yarn webpack&lt;/code&gt;, and you should get a generated &lt;code&gt;bundle.js&lt;/code&gt; in the root of your project.&lt;/p&gt;

&lt;p&gt;You can then add &lt;code&gt;node bundle.js&lt;/code&gt; to your &lt;code&gt;start&lt;/code&gt; command in your package json, and EBS should do what’s expected when you deploy. BTW, you’ll want to have your server code listen on &lt;code&gt;8081&lt;/code&gt;, or whatever the &lt;code&gt;PORT&lt;/code&gt; ENV var is set to.&lt;/p&gt;

&lt;h2&gt;
  
  
  Cleaning up your deps
&lt;/h2&gt;

&lt;p&gt;Now, open up your package.json, and move every package that isn’t a strict &lt;em&gt;runtime&lt;/em&gt; dependency from &lt;code&gt;dependencies&lt;/code&gt; to &lt;code&gt;devDependencies&lt;/code&gt;. Including all the Bucklescript packages you’ve installed (because you bundled them already), and &lt;em&gt;especially&lt;/em&gt; including &lt;code&gt;bs-platform&lt;/code&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  Deploying
&lt;/h1&gt;

&lt;p&gt;When I first tried a deploy, EBS was trying to zip up my whole code folder, including node modules, and ship it off for deployment. That’s obviously huge and unwieldy and not what we want at all for deployment. So do this instead:&lt;/p&gt;

&lt;p&gt;Create a file called &lt;code&gt;.ebignore&lt;/code&gt; and put inside:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;br&gt;
node_modules/&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Make sure the trailing slash is there!&lt;/p&gt;

&lt;p&gt;After that, you should be able to &lt;code&gt;eb deploy&lt;/code&gt;, and have a relatively quick deployment.&lt;/p&gt;

&lt;h1&gt;
  
  
  RDS
&lt;/h1&gt;

&lt;p&gt;The author of this post would still be trying to keep himself from bursting small blood vessels in his face if it weren’t for this Front-end Master’s course on Node and AWS EBS: &lt;a href="https://frontendmasters.com/courses/production-node-aws"&gt;https://frontendmasters.com/courses/production-node-aws&lt;/a&gt;. The information following is taken from that course. So if you have money and want to learn, consider giving some to those peeps.&lt;/p&gt;

&lt;p&gt;First step, add an RDS database. That should be pretty simple to figure out on your own.&lt;/p&gt;

&lt;p&gt;Here’s the more detailed stuff.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When you deployed your EB application, a new security group was created for it, and you can find the name of that security group in the config console for your EB application.&lt;/li&gt;
&lt;li&gt;You need to add your RDS instance to that same security group in its configuration console.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here’s the part that might seem surprising. It might seem that if the RDS instance and the EB instance are in the same security group, they should be intimate security buddies and open to all kinds of communication. But, nope.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You need to edit the incoming permissions for that security group, and open up the port your database is listening on to incoming traffic &lt;em&gt;from the selfsame security group&lt;/em&gt;. You need to tell it that it can access itself!&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--iIFCx-Um--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/p05voxx5uvldy8ul98ax.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--iIFCx-Um--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/p05voxx5uvldy8ul98ax.jpeg" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You’ll see in the snap above that security group &lt;code&gt;sg-9...&lt;/code&gt; now specifies that it should allow traffic on port 5432 from security group &lt;code&gt;sg-9...&lt;/code&gt; (the same group).&lt;/p&gt;

&lt;p&gt;After you’ve done this, EB and RDS should be able to talk.&lt;/p&gt;

&lt;h2&gt;
  
  
  S3
&lt;/h2&gt;

&lt;p&gt;If your application uses S3, you might be worried that you’d have to do silly shenanigans to allow that connection, but it should “just work”(tm).&lt;/p&gt;

&lt;h1&gt;
  
  
  Little tips for troubleshooting
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;You can SSH into a running EB instance by typing &lt;code&gt;eb ssh&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;The process runs under the user &lt;code&gt;nodejs&lt;/code&gt;,  but you can’t &lt;code&gt;su&lt;/code&gt; to that user. Don’t try. Someone did, and they got rejected. And rejection hurts.&lt;/li&gt;
&lt;li&gt;The logs for the node process live in &lt;code&gt;/var/logs/nodejs/nodejs.log&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;You can tail those logs with this command &lt;code&gt;tail -f /var/logs/nodejs/nodejs.log&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Trying to run things like &lt;code&gt;npm start&lt;/code&gt; by hand is a pain. &lt;/li&gt;
&lt;li&gt; You can run &lt;code&gt;npm install&lt;/code&gt; by first changing to the root user with &lt;code&gt;sudo su&lt;/code&gt; and then running this command: &lt;code&gt;/opt/elasticbeanstalk/containerfiles/ebnode.py --action npm-install&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;While deploying, you can find your application code in &lt;code&gt;/tmp/deploy/...&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;After deploy, you can find your application code in &lt;code&gt;/var/app&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;If you’re having a hard time connecting to some other box and port from your instance, you can run &lt;code&gt;nc -vf &amp;lt;host&amp;gt; &amp;lt;port&amp;gt;&lt;/code&gt; from your EB box to see if it can reach that port or not. This helped a lot when figuring out the connection between EB and RDS.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wfKEBH9R--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/ygoyrhjlpz3nru1nqoi5.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wfKEBH9R--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/ygoyrhjlpz3nru1nqoi5.jpg" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>reason</category>
      <category>aws</category>
      <category>devops</category>
    </item>
    <item>
      <title>A Note on Elm Compiler Perf &amp; File Organization </title>
      <dc:creator>Murphy Randle</dc:creator>
      <pubDate>Thu, 21 Dec 2017 18:32:32 +0000</pubDate>
      <link>https://dev.to/bloom/a-note-on-elm-compiler-perf--file-organization-467</link>
      <guid>https://dev.to/bloom/a-note-on-elm-compiler-perf--file-organization-467</guid>
      <description>&lt;p&gt;I did some experimentation today when working on a project and realizing  that the new module I added was taking about five seconds to compile, when previously the app would compile in about two seconds.&lt;/p&gt;

&lt;p&gt;I did some research and experimentation, and remembered that in order to make the Elm compiler work fast, you want to be making changes most often in files that are &lt;strong&gt;imported by&lt;/strong&gt; the fewest other files. &lt;strong&gt;It doesn’t matter so much how many other files a file imports&lt;/strong&gt; as it matters &lt;em&gt;how many files a file is imported by&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;In my case, I had made a new widget, and stuck all of its pieces inside one file. (Where its pieces are its types, the update function, the view function, etc...). I realized that this one file (let’s call it &lt;code&gt;Foo.elm&lt;/code&gt;) was imported by the application’s &lt;code&gt;Types.elm&lt;/code&gt; file. That file happens to be included by a bunch of other files in the application. So when I changed &lt;code&gt;Foo.elm&lt;/code&gt;, it caused &lt;code&gt;Types.elm&lt;/code&gt; to be recompiled, which triggered a re-compilation of a bunch of other files in the project.&lt;/p&gt;

&lt;p&gt;As an experiment, I extracted just the types from &lt;code&gt;Foo.elm&lt;/code&gt; in to &lt;code&gt;Foo/Types.elm&lt;/code&gt;. And it cut almost two whole seconds off of recompilations when editing &lt;code&gt;Foo.elm&lt;/code&gt;. I imagine that I could save even more time by splitting out the view, update, and etc... into their own files.&lt;/p&gt;

&lt;p&gt;I don’t really like that from an organizational standpoint, but it does speed up the compiler significantly.&lt;/p&gt;




&lt;p&gt;EDIT:&lt;/p&gt;

&lt;p&gt;FWIW, I had everything in Foo.elm in the interest of following the direction given here: youtube.com/watch?v=XpDsk374LDE. Which I think is good direction, but just putting everything for a section of the app in the same file isn't the best for compiler perf.&lt;/p&gt;

&lt;p&gt;I haven't tried this yet, but I'm theorizing that a better approach than extracting types into a whatever/Types.elm file, is to just extract the view functions into their own files as much as is necessary, since the view is typically what is iterated on, and maybe extract the update function too if that's also moving too slowly for you.&lt;/p&gt;

&lt;p&gt;Consider the following points:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Splitting a function out into its own file is only helpful if it doesn't have a parent that's imported by tons and tons of files. If you extract a function to its own file, you might need to extract its parent functions into their own files as well if you want to see an improvement in compilation speed.&lt;/li&gt;
&lt;li&gt;Where possible, functions that are used in many places should be moved into their own files for the sake of performance, and should not import any files that you will be updating regularly.&lt;/li&gt;
&lt;li&gt;This is a trade-off game, dealing with tons of files can be a pain. It's probably a bad idea to go all crazy and start putting all of your functions into their own files right off the bat.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Photo by Veri Ivanova on Unsplash&lt;/p&gt;

</description>
      <category>elm</category>
      <category>performance</category>
      <category>fileorganization</category>
    </item>
  </channel>
</rss>
