<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Krzysztof Szromek on Medium]]></title>
        <description><![CDATA[Stories by Krzysztof Szromek on Medium]]></description>
        <link>https://medium.com/@szromek?source=rss-634acae7b83a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*mu6rQMnTqRIMT3oDHS4ZdQ.png</url>
            <title>Stories by Krzysztof Szromek on Medium</title>
            <link>https://medium.com/@szromek?source=rss-634acae7b83a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 05:38:04 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@szromek/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to not kill your PostgreSQL database on AWS (with logs!)]]></title>
            <link>https://medium.com/exlabs/how-to-not-kill-your-postgresql-database-on-aws-with-logs-b24ee05aa1b8?source=rss-634acae7b83a------2</link>
            <guid isPermaLink="false">https://medium.com/p/b24ee05aa1b8</guid>
            <category><![CDATA[data]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[postgres]]></category>
            <dc:creator><![CDATA[Krzysztof Szromek]]></dc:creator>
            <pubDate>Tue, 09 Mar 2021 07:22:16 GMT</pubDate>
            <atom:updated>2021-04-27T11:14:10.144Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/744/1*XF0u6ayF4J9xGv0A4R0nRQ.png" /></figure><p>I am not going to say — we were caught off-guard at the last minute, but during preparation for soak testing, one of our applications became unresponsive for no apparent reason. After a short investigation, we found that a single AWS RDS instance had run out of space. At first glance, we had no idea why 🤭!</p><p>Luckily the impacted environment was only used for testing and had limited access from the outside world. When the environment went down, no load tests were being run, and we were pretty confident that there will not have been any significant amount of data processed and stored that day.</p><p>One might be tempted to throw more 💰💰💰 at it by increasing the storage space and move on. But what used up all the disk space? No exciting cliff-hanger here — it was a database log file!</p><p>Investigating into the root cause, we were taught a lesson by AWS about its product internals. For others to quickly benefit from our learnings, I’ve outlined below a TLDR version (disclaimer: for brevity, we will be discussing a single AZ setup)</p><h3>How Amazon RDS works?</h3><p>Amazon RDS is basically an EC2 instance that AWS manages for you (updating it when needed, applying security patches, etc.). It runs a database engine (in our case PostgreSQL server) and a utility tool (that we will call AWS Agent) for connecting it to the AWS console.</p><p>Under-the-hood, your managed EC2 instance mounts an EBS volume for data storage (volume mounting makes features like snapshots possible). Not everyone knows that this drive is also used for storing all database log files (in alignment with your data retention policies). In our case, the log files took up all the free space and were the reason for our service going down.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/904/0*GaBxctsbjj81hkRD" /><figcaption>Amazon RDS logical structure</figcaption></figure><h3>Why there was so much log data?</h3><p>We were able to pin down the root cause of the service outage. It was a single SQL script file being used to bulk insert test data. In development, we usually prepare fixtures using SQL scripts that get executed on the database. Most of the time, they are short (inserting one or two records at a time), so they don’t take long to complete and are an excellent way to set up the environment for testing against known data inputs/outputs. The bulk insert of test data, in this case, was slightly larger than usual but still within a reasonable size range. A couple of thousands of data inserts. Something that even lower capacity instances should be able to handle easily.</p><p>Unfortunately, our system was impacted by running large SQL script files because of the PGAudit extension:</p><blockquote>The PostgreSQL Audit Extension (or pgaudit) provides detailed session and/or object audit logging via the standard logging facility provided by PostgreSQL. The goal of PostgreSQL Audit to provide the tools needed to produce audit logs required to pass certain government, financial, or ISO certification audits.</blockquote><blockquote><a href="https://www.pgaudit.org/">https://www.pgaudit.org/</a></blockquote><p>For every SQL statement that modifies our underlying data, PGAudit creates a corresponding entry in the database log file. The oversight was that for every data modification being tracked, PGaudit saves the entire content of the executed script file (for each change). Practically — this meant our data volume suddenly got populated with a few thousand copies of the bulk data loading script. The space occupied by log statements grew exponentially 🚀. For a single INSERT added to the file, we would get an additional copy of the (thousand line+) script file in the log, creating a compounding effect.</p><p>This explained how we were able to run out of space with a single bulk INSERT. How did we fix it? After getting service back up and running (restoring from a snapshot and re-allocating storage), we’ve ensured that any test data scripts dealing with bulk inserts, disable database logging at the beginning and re-enable it at the end (to return the configuration to its previous state, minus a multiple-GB log file). That was it!</p><p>This story was a great reminder about understanding how security features can very quickly have functional impacts, so should be fully understood before subscribing to the mindset of “log everything, all the time, forever….”. It’s also a nice reminder to make sure you have metrics and alarms in place for your RDS instances so you can react quickly to any unforeseen side-effects that might only show themselves in test environments! 😁.</p><p>If you are interested in data-related tips &amp; tricks we have recently written about <a href="https://exlabs.com/sql-is-the-language-of-big-data">the role of SQL in Big Data</a> — give it a try and let me know what do you think</p><p>— -</p><p>Icons made by <a href="https://www.freepik.com/">Freepik</a> from <a href="http://www.flaticon.com/">www.flaticon.com</a>, Cover photo by <a href="https://unsplash.com/@jilburr?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Jilbert Ebrahimi</a> on <a href="https://unsplash.com/s/photos/broken?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b24ee05aa1b8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/exlabs/how-to-not-kill-your-postgresql-database-on-aws-with-logs-b24ee05aa1b8">How to not kill your PostgreSQL database on AWS (with logs!)</a> was originally published in <a href="https://medium.com/exlabs">Exlabs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why are fast-paced companies
moving back to static web pages?]]></title>
            <link>https://medium.com/exlabs/why-are-fast-paced-companies-moving-back-to-static-web-pages-4e9ee8aad719?source=rss-634acae7b83a------2</link>
            <guid isPermaLink="false">https://medium.com/p/4e9ee8aad719</guid>
            <category><![CDATA[marketing]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[documentation]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[jamstack]]></category>
            <dc:creator><![CDATA[Krzysztof Szromek]]></dc:creator>
            <pubDate>Mon, 01 Mar 2021 11:17:01 GMT</pubDate>
            <atom:updated>2021-04-27T11:13:59.028Z</atom:updated>
            <content:encoded><![CDATA[<h3>Why are fast-paced companies<br>moving back to static web pages</h3><p><strong>Was the internet more fun in the ’00s? I remember it as a place full of Information-dense forums, flash animations, and blinking texts. Everyone was hacking web pages in “tables” with HTML. WordPress was not even a thing until 2003. We used CGI scripts to bring some life to the web, but they were not widely adopted and tricky to maintain. Creating dynamic services was definitely “not-for-mortals”. Because of it, the internet was mostly a static place, granting the same experience for everyone.</strong></p><p>Static pages are back in the game now! Seeing the IT market going back to solutions from over two decades ago made me feel nostalgic. We have finally gone full circle, and soon Flash will be a thing once again 🤓. Jokes aside — forward-thinking companies are relying on static content even more than a few years ago. They are not recreating the internet from the past though. Those websites are not even close to ones from over 20 years ago in user experience, development, and content management. They are part of complex content delivery pipelines and use cutting-edge technologies for the best results.</p><h3>What is a modern content pipeline?</h3><p>Web portals from the early ’00s are similar to automobiles before Ford T. They were not mass-produced, complex to put together, and expensive to maintain. Modern content pipelines are more like assembly lines that we know today. They are divided into isolated, repetitive steps that ensure high quality, cost-effective, and decoupled product delivery flow.</p><p>For a modern content pipeline, you need <strong>page templates </strong>written in HTML and CSS with placeholders for all the content — titles, copy, images, names. For effective collaboration, store them in a version control system like Git.</p><p>The second ingredient is a shared <strong>content repository</strong>. Use headless CMS like Contentful, more traditional WordPress or Drupal, or even JSON/markdown files stored on a disk.</p><p>Don’t forget about a <a href="https://jamstack.org/generators/"><strong>static site generator</strong></a>. It gets data from a content repository and puts it into page templates. It is also responsible for content optimization (image processing, social tags, and more) and feature enrichment (search tools, page analytics, e-commerce, payments). In the end, it exports final HTML files to a designated location.</p><p>As soon as static pages are generated, you can upload them to your hosting <strong>server </strong>and propagate them across the globe with Cloud Delivery Network. This last step ends the life cycle of a content change in the modern content delivery pipeline.</p><p>What is great about it is the fact that you can automate it. Re-deploy your site on every single content change or a page template update automatically in a matter of seconds. Many modern hosting providers like Netlify provide built-in <strong>continuous delivery</strong> solutions with an easy few-click setup.</p><figure><img alt="A diagram of static site generation process" src="https://cdn-images-1.medium.com/max/705/1*QcLIMr7wUecIYM7uPD1qoA.png" /></figure><h3>How does it help?</h3><p>Transition towards static page delivery model enables you to not only reduce hosting cost. Every static HTML/CSS/JS file can be propagated globally to a Cloud Delivery Network (CDN), further reducing loading times and therefore <strong>increasing conversion rates</strong>. Improving loading time by 1s can benefit the conversion rate by a few percent (<a href="https://wpostats.com/2015/11/04/walmart-revenue.html">2% Walmart</a>, <a href="https://www.nccgroup.trust/globalassets/resources/uk/case-studies/web-performance/cook-case-study.pdf">7% COOK</a>). Switching from dynamic page to static one can yield 2s or even more significant load time improvements.</p><p>Removal of content processing step simplifies web server requirements. Server no longer needs a database instance, additional software, and complex configuration. It <strong>decreases the attack surface</strong> significantly, rendering the server a low-risk asset, comfortable to maintain for DevSecOps.</p><p>Modern stack for static page delivery embraces a strong separation of CMS features and HTML deliverables. Adoption of headless CMS software like Contentful enables companies to <strong>have a unified marketing strategy</strong>. All company content materials live in a single place. System integrators use those materials to build static pages, augment mobile apps, or enrich dynamic web applications. Frameworks like GatsbyJS build HTML code from predefined templates on every data change. They enable teams to <strong>reuse existing components </strong>from existing ReactJS codebases when crafting user experiences.</p><h3>When to use it?</h3><p>Whenever a portal you want to present is the same for all visitors and has strict performance requirements, you should consider deploying it as modern content delivery pages. They work well as <strong>marketing websites, blogs, knowledge hubs, product documentation</strong>. Translation of portals targeted towards <strong>multilingual audiences</strong> is a lot easier with an optimized static page delivery pipeline.</p><p>Modern content delivery accommodates well cases featuring limited sets of dynamic functions too. They deliver a rich user experience by <strong>connecting to external API</strong> with the help of JavaScript code. There are many service providers, including <strong>payment gateways, page commenting solutions, search engines</strong> — you name it — all ready to integrate.</p><h3>How much does it cost?</h3><p>Deploying a modern content delivery pipeline is usually a low-to-medium size effort and generally does not require a significant budget. To fully understand costs associated with such technology, you need to account for:</p><ul><li><strong>Development</strong> cost — This includes getting a development team familiar with technology and understanding continuous delivery concepts. You will address it using well-documented and popular <a href="https://jamstack.org/generators/">static site builders</a> that is the most familiar to your team — GatsbyJS being the default choice for most of the companies.</li><li><strong>Content management</strong> cost — You will need to onboard the content delivery team to a CMS that integrates with static site builder. It will usually generate recurring costs by having to pay a subscription fee. The most popular solution <a href="https://contentful.com/">Contentful.com</a> is free for small teams and costs around $500 for medium-sized ones.</li><li><strong>Hosting</strong> cost — Hosting solutions already include continuous delivery features, cloud distribution networks, and more, so you don’t have to pay for them separately. Most popular <a href="https://netlify.com/">Netlify.com</a> will cost you around $50-$150 a month.</li></ul><p>Following costs are most likely going to be covered by decreased server fleet size and increased conversion rates resulting in a positive net result.</p><h3>Wrapping up</h3><p>Reimagining content delivery pipelines can be a first step towards building well architectured and interconnected platforms for all players. With its relatively low entry point and upfront cost, you can democratize access to company’s information. It drives further innovation and, with a bit of luck, will become a digital transformation catalyst.</p><p>If you would like to learn more about building connected IT systems, I was involved in creating the “Connected Platform” whitepaper — soon on our website (be first to know when it’s published and follow us on our <a href="https://www.linkedin.com/company/exlabs">Company Page on LinkedIn</a>)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4e9ee8aad719" width="1" height="1" alt=""><hr><p><a href="https://medium.com/exlabs/why-are-fast-paced-companies-moving-back-to-static-web-pages-4e9ee8aad719">Why are fast-paced companies
moving back to static web pages?</a> was originally published in <a href="https://medium.com/exlabs">Exlabs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unusual Google Cloud solutions for problems that I didn’t know existed]]></title>
            <link>https://szromek.medium.com/unusual-google-cloud-solutions-for-problems-that-i-didnt-know-existed-ddda67faa482?source=rss-634acae7b83a------2</link>
            <guid isPermaLink="false">https://medium.com/p/ddda67faa482</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[heroku]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <dc:creator><![CDATA[Krzysztof Szromek]]></dc:creator>
            <pubDate>Thu, 26 Oct 2017 11:05:46 GMT</pubDate>
            <atom:updated>2017-10-26T11:05:46.787Z</atom:updated>
            <content:encoded><![CDATA[<p>I’ve been this week on a <a href="https://cloudplatformonline.com/2017-OnBoard-krakow.html">Google Cloud Onboard</a>- an introduction to solutions available in Google Cloud Platform. I was there looking for inspirations and motivation to make a next step in a cloud adoption (as we’re currently migrating our monolith from Heroku PaaS to microservice architecture on the cloud).</p><p>I was always hoping that there’s more in the cloud than just pure computing power/storage. If it wasn’t the case- we’ll see everyone launching their own data centers. Turns out, with proper scale you see problems that others can’t. Solutions for those problems were inspiration I was looking for.</p><h3>1. Atomic clocks and GPS</h3><p>Looks like Google has solution for scaling problems of SQL databases. They are using state of an art hardware such as atomic clocks to make sure everything that is distributed, is consistent at the same time.</p><p><a href="https://www.theverge.com/2012/11/26/3692392/google-spanner-atomic-clocks-GPS">How Google keeps its global Spanner database running with atomic clocks and GPS</a></p><h3>2. AI reduces power consumption</h3><p>I can’t imagine how big is power consumption for large data centers. Significant part of it is being used for cooling all devices. Google has experts trying to reduce that consumption but looks like they were bitten by AI:</p><p><a href="https://www.blog.google/topics/environment/deepmind-ai-reduces-energy-used-for/">DeepMind AI reduces energy used for cooling Google data centers by 40%</a></p><p><strong><em>If you enjoyed this story please hit 👏 button so others find this article too. If you are inspired by cloud like us, </em></strong><a href="http://exlabs.co.uk/"><strong><em>we’d like to meet you</em></strong></a><strong><em> and hear your story!</em></strong></p><p><strong><em>We can also be friends on </em></strong><a href="https://twitter.com/szromek/"><strong><em>Twitter</em></strong></a><strong><em> ;)</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ddda67faa482" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Docker tips for Ruby on Rails apps]]></title>
            <link>https://szromek.medium.com/docker-tips-for-ruby-on-rails-apps-f1d2702a07df?source=rss-634acae7b83a------2</link>
            <guid isPermaLink="false">https://medium.com/p/f1d2702a07df</guid>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[linter]]></category>
            <category><![CDATA[rails]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[docker-compose]]></category>
            <dc:creator><![CDATA[Krzysztof Szromek]]></dc:creator>
            <pubDate>Thu, 26 Oct 2017 10:53:18 GMT</pubDate>
            <atom:updated>2020-04-23T07:08:54.720Z</atom:updated>
            <content:encoded><![CDATA[<h4>“How to run a rails console” and other common questions</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eC9wcDCfQd1WOQw0jOp_uA.png" /></figure><p>After spending another day of work in one of our projects trying to fix local dependency issues, we’ve decided to finally move our Ruby on Rails app over to Docker. The process was almost no-brainer but we needed to fill gaps between our previous workflow and the new one. Following article presents docker ways of performing most common tasks when working on Ruby on Rails application.</p><h3>Application setup</h3><p>We’ve followed instructions from <a href="https://semaphoreci.com/community/tutorials/dockerizing-a-ruby-on-rails-application">https://semaphoreci.com/community/tutorials/dockerizing-a-ruby-on-rails-application</a> for Docker setup and ended up with following docker-compose.yml file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7ed3969460d165e225cb832313bec9c8/href">https://medium.com/media/7ed3969460d165e225cb832313bec9c8/href</a></iframe><p>It has one subtle difference- DB_* environment variables are defined inside docker-compose.yml instead of .env file as .env file is not added to our git repository.</p><blockquote><strong>Things to consider:</strong></blockquote><blockquote>1. Move docker-related environment variables to docker-compose</blockquote><blockquote>2. Add other environment variables to .env file that is not tracked in version control system</blockquote><blockquote>3. Make sure you preserve postgres data by adding “postgres-volume”. This will prevent data loss when removing containers</blockquote><blockquote>4. Make sure you use “.dockerignore” file to exclude /tmp, /.git, /log folders</blockquote><h3>How to run rails console</h3><p>Running rails console is something that we do quite often when we want to debug an issue on live server, but at the same time we don’t want to modify code by adding debugger instructions.</p><p>We can do it now with following command:</p><pre>docker-compose run web rails console</pre><p>The following task will spin up new docker container with rails console as its command instead of default rails s</p><h3>How to run migrations</h3><p>Whenever we work on local machine we always run our migrations as one time jobs with following command:</p><pre>docker-compose run web rake db:migrate</pre><p>For production applications we’re using entrypoint to ensure that migrations are always run on container start:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d9e0278feb73318d19109386249721cc/href">https://medium.com/media/d9e0278feb73318d19109386249721cc/href</a></iframe><p>Just remember to add docker-entrypoint.sh as an <a href="https://docs.docker.com/engine/reference/builder/#entrypoint">ENTRYPOINT</a> instruction.</p><h3>How to work with debugger</h3><p>When you want to work with debugger you need to make sure it will allow communication with your container via console. It can be achieved by adding tty and stdin_open flags to your docker compose as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ca81b76e238aab38f014e38d7fd7a713/href">https://medium.com/media/ca81b76e238aab38f014e38d7fd7a713/href</a></iframe><p>When you stop on a breakpoint, you won’t be able to type in anything in docker-compose by design. All you have to do is to attach to running container. First we need to find container id:</p><pre>docker ps</pre><p>This command will print all running containers. You just need to find a container id corresponding to your web application. Having that id you can attach and start debugging:</p><pre>docker attach CONTAINER_ID</pre><h3>How to lint my files</h3><p>If you already have all your linters installed as gems from within Gemfile, running them is easy as piece of cake. You can use the same pattern as in previous instructions, for example to run rubocop:</p><pre>docker-compose run web rubocop</pre><p>If you want not to run container every single time, but use instead one running instance you can use following command and run linter commands from there:</p><pre>docker-compose exec web bash<br>root@216d180c59fa:/app# rubocop</pre><p>We’re currently working on dockerized linter environment and plugins for popular text editors so this step will be a lot easier… please stay tuned.</p><p><strong><em>If you enjoyed this story please hit 👏 button so others find this article too. You may also be interested in </em></strong><a href="https://medium.com/@k.szromek/how-my-mom-helped-my-team-with-pull-requests-reviewing-1139f39aa775"><strong><em>the way we’ve saved our pull requests</em></strong></a></p><p><strong><em>We can also be friends on </em></strong><a href="https://twitter.com/szromek/"><strong><em>Twitter</em></strong></a><strong><em> ;)</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f1d2702a07df" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How my mom helped my team with Pull Requests reviewing]]></title>
            <link>https://szromek.medium.com/how-my-mom-helped-my-team-with-pull-requests-reviewing-1139f39aa775?source=rss-634acae7b83a------2</link>
            <guid isPermaLink="false">https://medium.com/p/1139f39aa775</guid>
            <category><![CDATA[quality-assurance]]></category>
            <category><![CDATA[pull-request]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[code-review]]></category>
            <dc:creator><![CDATA[Krzysztof Szromek]]></dc:creator>
            <pubDate>Mon, 28 Aug 2017 19:18:14 GMT</pubDate>
            <atom:updated>2020-04-23T07:10:22.324Z</atom:updated>
            <content:encoded><![CDATA[<h4>You can also make your Pull Requests fun to work with</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/962/1*rZge5QseaOIVzxWlpSictQ.png" /></figure><p>Every development process gets out of hand when there’s a time pressure, and to be honest, it is not that uncommon for time pressure to be there ;) If I’d have to do a list of steps sacrificed for speed I think it’d look like this:</p><p><strong>“How to speed up development 101”</strong>™</p><ol><li>Documentation? Nah…</li><li>Tests? We catch up at some point</li><li>Code review? Ain’t nobody got time for that</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*K10I_Aw077MHDnFiKM-svA.jpeg" /></figure><p>The worst part is — once sacrificed- it’s hard for good habits to come back. We’ve tried many times to get back on track but every single time we ended up with nothing.<strong> I have never seen it coming that my mom will help me solve this problem.</strong></p><h3>Let’s look from a different angle</h3><p>Is my team behaviour much different from me when I was a kid? Let’s face it- when I wanted to play, I threw all clothes into a closet and considered housekeeping done (It looks like nothing changed over time ;))</p><p>Then it struck me- what my mom did was really simple. She was always there to repeat what needs to be done over and over again. Sounds familiar? I just have to constantly tell my coworkers what needs to be done... Except it wasn’t what I really needed. First of all, it does not scale very well. I didn’t want to be this unpleasant folk you try to pass walking the other side of the street either. Then I’ve found it…</p><h3>Pull Request template to the rescue</h3><p>Wouldn’t it be nice to always remember what needs to be done when opening new Pull Request? We had a documentation living on a Google Cloud just for that but as you can guess it was never used. It was simply too far to reach. Luckily on February 2016 <a href="https://github.com/blog/2111-issue-and-pull-request-templates">Github introduced Pull Requests templates</a>. They are markdown files that populate descriptions of newly created Pull Requests. It was exactly what I was looking for.</p><p>For our project, we’ve created PULL_REQUEST_TEMPLATE file in .github/ folder and we started iterating on its content to the point where the team was happy.</p><p>We’ve created its own Pull Request in which we were sharing our thoughts and ideas so everyone could be involved. You can see what we landed on:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/887fc61a2332758812ce50717028861d/href">https://medium.com/media/887fc61a2332758812ce50717028861d/href</a></iframe><p><strong>Template structure:</strong></p><ul><li>PR naming rules</li><li>PR maximal count rules — this helped us get rid of Pull Requests hanging too long in the queue, waiting to be reviewed</li><li>PR sections — description, motivation, screenshots for easy debugging and context information about why change was made</li><li>Checklist — filled by PR author. Its purpose is to make sure author did not forget about important actions</li><li>Branch naming conventions</li></ul><p>Below is a screenshot of Pull Request template in action. Note the fact that &lt;!--- .... ---&gt; are comments and will not be displayed on a created PR.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mLY-5QONWOQ3_CGyIhVEJQ.png" /></figure><h3>Awesome results</h3><p>With this simple file, we’ve achieved more than ever. It was surprising how team work improved by having this constant reminder of things that have to be done.</p><ul><li>We went down <strong><em>from 3 weeks to 2 days</em></strong> for reviews of the most complicated pull requests</li><li>We no longer need to spin up local app for a simple frontend change review— thanks to screenshots in place</li><li>Pull Request description can be used now to <strong><em>create Changelog</em></strong></li><li>Team members <strong><em>write tests</em></strong><em> </em>— they don’t want to be judged for leaving unchecked “I have added tests…”</li></ul><p><strong><em>If you enjoyed this story please hit 👏 button so others find this article too. You may also be interested in </em></strong><a href="https://medium.com/@k.szromek/semi-automated-code-review-40f5489c45d1"><strong><em>the way we automated our code review process</em></strong></a><strong><em>.</em></strong></p><p><strong><em>We can also be friends on </em></strong><a href="https://twitter.com/szromek/"><strong><em>Twitter</em></strong></a><strong><em> ;)</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1139f39aa775" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[(Semi)Automated code review]]></title>
            <link>https://szromek.medium.com/semi-automated-code-review-40f5489c45d1?source=rss-634acae7b83a------2</link>
            <guid isPermaLink="false">https://medium.com/p/40f5489c45d1</guid>
            <category><![CDATA[rails]]></category>
            <category><![CDATA[code-review]]></category>
            <category><![CDATA[circleci]]></category>
            <category><![CDATA[continuous-integration]]></category>
            <category><![CDATA[github]]></category>
            <dc:creator><![CDATA[Krzysztof Szromek]]></dc:creator>
            <pubDate>Mon, 31 Jul 2017 09:15:07 GMT</pubDate>
            <atom:updated>2017-08-21T06:14:06.948Z</atom:updated>
            <content:encoded><![CDATA[<h4>Automation of a Github code review process with Pronto and Circle CI</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/692/1*n9XXmBStsvGt1Rk6RWfidg.jpeg" /></figure><p>As your team grows you start noticing subtle differences with the way your team members write and format code. For smaller teams it’s not a big issue but imagine team with dozens of developers, each one of them organizes and formats code differently. After a while app is a mess. Sounds disturbing? I should have mentioned every one of them has different experience and standards for what’s “good enough”.</p><p>You may find yourself very often writing the same Pull Request comments just to keep codebase consistent and up to date with chosen style guide. How many of <em>“use guard clause”</em> or <em>“this line seems to be too long”</em> or <em>“this variable is never being used”</em> have you written so far? Well for me it was definitely too often and I decided to look for available solutions. After a moment or two I’ve came across <strong>Pronto </strong>gem.</p><h3>They way out — Pronto</h3><p>Pronto (<a href="https://github.com/mmozuras/pronto">https://github.com/mmozuras/pronto</a>) is gem for code static analysis automation. Its biggest advantage is ability to analyze only most recent changes (so it can be used for existing projects without adding too much noise) and post violations as comments directly to Github, Gitlab or Bitbucket.</p><p>First thing you have to do is to add gem, its runners and dependencies to Gemfile and run bundle install</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d80597d9421925cba16ba7ce3e7cd420/href">https://medium.com/media/d80597d9421925cba16ba7ce3e7cd420/href</a></iframe><p>This will make pronto command available within our test environment. In next step we’ll make sure automatic code review is being made on pull request creation. For this purpose we will use Continuous Integration service CircleCI.</p><h3>Setting up Circle CI</h3><p>I’m going to use Circle CI as a trigger for our code review. If you don’t have it setup yet please go to <a href="https://circleci.com/docs/1.0/language-ruby-on-rails/">https://circleci.com/docs/1.0/language-ruby-on-rails/</a> for further instructions. You can use different tool (such as Jenkins) but please keep in mind it may require some changes in script from the next step.</p><p>Assuming you have Circle CI in place go to your project settings and make sure you have <em>“Only build pull requests”</em> turned on. This way we will make sure code review is being performed only after Pull Request is created (we will need Pull Request ID to submit comments)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y82e8J7qCSb92UJhiQ3PUw.png" /><figcaption>Enabling “Only build pull requests” on Circle CI</figcaption></figure><p>Next thing you have to do is to setup circle.yml configuration file. We need to add two things:</p><ul><li>modification of the way CircleCI performs fetch — by default it downloads only small part of git history making diff comparison impossible</li><li>running script file<strong> bin/automated_code_review</strong> that we’re going to create in the next step</li></ul><p>This can be done with following lines:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/16450d1da5b61fa90f1a4832de441153/href">https://medium.com/media/16450d1da5b61fa90f1a4832de441153/href</a></iframe><p>At the end you have to setup <strong>PRONTO_GITHUB_ACCESS_TOKEN</strong> environment variable. You will get access token from your Github account in “Personal access tokens” tab. All you have to do is to place it inside your build settings under “Environmental variables”</p><p>Having all those things set up we can move to last step which is creating code review script</p><h3>Creating code review script</h3><p>By default Pronto compares changes agains master branch. In my case it was not always desired state because sometimes Pull Requests were branched off from branches different than master. For such a situation I’ve prepared short script that asks Github API for Pull Request base branch, and uses it as base for Pronto diff calculations.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/05b1315d273cc351448ae90cb7300fba/href">https://medium.com/media/05b1315d273cc351448ae90cb7300fba/href</a></iframe><p>Don’t forget to change rights of the file with chmod 755 bin/automated_code_review, only this way Circle CI will be able to execute file.</p><h3>How it looks?</h3><p>If everything works correctly once you try to submit all those changes and you will create a Pull Request you should see new Github statuses and maybe even some comments:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DMakPN8aZSIoYtVaQBdy-A.png" /><figcaption>First comments made by automatic code review (it uses my access token so they are displayed as my comments)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5zlx-UI0-mTR2QL4b3OWIA.png" /><figcaption>List of checks for Pull Request</figcaption></figure><p>From this point you can start customizing all linters with files like .rubocop.yml added to your repository or maybe even add your own runners. It is also possible to plug in pronto on your before_commit hook but I’ll let you assess whether it’s good approach or not.</p><p>Thanks for reading. If you liked this article you may be also interested in our best practices on keeping code clean: <a href="http://exlabs.co.uk/best-practices-on-keeping-your-codebase-clean/">http://exlabs.co.uk/best-practices-on-keeping-your-codebase-clean/</a>. Please clap your hands it if you like it :)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/148/1*8n5BLtkI-xnOUllGfzsSlQ.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=40f5489c45d1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Frontend security with CSP]]></title>
            <link>https://szromek.medium.com/frontend-security-with-csp-946be018c370?source=rss-634acae7b83a------2</link>
            <guid isPermaLink="false">https://medium.com/p/946be018c370</guid>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[backend]]></category>
            <category><![CDATA[https]]></category>
            <dc:creator><![CDATA[Krzysztof Szromek]]></dc:creator>
            <pubDate>Tue, 04 Jul 2017 10:12:09 GMT</pubDate>
            <atom:updated>2020-04-23T07:11:39.580Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Is my website secure?</em> You bet it is! <em>I’m using HTTPS</em>… Hang on, there’s more?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BflxydTKd-KK7zaSDRzSEA.png" /></figure><p>Most of the time we’re thinking about web security in terms of backend development, leaving the frontend with HTTPS and nothing more. Having a secured channel is a must have these days, but it shouldn’t be the only thing that we think off when it comes to securing our application on the users’ end.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/465/1*_RYcrKQHzfOr9-4PlZo-GQ.png" /></figure><p>Every security solution is like a slice of cheese- it may have some holes, leaving our application at risk. This is why we need to stack many layers till we don’t see any holes left.</p><p>With that in mind we need to consider HTTPS being only first layer of our security stack. I’d like to explain a little bit more about second most important (in my opinion) layer which is <strong>Content Security Policy.</strong></p><h3>What is CSP?</h3><p>Content Security Policy is an HTTP response header that reduces the risk of XSS attack by whitelisting sources of images, scripts, styles and other resources. It is supported by top browsers, excluding IE (although there’s Edge support since build 10240+).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VqIgPgbBOQIX9TM4aDAc1g.png" /><figcaption>Browser supporting CSP 1.0 <a href="http://caniuse.com/#search=content%20security%20policy">http://caniuse.com/#search=content%20security%20policy</a></figcaption></figure><p>Currently there are two versions of CSP available, where version 1.0 has a better support coverage, but version 2.0 adds a number of new directives and capabilities thus should be considered as more robust solution.</p><h3>CSP Examples</h3><p>When you want to allow resource loading only from the same origin this is how CSP header looks like:</p><pre>Content-Security-Policy: default-src &#39;self&#39;;</pre><p>If you only want to restrict specific kind of resources for example scripts, you can do following:</p><pre>Content-Security-Policy: script-src &#39;self&#39;;</pre><p>Most of pages are using Google Analytics and Google Ajax CDN, this is all you need to enable those scripts:</p><pre>Content-Security-Policy: script-src &#39;self&#39; www.google-analytics.com ajax.googleapis.com;</pre><blockquote>You can see a list of all possible attributes here: <a href="https://content-security-policy.com/">https://content-security-policy.com/</a></blockquote><h3>How to start</h3><p>By enabling a Content-Security-Policy header in an existing application you’ll disable loading of all non-listed sources potentially breaking the page for a user. I recommend to start with <em>Content-Security-Policy-Report-Only</em>.</p><pre>Content-Security-Policy-Report-Only: script-src &#39;self&#39; www.google-analytics.com ajax.googleapis.com; report-uri /my-post-webhook.php</pre><p>It works the same way as Content-Security-Policy, but instead of blocking the resource it throws an error in form of a JSON. You can handle it by yourself as they will be send via POST to a given URL, or use a service that will handle it for you (e.g. <a href="https://report-uri.io/">https://report-uri.io/</a>).</p><p>You can record those errors and refine your policy, to the point where all needed sources are whitelisted and you don’t get any errors. It’s worth noting that Content-Security-Policy-Report-Only and Content-Security-Policy can coexists, so you can use one to block resources, and the other one to develop more strict policy versions for better security.</p><pre>Content-Security-Policy: script-src script-src &#39;self&#39; www.google-analytics.com ajax.googleapis.com; report-uri /my-post-webhook.php;<br>Content-Security-Policy-Report-Only: script-src &#39;self; report-uri /my-post-webhook.php</pre><h3>Server setup</h3><p><strong>Apache</strong></p><p>Add the following to your httpd.conf in your VirtualHost or in an .htaccess file:</p><pre>Header set Content-Security-Policy &quot;default-src &#39;self&#39;;&quot;</pre><p><strong>Nginx</strong></p><p>In your server {} block add:</p><pre>add_header Content-Security-Policy &quot;default-src &#39;self&#39;;&quot;;</pre><h3>Further reading</h3><p><a href="https://content-security-policy.com/">Content-Security-Policy (CSP) Header Quick Reference</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=946be018c370" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>